Answer to Question #236664 in C++ for xyz

Question #236664

Create a class student which stores name, roll number and age of a student. Derive a

class test from student class, which stores marks in 5 subjects. Input and display the

details of a student.Extend this program to derive a class from result from class ‘test’ which includes

member function to calculate total marks and percentage of a student. Input the data for a

student and display its total marks and percentage.


1
Expert's answer
2021-09-13T12:18:41-0400
#include<iostream>
using namespace std;
class student{
	private:
		string name;
		string roll_number;
		int  age; 
};


class test: public student{
	private:
		int mark1, mark2, mark3, mark4, mark5;
	public:
		void input(int m1, int m2, int m3, int m4, int m5){
			cout<<"Enter the student's marks\n";
			cout<<"Mark 1\n";
			cin>>m1;
			cout<<"Mark 2\n";
			cin>>m2;
			cout<<"Mark 3\n";
			cin>>m3;
			cout<<"Mark 4\n";
			cin>>m4;
			cout<<"Mark 5\n";
			cin>>m5;
			mark1=m1; mark2=m2; mark3=m3; mark4=m4; mark5=m5;
			
		}
		
		int getMark1(){
			return mark1;
		}
		
		int getMark2(){
			return mark2;
		}
		
		int getMark3(){
			return mark3;
		}
		int getMark4(){
			return mark4;
		}
		int getMark5(){
			return mark5;
		}
		
		void display(){
			cout<<"The student's marks are:\n";
			cout<<"Mark 1: "<<mark1<<"\nMark 2:  "<<mark2<<"\nMark 3: "<<mark3<<"\nMark 4: "<<mark4<<endl;
			cout<<"Mark 5:  "<<mark5<<endl;
		}
};
class Result: public test{
	public:
		
		void calculate_totalMarks(){
			int m1, m2, m3,m4,m5;
			input(m1, m2, m3,m4,m5);
			int total = getMark1() + getMark2() + getMark3() + getMark4() + getMark5();
			display();
			cout<<"The total marks is:  "<<total<<endl;
			cout<<"The percentage is:    "<<total /5;
		}
};
int main(){


 Result r;
 r.calculate_totalMarks();
	
}

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