Create the classes as per the hierarchy given below. The data members are mentioned along with class name. Include parameterized constructor in all the classes. Input data at run-time for a student, calculate the total marks and percentage and display them.
Student: Name, Roll Number
|
V
Marks: marks in 5 subjects
|
V
Result: total marks, percentage
#include <iostream>
using namespace std;
class Student{
private:
string Name;
int Roll_Number
public:
void getData1(){
cout<<"\nEnter name: ";
cin>>Name;
cout<<"\nEnter Roll Number: ";
cin>>Roll_Number;
}
void disp1(){
cout<<"\nName: "<<Name;
cout<<"\nRoll Number: "<<Roll_Number;
}
};
class Marks: public Student{
private:
int marks[5];
public:
void getData(){
cout<<"\nEnter marks in 5 subjects: ";
for(int i=0;i<5;i++){
cin>>marks[i];
}
int sum=0;
for(int i=0;i<5;i++){
sum+=i;
}
double perc=(sum/500)*100;
cout<<"\nTotal Marks: "<<sum;
cout<<"\nPercentage: "<<perc;
}
};
class Result: public Marks{
private:
int total_marks;
int percentage;
};
int main()
{
Result r;
r.disp1();
return 0;
}
Comments
Thanks a lot AssignmentExpert
Leave a comment