You are on page 1of 15

Inheritance program in c++

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class person
{
public:
char name[100],street[100],city[100],DateOfBirth[100];
long int pin,aadharNumber;
person()
{
clrscr();
cout<<"\nEnter your name:";
gets(name);
cout<<"\nEnter your street name:";
gets(street);
cout<<"\nEnter your city:";
gets(city);
cout<<"\nEnter your Pincode:";
cin>>pin;
cout<<"\nEnter your Date of Birth:";
gets(DateOfBirth);
cout<<"\nEnter your Aadhar Number:";
cin>>aadharNumber;
}
};
class display
{
public:
char name[100],street[100],city[100],DateOfBirth[100];
long int pin,aadharNumber;
display()
{
clrscr();
cout<<"\nName:"<<name;
cout<<"\nStreet name:"<<street;
cout<<"\nCity:"<<city;
cout<<"\nPincode:"<<pin;
cout<<"\nDate of Birth:"<<DateOfBirth;
cout<<"\nAadhar Number:"<<aadharNumber;
}
};
void main()
{
display d;
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class person
{
public:
char name[100],street[100],city[100],DateOfBirth[100];
long int pin,aadharNumber;
person()
{
clrscr();
cout<<"\nEnter your name:";
gets(name);
cout<<"\nEnter your street name:";
gets(street);
cout<<"\nEnter your city:";
gets(city);
cout<<"\nEnter your Pincode:";
cin>>pin;
cout<<"\nEnter your Date of Birth:";
gets(DateOfBirth);
cout<<"\nEnter your Aadhar Number:";
cin>>aadharNumber;
}
};
class student:public person
{
public:
char roll[10],course[100],prog[100];
student()
{
cout<<"\nEnter your Roll No:";
gets(roll);
cout<<"\nEnter your Course Registered:";
gets(course);
cout<<"\nEnter your Programme:";
gets(prog);
cout<<"\nName:"<<name;
cout<<"\nStreet name:"<<street;
cout<<"\nCity:"<<city;
cout<<"\nPincode:"<<pin;
cout<<"\nDate of Birth:"<<DateOfBirth;
cout<<"\nAadhar Number:"<<aadharNumber;
cout<<"\nRoll No:"<<roll;
cout<<"\nCourse Registered:"<<course;
cout<<"\nProgramme:"<<prog;
getch();
}
};
void main()
{
student s;
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class person
{
public:
char name[100],street[100],city[100],DateOfBirth[100];
long int pin,aadharNumber;
person()
{
clrscr();
cout<<"\nEnter your name:";
gets(name);
cout<<"\nEnter your street name:";
gets(street);
cout<<"\nEnter your city:";
gets(city);
cout<<"\nEnter your Pincode:";
cin>>pin;
cout<<"\nEnter your Date of Birth:";
gets(DateOfBirth);
cout<<"\nEnter your Aadhar Number:";
cin>>aadharNumber;
}
};
class teacher:public person
{
public:
char course[100],dept[100],qual[100];
int sal,exp;
teacher()
{
cout<<"\nEnter your Department:";
gets(dept);
cout<<"\nEnter your Course Taught:";
gets(course);
cout<<"\nEnter your Salary:";
cin>>sal;
cout<<"\nEnter your Qualification:";
gets(qual);
cout<<"\nEnter your Experience:";
cin>>exp;
cout<<"\nName:"<<name;
cout<<"\nStreet name:"<<street;
cout<<"\nCity:"<<city;
cout<<"\nPincode:"<<pin;
cout<<"\nDate of Birth:"<<DateOfBirth;
cout<<"\nAadhar Number:"<<aadharNumber;
cout<<"\nDepartment:"<<dept;
cout<<"\nCourse Taught:"<<course;
cout<<"\nQualification:"<<qual;
cout<<"\nSalary:"<<sal;
cout<<"\nExperience:"<<exp;
getch();
}
};
void main()
{
teacher s;
}
#include<iostream.h>
#include<conio.h>

class A
{
public:
A()
{
cout<<"A is basic constructor"<<endl;
}
};

class B: public A
{
public:
B()
{
cout<<"B is derived constructor"<<endl;
}
};

class C: public B
{
public:
C()
{
cout<<"C is derived constructor"<<endl;
}
};

void main()
{
clrscr();
C c;
getch();
}
#include<iostream.h>
#include<conio.h>

class A
{
public:
A()
{
cout<<"A is basic constructor"<<endl;
}
};

class B: public A
{
public:
B()
{
cout<<"B is derived constructor"<<endl;
}
};

class C: public A
{
public:
C()
{
cout<<"C is derived constructor"<<endl;
}
};

void main()
{
clrscr();
B b;
C c;
getch();
}
#include<iostream.h>
#include<conio.h>

class A
{
public:
A()
{
cout<<"A is basic constructor"<<endl;
}
};

class B: public A
{
public:
B()
{
cout<<"B is derived constructor"<<endl;
}
};

class C: public A
{
public:
C()
{
cout<<"C is derived constructor"<<endl;
}
};

class D: public B, public C


{
public:
D()
{
cout<<"D is derived constructor"<<endl;
}
};

void main()
{
clrscr();
B b;
C c;
D d;
getch();
}
#include<iostream.h>
#include<conio.h>

class A
{
public:
A()
{
cout<<"A is basic constructor"<<endl;
}
};

class B
{
public:
B()
{
cout<<"B is a basic constructor"<<endl;
}
};

class C: public A, public B


{
public:
C()
{
cout<<"C is derived constructor"<<endl;
}
};

void main()
{
clrscr();
C a;
getch();
}

You might also like