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 <string>
using namespace std;
class Student
{
protected:
string rollno;
string name;
public:
void setData(string rollno,string name){
this->rollno = rollno;
this->name = name;
}
};
class Fees: public Student
{
protected:
int fees;
public:
void submitFees(int fees){
this->fees = fees;
}
void generateReceipt()
{
cout<<"Fee Receipt:";
cout<<"\nRoll No.: "<<this->rollno;
cout<<"\nName: "<<this->name;
cout<<"\nFee: "<<this->fees;
}
};
class Result: public Fees
{
private:
int tests;
int activities;
int sports;
int totalMarks;
string grade;
public:
void setMarks(int tests, int activities, int sports)
{
this->tests=tests;
this->activities = activities;
this->sports = sports;
this->totalMarks = tests + activities + sports;
float average=this->totalMarks/3.0;
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";
}
}
void generateReceipt(void)
{
Fees::generateReceipt();
cout<<"\n\nMarks Receipt:";
cout<<"\nMarks in Tests: "<<tests;
cout<<"\nMarks in Activities: "<<activities;
cout<<"\nMarks in Sports: "<<sports;
cout<<"\nTotal Marks: "<<totalMarks;
cout<<"\nFinal Grade: "<<grade;
}
};
int main(void)
{
Result student;
student.setData("7855554","Mary Clark");
student.submitFees(80);
student.setMarks(80,70,90);
student.generateReceipt();
cout<<"\n\n\n";
system("pause");
return 0;
}
Comments
Leave a comment