Answer to Question #280212 in C++ for Kandha

Question #280212

We want to calculate the total marks of each student of a class in Physics,Chemistry and





Mathematics and the average marks of the class. The number of students in the class are entered





by the user. Create a class named Marks with data members for roll number, name and marks.





Create three other classes inheriting the Marks class, namely Physics, Chemistry and





Mathematics, which are used to define marks in individual subject of each student. Roll number





of each student will be generated automatically.






1
Expert's answer
2021-12-16T14:31:31-0500
#include<iostream>
using namespace std;
class Marks {
	public:
	  int roll_number = 0;
	 string name;
	 int  marks;
	 
};


class Physics: Marks  {
	public:
		int input(){
			cout<<"Enter marks for Physics: \n";
			cin>>marks;
			return marks;
		}
};


class Chemistry: Marks{
	public:
			int input(){
			cout<<"Enter marks for Chemistry: \n";
			cin>>marks;
			return marks;
		}
};
  
class Mathematics: Marks{
	public:
			int input(){
			cout<<"Enter marks for Mathematics: \n";
			cin>>marks;
			return marks;
		}
};


int main(){
	Physics p;
	Chemistry c;
	Mathematics m;
	cout<<"Enter the number of students:\n";
	int n;
	cin>>n;
	int total [n];
	for(int i=0; i<n; i++){
		int ph = p.input();
		int ch = c.input();
		int mat = m.input();
		int sum = ph + ch + mat;
		int av = sum /3;
		total[i] = av;
	}
	
	for(int i=0; i<n; i++){
		cout<<total[i]<<"  ";
	}
}















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