Answer to Question #329366 in C++ for namrata

Question #329366

Create classes as per below structure and add below functionalities



1. Add getter and setter member functions and display function in student, Test and sports



classes.



2. Result class only display all the data of Student, sports and test. and also calculate the total as



Total= marks of subject+ score for sports and display that also.

1
Expert's answer
2022-04-16T06:47:55-0400
#include<iostream>
#include<string>

using namespace std;

class Test
{
	float submarks;
public:
	Test():submarks(0){}
	void Setmarks(float marks)
	{
		submarks = marks;
	}
	float Getmarks() { return submarks; }
};

class Sports
{
	float sportmarks;
public:
	Sports() :sportmarks(0) {}
	void SetSports(float marks)
	{
		sportmarks = marks;
	}
	float GetSports() { return sportmarks; }
};


class Student:public Test,public Sports
{
	string name;
	float total;
public:
	Student():name(""),total(0){}
	void SetName(string nm) { name = nm; }
	string GetName() { return name; }
	float GetTotal() { return total; }
	float CalculateTotal()
	{
		total = GetSports() + Getmarks();
		return total;
	}
};


int main()
{
	Student s;
	s.SetName("Jack");
	s.Setmarks(50);
	s.SetSports(30);
	s.CalculateTotal();
	cout << s.GetName() << " marks of subject " << s.Getmarks() 
		<< "\nscore for sports " << s.GetSports();
	cout << "\nThe total is " << s.GetTotal();
}





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