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.
#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();
}
Comments
Leave a comment