Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

//A program to illustrate multilevel inheritance #include<iostream.h> #include<conio.h> #include<stdio.

h> class admin { char name[30]; int adno; public: void getadmin(); void putadmin(); }; void admin::getadmin() { cout<<"\n\nEnter the name:"; gets(name); cout<<"\nEnter the admission no:"; cin>>adno; } void admin::putadmin() { cout<<"\nName of the student:"; cout<<name; cout<<"\nAdmission no:"; cout<<adno; } class acad { int rno; float totmrks; public: void get_acad(); void put_acad(); }; void acad::get_acad() { cout<<"\nEnter the roll no:"; cin>>rno; cout<<"\nEnter total marks:"; cin>>totmrks; } void acad::put_acad() { cout<<"\nRoll no:", cout<<rno; cout<<"\nTotal marks:"; cout<<totmrks; } class school:public admin,public acad { char sports[15]; char house[15]; public: void admin(); void academics(); void get_school(); void put_school(); }; void school::get_school() { getadmin(); get_acad(); cout<<"\nEnter the house:"; gets(house); cout<<"\nEnter the sport chosen:"; gets(sports); } void school::put_school() { putadmin(); put_acad(); cout<<"\nHouse:"; cout<<house; cout<<"\nSports chosen:"; cout<<sports; } void main() { clrscr; school obj[10]; int i,j,n; cout<<"\nEnter the number of students:"; cin>>n; cout<<"\nEnter student details:"; for(i=0;i<n;i++) //Enter student details { obj[i].get_school(); } cout<<"\nThe student details are:"; for(j=0;j<n;j++) //display student details { obj[j].put_school(); } getch(); }

OUTPUT Enter the number of students:3 Enter student details: Enter the name:Karun Enter the admission no:1254 Enter the roll no:16 Enter total marks:81 Enter the house:Cauvery Enter the sport chosen:Football Enter the name:Vishal Enter the admission no:1689 Enter the roll no:31 Enter total marks:84 Enter the house:Gangotri Enter the sport chosen:Basketball Enter the name:Tom Enter the admission no:1564 Enter the roll no:25 Enter total marks:79 Enter the house:Gangotri Enter the sport chosen:Football The student details are: Name of the student:Karun Admission no:1254 Roll no:16 Total marks:81 House:Cauvery Sports chosen:Football Name of the student:Vishal Admission no:1689 Roll no:31 Total marks:84 House:Gangotri Sports chosen:Basketball Name of the student:Tom Admission no:1564 Roll no:25 Total marks:79 House:Narmada Sports chosen:Football

You might also like