//PROGRAM TO IMPLEMENT MULTILEVEL INHERITENCE
/*MADE BY KRISHNA AGARWAL*/
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int roll_number;
public:
void get_number();
void put_number();
};
void student::get_number()
{
int k;
cout<<"enter the roll number\n";
cin>>k;
roll_number=k;
}
void student::put_number()
{
cout<<"\nroll number = "<<roll_number<<"\n";
}
class test:public student
{
protected:
float sub1;
float sub2;
public:
void get_marks();
void put_marks();
};
void test::get_marks()
{
float p,q;
cout<<"enter the marks in two subjects\n";
cin>>p>>q;
sub1=p;
sub2=q;
}
void test::put_marks()
{
cout<<"\nmarks in sub1 is = "<<sub1<<endl;
cout<<"marks in sub2 is = "<<sub2<<endl;
}
class result: public test
{
float total;
public:
void display(void);
};
void result::display()
{
total=sub1 + sub2;
put_number();
put_marks();
cout<<"\ntotal = "<<total<<"\n";
}
//-----------------------------------------
void main()
{
clrscr();
result student1;
student1.get_number();
student1.get_marks();
student1.display();
getch();
}
/*MADE BY KRISHNA AGARWAL*/
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int roll_number;
public:
void get_number();
void put_number();
};
void student::get_number()
{
int k;
cout<<"enter the roll number\n";
cin>>k;
roll_number=k;
}
void student::put_number()
{
cout<<"\nroll number = "<<roll_number<<"\n";
}
class test:public student
{
protected:
float sub1;
float sub2;
public:
void get_marks();
void put_marks();
};
void test::get_marks()
{
float p,q;
cout<<"enter the marks in two subjects\n";
cin>>p>>q;
sub1=p;
sub2=q;
}
void test::put_marks()
{
cout<<"\nmarks in sub1 is = "<<sub1<<endl;
cout<<"marks in sub2 is = "<<sub2<<endl;
}
class result: public test
{
float total;
public:
void display(void);
};
void result::display()
{
total=sub1 + sub2;
put_number();
put_marks();
cout<<"\ntotal = "<<total<<"\n";
}
//-----------------------------------------
void main()
{
clrscr();
result student1;
student1.get_number();
student1.get_marks();
student1.display();
getch();
}
No comments:
Post a Comment