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.
#include <iostream>
#include <map>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
//Implement class Student
class Student
{
private:
int rollno;//member rollno
string name;//name
public:
//default constructor
Student()
{
this->name = "";//emprty name
this->rollno = 0;
}
//Parametr constructor
Student(int _rol, string _name)
{
this->name = _name;
this->rollno = _rol;
}
//Getter and setter
void setName(const string nm)
{
this->name = nm;
}
void setRoll(int rol)
{
this->rollno = rol;
}
string getName()const
{
return this->name;
}
int getRoll()const
{
return this->rollno;
}
};
//direve class Fees from Student
class Fees :public Student
{
private:
double pr;//fees date $
public:
//constructor
Fees(double pay,string name_stud):Student(0,name_stud)
{
this->pr = 0.0;
}
//submit and generate receipt
string submit()
{
//generate receipt
string ans = "########################\n";
ans += " PAY " + std::to_string(this->pr) + "\n";
return ans;
}
};
//direve class Result
class Result :public Student
{
private:
//the marks test
vector<int>testMark;
int marKAct;//mark activities
int sportMark;//mark sport
public:
//constructor
Result(string name_Stud, int roll) :
Student(roll, name_Stud)
{
}
void InputDate()
{
cout << "Enter count test: ";
int cnt;
cin >> cnt;
cout << "Please mark of tests:\n";
for (int i = 0; i < cnt; i++)
{
int mrk;
cin >> mrk;
this->testMark.push_back(mrk);
}
cout << "Please enter activities mark: ";
cin >> this->marKAct;
cout << "Please enter mark sport: ";
cin >> this->sportMark;
}
//calc average tests ,activities and sport marks
double resultExec()
{
double sum = 0.0;
for (int i = 0; i < this->testMark.size(); i++)
{
sum += static_cast<double>(testMark[i]);
}
sum += this->sportMark * 1.0;
sum += this->marKAct * 1.0;
sum /= (this->testMark.size() * 1.0 + 2 * 1.0);
return sum;
}
};
int main()
{
vector<Result>st;
cout << "Enter count student: ";
int cnS;
cin >> cnS;
for (int i = 0; i < cnS; i++)
{
int rl;
string nm;
cout << "Please enter rollno and name Student:\n";
cin >> rl;
cin >> nm;
Result rs(nm,rl);
st.push_back(rs);
}
//enter marks
for (int i = 0; i < st.size(); i++)
{
cout << "Please full date from Student " << st[i].getName() << endl;
st[i].InputDate();
}
for (int i = 0; i < st.size(); i++)
{
cout << st[i].getName() << " Common result: " << st[i].resultExec() << endl;
}
return 0;
}
Comments
Leave a comment