Multi level inheritance

Multi level inheritance:

In multi level inheritance a single derived class may inherit from two or more than two base class

multilevel

 

Example

#include<iostream.h>

#include<conio.h>

#include<string.h>

class student //

base class

{

private: int rl;

char nm[20];

public: void reads();

void disp(); };

class mark : public student // dervivec from student

{

protected: int s1;

int s2; int s3;

public: void getmark();

void putmark();

};

class result : public mark // derived from marks

{

private: int t;

float p;

char div[10];

public: void process();

void dispresult();

};

void student::reads()

{

cout<<“enter Roll no and Name “<<endl;

cin>>rl>>nm;

}

void student:: disp()

{

cout <<“Roll NO:”<<rl<<endl;

cout<<“name : “<<nm<<endl;

}

void mark ::getmark()

{

cout<<“enter three subjects mark “<<endl;

cin>>s1>>s2>>s3;

}

void marks ::putmark()

{

cout <<” 1st sub mrk:-“<<s1<<endl;

cout<<” 2nd sub mrk:- “<<s2<<endl;

cout <<” 3rd sub mrk:-“<<s3<<endl;

}

void result::process()

{

t= s1+s2+s3; p = t/3.0;

p>=60?strcpy(div,”first”):p>=50?strcpy(div, “second”): strcpy(div,”third”);

}

void result::dispresult()

{

cout<<“total = “<<t<<endl;

cout<<“per = “<<p<<endl;

cout<<“div = “<<div<<endl;

}

void main()

{

result x;

clrscr();

x.reads();

x.getmark();

x.process();

x.disp();

x.putmark();

x.dispresult();

getch();

}

Output
Output:-

Enter roll no & name

12

Ram

Enter three subjects mark

90

67

89

ROllno.: 12

Name :Ram

1st sub:-90

2nd sub:-67

3rd sub:-89

Total=246

Per=82

Div=first

Leave a Reply

Your email address will not be published. Required fields are marked *