Tech

Multilevel Inheritance

// An example for Multilevel Inheritance
#include<iostream.h>
#include<conio.h>
#include<string.h>
class student    // base class
{
private:
int rl;
char nm[20];
public:
void read();
void display();
};
class marks : public student // dervivec from student
{
protected:
int s1;
int s2;
int s3;
public:
void getmarks();
void putmarks();
};
class result : public marks // derived  from marks
{
private:
int t;
float p;
char div[10];
public:
void process();
void printresult();
};
void student::read()
{
cout<<“enter Roll no and Name “<<endl;
cin>>rl>>nm;
}
void student:: display()
{
cout <<“Roll NO:”<<rl<<endl;
cout<<“name : “<<nm<<endl;
}
void marks ::getmarks()
{
cout<<“enter three subject marks  “<<endl;
cin>>s1>>s2>>s3;
}
void marks ::putmarks()
{
cout <<“subject 1:”<<s1<<endl;
cout<<” subject 2 : “<<s2<<endl;
cout <<“subject 3:”<<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::printresult()
{
cout<<“total = “<<t<<endl;
cout<<“per  = “<<p<<endl;
cout<<“div = “<<div<<endl;
}
void main()
{
result x;
clrscr();
x.read();
x.getmarks();
x.process();
x.display();
x.putmarks();
x.printresult();
getch();
}

Advertisements

About Sri

A species who has a little of more things combined together. Strongly believes that "Art is long, life is short" and a lifetime is insufficient to master even one. ~ Silent ~ Silly atTimes ~ Truthful Always

Discussion

No comments yet.

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

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 499 other followers

Blog Stats

  • 330,904 views

Blog categories..

On My twitter now !

This is me :)

%d bloggers like this: