Answer to Question #216118 in C++ for honey

Question #216118

Design four classes: Student, Exam ,Sports and Result.  The Student class has data members such as reg. number, name. Create Exam by inheriting the Student. The Exam class adds data members representing the marks scored in 3 subjects. Create Sports by inheriting the Student. The Sports class adds data members representing the marks scored in indoor and outdoor games. Derive the Result from the Exam , Sports and Result  has its own data member of Total mark. Write an interactive program with appropriate member functions to model this relationship.


1
Expert's answer
2021-07-11T14:34:15-0400


#include<iostream>
#include<bits/stdc++.h>
using namespace std;


class Student{
	public:
		int reg_no;
		string name;
		
		void input()
		{
			cout<<"Enter student name : ";
			string s;
			cin>>s;
			name = s;
			cout<<"Enter student regd number : ";
			int n;
			cin>>n;
			reg_no = n;
			cout<<endl<<endl;
		}
		
};


class Exam : public Student{
	public:
		int sub1;
		int sub2;
		int sub3;
		
		void input1()
		{
			cout<<"Enter student marks in sub1 : ";
			int a;
			cin>>a;
			cout<<"Enter student marks in sub2 : ";
			int b;
			cin>>b;
			cout<<"Enter student marks in sub3 : ";
			int c;
			cin>>c;
			sub1 = a;
			sub2 = b;
			sub3 = c;
			cout<<endl<<endl;
		}
		
		
};


class Sports : public Student{
	public:
		int indoor;
		int outdoor;
		
		void input2()
		{
			cout<<"Enter student marks in indoor games : ";
			int a;
			cin>>a;
			cout<<"Enter student marks in outdoor games : ";
			int b;
			cin>>b;
			indoor = a;
			outdoor = b;
			cout<<endl<<endl;
		}
}; 


class Result : public Exam, public Sports{
	public:
		int total_marks;
		
		int get_total()
		{
			total_marks = sub1 + sub2 + sub3 + indoor + outdoor;
			return total_marks;
		}
		
		
};


int main()
{
	Student s;
	s.input();
	Result ob;
	ob.input1();
	ob.input2();
	
	cout<<"Total marks gained by student is : "<<ob.get_total()<<"/500";
	
}




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