Write a Program to declare examination results. Design three classes: Student,
Exam, Result, The Student class has the data members such as Rollno and name.
Create the class Exam by inheriting the Student class. The Exam class includes
the data members representing the marks scored in six subjects. Derive the
Result from Exam class and it has its own data members such as Total_marks,
grade and display the student information in descending order. Design the
inheritance this model belongs to.
#include<iostream>
using namespace std;
class student {
protected:
int rno, subject1, subject2,subject3,subject4,subject5,subject6;
public:
void get() {
cout << "Enter the Roll no :";
cin>>rno;
cout << "Enter the six marks :";
cin >>subject1>>subject2>>subject3>>subject4>>subject5>>subject6;
}
};
class exam {
protected:
int subject1;
int subject2;
int subject3;
int subject4;
int subject5;
int subject6; // sm = Sports mark
public:
void getsm() {
cout << "\nEnter the First subject mark :";
cin>>subject1;
cout << "\nEnter the second subject mark :";
cin>>subject2;
cout << "\nEnter the third subject mark :";
cin>>subject3;
cout << "\nEnter the fourth subject mark :";
cin>>subject4;
cout << "\nEnter the fifth subject mark :";
cin>>subject5;
cout << "\nEnter the sixth subject mark :";
cin>>subject6;
}
};
class result : public student, public exam {
int tot, avg;
public:
void display() {
tot = subject1+subject2+subject3+subject4+subject5+subject6;
avg = tot / 3;
cout << "\n\n\tRoll No : " << rno << "\n\tTotal : " << tot;
cout << "\n\tAverage : " << avg;
}
};
int main() {
statement obj;
obj.get();
obj.getsm();
obj.display();
getch();
}
Comments
Leave a comment