#include<iostream>
using namespace std;
class Student
{
public:
int rollno;
string sname;
void setdata()
{
rollno = 1;
sname = "ABC";
}
};
class Marks : public Student
{
public:
int m1, m2, m3, total;
float per;
void setmarks()
{
setdata();
m1 = 60;
m2 = 65;
m3 = 70;
total = m1 + m2 + m3;
per = total / 3;
}
void show()
{
setmarks();
cout<<"Student Information"<<endl;
cout<<"Student Roll No : "<<rollno<<endl;
cout<<"Student Name : "<<sname<<endl;
cout<<"-----------------------"<<endl;
cout<<"Student Marks"<<endl;
cout<<"Marks1 : "<<m1<<endl;
cout<<"Marks2 : "<<m2<<endl;
cout<<"Marks3 : "<<m3<<endl;
cout<<"Total : "<<total<<endl;
cout<<"Percentage : "<<per<<endl;
}
};
int main()
{
Marks mar;
mar.setmarks();
mar.show();
return 0;
}
#include<iostream>
using namespace std;
class A
{
public:
A()
{
cout << "Class A" << endl;
}
};
class B
{
public:
B()
{
cout << "Class B" << endl;
}
};
class C
{
public:
C()
{
cout<<"Class C"<<endl;
}
};
class D: public C, public B, public A // Note the order. Class C, Class B and then Class A
{
public:
D()
{
cout << "Class D" << endl;
}
};
int main()
{
D d;
return 0;
}
#include <iostream>
using namespace std;
class A
{
public:
void show()
{
cout<<"Class A - Base Class";
}
};
class B : public A
{
};
class C : public B
{
};
int main()
{
C c;
c.show();
return 0;
}
class base_class
{
. . .
};
class first_derived_class : access_specifier base_class
{
. . .
};
class second_derived_class : access_specifier base_class
{
. . .
};
class third_derived_class : access_specifier base_class
{
. . .
};
#include <iostream>
using namespace std;
class Shape
{
public:
Shape()
{
cout<<"Base Class - Shape"<<endl;
}
};
class Rectangle : public Shape
{
public:
Rectangle()
{
cout<<"Derived Class - Rectangle"<<endl;
}
};
class Triangle : public Shape
{
public:
Triangle()
{
cout<<"Derived Class - Triangle"<<endl;
}
};
class Circle : public Shape
{
public:
Circle()
{
cout<<"Derived Class - Circle"<<endl;
}
};
int main()
{
Rectangle r;
cout<<"---------------------------"<<endl;
Triangle t;
cout<<"---------------------------"<<endl;
Circle c;
return 0;
}
#include<iostream>
using namespace std;
class Student
{
protected:
int rollno;
public:
void get_rollno(int r)
{
rollno=r;
}
void show_rollno(void)
{
cout<<"Student Result"<<endl;
cout<<"----------------------------"<<endl;
cout<<"Roll no : "<<rollno<<"\n";
}
};
class Test:public virtual Student
{
protected:
float mark1, mark2;
public:
void get_marks(float m1,float m2)
{
mark1 = m1;
mark2 = m2;
}
void show_marks()
{
cout<<"Marks obtained:"<<endl;
cout<<"Mark1 = "<<mark1<<"\n"<<"Mark2 = "<<mark2<<"\n";
}
};
class Sports : public virtual Student
{
protected:
float score;
public:
void get_score(float s)
{
score = s;
}
void show_score(void)
{
cout<<"Sport Scores = "<<score<<"\n";
}
};
class Result: public Test, public Sports
{
float total;
public:
void show(void);
};
void Result :: show(void)
{
total = mark1 + mark2 + score;
show_rollno();
show_marks();
show_score();
cout<<"----------------------------"<<endl;
cout<<"Total Score = "<<total<<"\n";
}
int main()
{
Result re;
re.get_rollno(101);
re.get_marks(60,65);
re.get_score(6.0);
re.show();
return 0;
}