0% found this document useful (0 votes)
44 views

Inheritance Program in C++

The document discusses inheritance in C++ through multiple code examples. It defines base classes A and B and derives several other classes from them to demonstrate inheritance. The derived classes inherit properties and methods from their respective base classes. Constructors are called in the defined order of inheritance from base to derived classes during object instantiation.

Uploaded by

Rinku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Inheritance Program in C++

The document discusses inheritance in C++ through multiple code examples. It defines base classes A and B and derives several other classes from them to demonstrate inheritance. The derived classes inherit properties and methods from their respective base classes. Constructors are called in the defined order of inheritance from base to derived classes during object instantiation.

Uploaded by

Rinku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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