Answer to Question #174017 in C++ for VARUN

Question #174017


Design a C++ program having a base class Student with data member rollno and member functions getnum() to input rollno and putnum() to display rollno. The class Test is derived from class Student with data member marks (Three subject marks) and member functions getmarks() to input marks and putmarks() to display marks. The class Sports is also derived from class Student with data member score (range between 100) and member functions getscore() to input score and putscore() to display score. The class Result is inherited from two base classes, class Test and class Sports with data member total and a member function display() to display rollno, marks, score and the total (marks + score).



1
Expert's answer
2021-03-22T07:26:49-0400
#include <iostream>
class Student
{
public:
	int rolno{0};
	virtual void getnum() 
	{
		std::cout << "Enter roll_No"<<std::endl;
		std::cin >> rolno;
	 }
	virtual void putnum()
	{
		std::cout << "roll_No"<<rolno<<std::endl;
	}
};
class Test :public virtual Student
{
public:
	int mark_1{0};
	int mark_2{0};
	int mark_3{0};
	void getmarks() 
	{
		std::cout << "Enter mark_1 "<<std::endl;
		std::cin >> mark_1;
		std::cout << "Enter mark_2 " << std::endl;
		std::cin >> mark_2;
		std::cout << "Enter mark_3 " << std::endl;
		std::cin >> mark_3;
	}
	void putmarks()
	{
		std::cout << " mark_1 " << mark_1<<std::endl;
		std::cout << " mark_2 " << mark_2 << std::endl;
		std::cout << " mark_3 " << mark_3 << std::endl;
		std::cout << " total marks " << mark_1+ mark_2 + mark_3 << std::endl;
	}
};


class Sport :public virtual Student
{
public:
	int score{0};
	void getscore()
	{
		std::cout << "Enter member score" << std::endl;
		std::cin >> score;
	}
	void putscore()
	{
		std::cout << "member score " << score<<std::endl;
	}
};
class Result :public Test, public Sport
{
public:
	void display() {
		putnum();
		putmarks();
		putscore();
		std::cout << "total score " << mark_1 + mark_2 + mark_3 + score << std::endl;
	}
};
int main()
{
\\ example 
	Result r1;
	r1.getnum();
	r1.getmarks();
	r1.getscore();
	r1.display();
	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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS