Monday, January 20, 2014

C++ Program to Find Students Details Using MultiLevel Inheritance

with 0 Comment
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int rollno;
char sname[10];
public:
void get_rollno()
{
cout<<"\n Enter the Roll no:";
cin>>rollno;
cout<<"\n Enter the Student name:";
cin>>sname;
}
void disproll()
{
cout<<rollno;
cout<<"\t"<<sname;
}
};
class test::public student
{
protected:
int m1,m2,m3;
public:
void get_marks()
{
cout<<"\n Enter the mark1:";
cin>>m1;
cout<<"\n Enter the mark2:";
cin>>m3;
cout<<"\n Enter the mark3:";
cin>>m3;
}
void dispmarks()
{
cout<<"\t"<<m1;
cout<<"\t"<<m2;
cout<<"\t"<<m3;
}
};
class result:public test
{
int tot;
public:
void calculate()
{
tot=m1+m2+m3;
}
void disptot()
{
cout<<"\t"<<tot;
}
};
void main()
{
int n;
result r[10];
clrscr();
cout<<"\t\t MULTILEVEL INHERITANCE \n";
cout<<"\t\t -------------------------\n";
cout<<"\n Enter the no.of students:";
cin>>n;
for(int i=1;i<=n;i++)
{
cout<<"\n Student:"<<i<<"\n";
r[i].get_rollno();
r[i].get_marks();
r[i].calculate();
}
cout<<"\t\t STUDENT DETAILS \n";
cout<<"\n ------------------ \n";
cout<<"SNO\tSNAME\tM1\tM2\tM3\tTOTAL\n";
cout<<"\n--------------------------------\n";
for(i=1;i<=n;i++)
{
r[i].disproll();
r[i].dispmarks();
r[i].disptot();
cout<<"\n";
}
cout<<"\n ----------------------------------\n";
getch();
}

------------
OUTPUT:
------------

MULTILEVEL INHERITANCE:
----------------------------------------
Ente the no.of students:2
Student:1
Enter the Roll no:101
Enter the Student name: KARTHIKA
Enter the mark1:90
Enter the mark2:85
Enter the mark3:95
Student:2
Enter the Roll no:102
Enter the Student name: SUCILA
Enter the mark1:85
Enter the mark2:75
Enter the mark3:60


                               STUDENT DETAILS
----------------------------------------------------------------------
SNO     SNAME           M1     M2        M3         TOTAL
101    KARTHIKA        90      85          95           270
102     SUCILA             85      75          60           220
----------------------------------------------------------------------

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive