Write a c++ program to implement multilevel inheritance by creating classes:
College—> name_id, location,dept
Student—>name ,reg_no, course, age
DOB—>date, month, year, place
#include
using namespace std;
class College {
int name_id;
char location[30],dept[30];
public :
void inputCollegeDetails(){
cout<<"Enter name_id:";
cin>>name_id;
cout<<"Enter location.:";
cin>>location;
cout<<"Enter dept:";
cin>>dept;
}
void displayCollege(){
cout << "\nid =" << name_id;
cout << "\ndept =" << dept ;
cout << "\nlocation =" << location ;
}
};
class DOB: public College{
int date, month, year;
char place[20];
public :
void inputDOB(){
cout<<"Enter date:";
cin>>date;
cout<<"Enter month.:";
cin>>month;
cout<<"Enter year:";
cin>>year;
cout<<"Enter place:";
cin>>place;
}
void displayDate(){
cout << "\ndate="<< date << "-" << month << "-" << year;
cout << "\nplace ="<< place ;
}
};
class student: public DOB
{
private:
char name[20],regd[10],branch[10];
int sem;
public:
void input();
void display();
};
void student::input()
{
cout<<"Enter Name:";
cin>>name;
cout<<"Enter Regdno.:";
cin>>regd;
cout<<"Enter Branch:";
cin>>branch;
cout<<"Enter Sem:";
cin>>sem;
}
void student::display()
{
cout<<"\nName:"<< name;
cout<<"\nRegdno.:"<< regd;
cout<<"\nBranch:"<< branch;
cout<<"\nSem:"<< sem;
}
int main()
{
student s;
s.input();
s.inputDOB();
s.inputCollegeDetails();
s.display();
s.displayDate();
s.displayCollege();
}