1. Program to design a `Student` class representing student roll numbers, and a `Test` class (derived from `Student`) representing the scores in various subjects, and a `Sports` class representing the score in sports. Inherit `Sports` and `Test` classes into a `Result` class to add scores and display the final result for a student.
#include <iostream.h>
#include<conio.h>
class Student {
public:
int rollNo;
void getRollNo() {
cout << "Enter roll number: ";
cin >> rollNo;
}
void displayRollNo() {
cout << "Roll Number: " << rollNo << endl;
}
};
class Test : public Student {
public:
int marks[5];
void getMarks() {
cout << "Enter marks in 5 subjects: ";
for (int i = 0; i < 5; i++) {
cin >> marks[i];
}
}
void displayMarks() {
cout << "Marks in 5 subjects: ";
int total_marks=0;
for (int i = 0; i < 5; i++) {
cout << marks[i] << " ";
total_marks=total_marks+marks[i];
}
cout <<"\nTotal Marks: "<<total_marks<< endl;
}
};
class Sports : public Test {
public:
int sportsScore;
void getSportsScore() {
cout << "Enter sports score: ";
cin >> sportsScore;
}
void displaySportsScore() {
cout << "Sports Score: " << sportsScore << endl;
}
};
int main() {
Sports student;
student.getRollNo();
student.getMarks();
student.getSportsScore();
student.displayRollNo();
student.displayMarks();
student.displaySportsScore();
getch();
return 0;
}