Answer to Question #213307 in C++ for Hemambar

Question #213307

Define a class Student with data members as rollno and name. Derive a class Fees from student

that has a data member fees and functions to submit fees and generate receipt. Derive another class

Result from Student that displays the marks and grade obtained by the student. Write a program that

extends the class Result so that the final result of the Student is evaluated based on the marks obtained

in tests, activities and sports.


1
Expert's answer
2021-07-31T07:43:47-0400
#include <iostream>
#include <string>
using namespace std;


class Student
{
    protected:
    	int rollno;
    	string name;
    public:
    	void setData(int r,string n){
    		rollno = r;
    		name = n;
    	}
};




class Fees: public Student
{
    protected:
    	int fees;
    public:
    	void submitFees(int f){ 
    		fees = f;
    	}
    	void generateReceipt()
    	{
    		cout<<"Fee Receipt:";
    		cout<<"Roll No: "<<rollno<<"\n";
    		cout<<"Name: "<<name<<"\n";
    		cout<<"Fee: "<<fees<<"\n";
    	}
};




class Result: public Fees
{
private:
	int tests;
	int activities;
	int sports;
public:
	void setMarks(int tests, int activities, int sports)
	{ 
		this->tests=tests;
		this->activities = activities;
		this->sports = sports;




	}
	void generateReceipt(void)
	{
		float tm = tests + activities + sports;
		float average=tm/3.0;
		char grade;
		if(average>=90)
		{
			grade = 'A';
		}
		else if(average>=80 && average<90)
		{
			grade = 'B';
		}
		else if(average>=70 && average<80)
		{
			grade = 'C';
		}
		else if(average>=60 && average<70)
		{
			grade = 'D';
		}
		else{
			grade = 'F';
		}
		Fees::generateReceipt();
		cout<<"\n\nMarks Receipt:";
		cout<<"Marks in Tests: "<<tests<<"\n";
		cout<<"Marks in Activities: "<<activities<<"\n";
		cout<<"Marks in Sports: "<<sports<<"\n";
		cout<<"Grade: "<<grade<<"\n\n";
	}
};
int main()
{
	Result s1;
	s1.setData(1234,"James");
	s1.submitFees(1000);
	s1.setMarks(92,69,78);
	s1.generateReceipt();
	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