Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a base class called Student with the foll. 2 fields:- (i) Name (ii) Id. D

ID: 3842578 • Letter: D

Question

Design a base class called Student with the foll. 2 fields:- (i) Name (ii) Id. Derive 2 classes called Sports and Exem from the Student base class. Class Sports has a field called s_grade and class Exem has a field called e_grade which are integer fields. Derive a class called Results which inherit from Sports and Exem. This class has a character array or string field to represent the final result. Also it has a member function called display which can be used to display the final result. Illustrate the usage of these classes in main.

how to slove this problems in C++?

Explanation / Answer

#include <iostream>

using namespace std;

class Student{
  
protected:
       char *name;
       int id;

public:
      void setName(char* n) {
         name = n;
      }
      
      void setId(int i) {
         id = i;
      }
};

class Sports : public Student{
  
    protected:
       int s_grade; // sports grade
     
    public:
      void sets_grade(int sg) {
         s_grade = sg;
      }
};

class Exem : public Student{
  
    protected:
      int e_grade; // exem grade
    
    public:
      void sete_grade(int eg) {
         e_grade = eg;
      }
};

class Results : public Sports, public Exem{
  
    protected:
      float f_result; // final result
      //consider final result as average of
      //sports grade and exem grade
  
    public:
        void setf_result() {
            f_result = (s_grade+e_grade) / 2.0;
        }
      
        void display(){
          
            cout<<"Final Result is : "<<f_result;
        }
  
};


int main()
{
   Results r;
   r.sets_grade(75);
   r.sete_grade(85);
   r.setf_result();
   r.display();

   return 0;
}

/*

output :-

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote