Monday, April 5, 2021

Multilevel inheritance (OOP) (21)

 /*multilevel inheritance

                                ************************/

#include<iostream>

using namespace std;

class student  //this is parent class named student

{

protected: //this is the protected part of the class

int roll;

public://this is the public part of the class

void get_roll(int);

void put_roll();

};

class study:public student  //this is the child class of the student class and parent class of the test class

{

protected: //this is the protected part of the class

float m1,m2;

public://this is the public part of the class

void get_marks(float,float);

void put_marks();

};

class test:public study // this is the child class of the class study

{

protected: //this is the protected part of the class

int total;

public://this is the public part of the class

void display();

};

void student::get_roll(int x) //here we define the function of our class named student

{

roll=x;

}

void student::put_roll()//here we define the function of our class named student

{

cout<<"roll number is:"<<roll<<endl;

}

void study:: get_marks(float u,float y)//here we define the function of our class named study

{

m1=u;

m2=y;

}

void study :: put_marks()//here we define the function of our class named study

{

cout<<"your marks in english are:"<<m1<<endl;

cout<<"your marks in programming are:"<<m2<<endl;;

}

void test::display()//here we define the function of our class named test

{

total=m1+m2;

cout<<"total numbers in both subject are:"<<total<<endl;

}

int main()

{

int a;

float b,c;

test o;

cout<<"please enter your roll number:";

cin>>a;

cout<<"please enter your marks in english:";

cin>>b;

cout<<"please enter your marks in programming:";

cin>>c;

o.get_roll(a);

o.get_marks(b,c);

cout<<endl;

o.put_roll();

o.put_marks();

o.display();

} 

No comments:

Post a Comment