StudyLover
  • Home
  • Study Zone
  • Profiles
  • Contact us
  • Sign in
StudyLover 16. 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.
Download
  1. C++ Programs list
15. Program to display names, roll numbers, and grades of 3 students who have appeared in an examination using a class. Create an array of class objects and read and display the contents of the array. : 17. Program to demonstrate inheritance and polymorphism using virtual functions.
C++ Programs list

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.

  1. #include <iostream.h>

  2. #include<conio.h>

  3. class Student {

  4. public:

  5.     int rollNo;

  6.  

  7.     void getRollNo() {

  8.                 cout << "Enter roll number: ";

  9.                 cin >> rollNo;

  10.     }

  11.  

  12.     void displayRollNo() {

  13.                 cout << "Roll Number: " << rollNo << endl;

  14.     }

  15. };

  16.  

  17. class Test : public Student {

  18. public:

  19.     int marks[5];

  20.  

  21.     void getMarks() {

  22.                 cout << "Enter marks in 5 subjects: ";

  23.                 for (int i = 0; i < 5; i++) {

  24.                     cin >> marks[i];

  25.                 }

  26.     }

  27.  

  28.     void displayMarks() {

  29.                 cout << "Marks in 5 subjects: ";

  30.                 int total_marks=0;

  31.                 for (int i = 0; i < 5; i++) {

  32.                     cout << marks[i] << " ";

  33.                     total_marks=total_marks+marks[i];

  34.                 }

  35.                 cout <<"\nTotal Marks: "<<total_marks<< endl;

  36.     }

  37. };

  38.  

  39. class Sports : public Test {

  40. public:

  41.     int sportsScore;

  42.  

  43.     void getSportsScore() {

  44.         cout << "Enter sports score: ";

  45.         cin >> sportsScore;

  46.     }

  47.  

  48.     void displaySportsScore() {

  49.         cout << "Sports Score: " << sportsScore << endl;

  50.     }

  51. };

  52.  

  53. int main() {

  54.     Sports student;

  55.  

  56.     student.getRollNo();

  57.     student.getMarks();

  58.     student.getSportsScore();

  59.  

  60.     student.displayRollNo();

  61.     student.displayMarks();

  62.     student.displaySportsScore();

  63.     getch();

  64.     return 0;

  65. }

15. Program to display names, roll numbers, and grades of 3 students who have appeared in an examination using a class. Create an array of class objects and read and display the contents of the array. 17. Program to demonstrate inheritance and polymorphism using virtual functions.
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website