Answer to Question #192877 in C++ for Sankalp

Question #192877

Write a C++ program using multilevel inheritance concept which will display studentinformation ( Roll number ,marks obtain in two subject, total marks) use followinginformation Class student to get and put roll number, class test to get and put marks of twosubject & test will inherit class student• Class Result to compute and display total marks

1
Expert's answer
2021-05-13T07:15:13-0400
#include <iostream>
using namespace std;




class Student{
private:
	int rollNumber;


public:	
	Student(){}


	void putRollNumber(int rollNumber){
		this->rollNumber=rollNumber;
	}


	int getRollNumber(){
		return this->rollNumber;
	}


	~Student(){


	}
};


//class test to get and put marks of two subject & test will inherit class student
class Test: public Student{
private:
	int marks[2];


public:	
	Test(){}


	void putMarks(int mark1,int mark2){
		this->marks[0]=mark1;
		this->marks[1]=mark2;
	}


	int getMark1(){
		return this->marks[0];
	}
	int getMark2(){
		return this->marks[1];
	}


	~Test(){


	}
};


class Result: public Test{


public:	
	Result(){}
	//compute and display total marks
	void computeDisplayTotalMarks(){
		int totalMmarks= getMark1()+getMark2();
		cout<<"Total marks "<<totalMmarks<<"\n";
	}


	~Result(){


	}
};


 


int main(){
	Result result;
	result.putRollNumber(1000);
	result.putMarks(60,50);
	cout<<"Roll number: "<<result.getRollNumber()<<"\n";
	cout<<"Mark 1: "<<result.getMark1()<<"\n";
	cout<<"Mark 2: "<<result.getMark2()<<"\n";
	result.computeDisplayTotalMarks();
	system("pause");
	return 0;
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment