C++, Programmimg Languages

Write a program of multilevel inheritance having 3 classes person, student & exam.

#include<iostream.h>

const int size = 50;

class person

{

char name[20];

int age;

char sex;

Public:

void get_data()

{

cout<<“Name=”;

cin>>name;

cout<<“Age=”;

cin>>age;

cout<<“Sex=”;

cin>>sex;

}

void display ()

{

cout<<“Name=”<<name<<endl;

cout<<“Age=”<<age<<endl;
cout<<“Sex=”<<sex<<endl;
}

};

class student:: public person 

{

private:

int rollno;

char branch[50];

public:

get_data()

{

person::get_data();

cout<<“Roll No.=”;

cin>>rollno;

cout<<“Branch=”;

cin>>branch;

}

void display ()

{

person::display();

cout<<“Roll No.=”<<rollno<<endl;

cout<<“Branch=”<<branch<<endl;

}

};

class exam::public student

{

int marks1;

int marks2;

public:

void get_data()

{

student:: get_data();

cout<<“Marks of first subject=”;

cin>>marks1;

cout<<“Marks of second subject=”;

cin>>marks2;

}

void display ()

{

person::display();

cout<<“Marks of first subject=”<<marks1<<endl;

cout<<“Marks of second subject=”<<marks2<<endl;

}

}

};
void main()

{

exam e;

cout<<“Enter the data”<<endl;

e.get_data()!

cout<<“Details of students “<<endl;

e.display ();

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s