Professional Documents
Culture Documents
#include<iostream>
using namespace std;
class std_basic_info
{
private:
char name[30];
int age;
char gender;
public:
void getBasicInfo(void);
void putBasicInfo(void);
};
int main()
{
std_result_info std;
std.getBasicInfo();
std.getResultInfo();
std.putBasicInfo();
std.putResultInfo();
return 0;
}
2. Write a C++ program which shows all types of inheritance.
#include<iostream>
using namespace std;
class A
{
public:
int a=200;
};
class C
{
public:
int c=20;
};
/*Here as you can see B,D and E inherits a from A. This is known as
Hierarchical Inheritance*/
class F: public E
{
public:
int f=90;
void addAEF()
{
cout<<endl<<"a+e+f="<<a+e+f;
}
}f1;
int main()
{
b1.addAB();
d1.addADC();
e1.addAE();
f1.addAEF();
g1.addABEG();
return 0;
}
3. Write C++ program to implement Virtual base class.
#include<iostream>
using namespace std;
class A
{
public:
int a;
};
int main()
{
D obj;
obj.a = 10;
obj.a = 100;
obj.b = 20;
obj.c = 30;
obj.d = 40;
#include<iostream>
using namespace std;
class Shape
{
public:
void printinfo()
{
cout<<endl<<"This is a Shape";
}
};
int main()
{
Shape s;
Polygon p;
Rectangle r;
Triangle t;
Square sq;
s.printinfo();
p.printinfo();
r.printinfo();
t.printinfo();
sq.printinfo();
return 0;
}
#include<iostream>
using namespace std;
class Animal
{
public:
int weight;
void getweight()
{
cout<<endl<<"Enter Weight:";
cin>>weight;
}
};
int main()
{
Herbivores h;
Carnivores c;
h.getweight();
c.getweight();
return 0;
}