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

Create a class student contains roll number, name and course as data member and

ID: 3694023 • Letter: C

Question

Create a class student contains roll number, name and course as data member and Input_student and display_student as member function. A derived class exam is created from the class student with publicly inherited. The derived class contains mark1, mark2, mark3 as marks of three subjects and input_marks and display_result as member function.

Each one of these classes should contain 2 constructors (default and argument constructors).

implement all the methods in implementations files

create a a cpp file with a main function to create 2 exam objects one using a default constructor and the other one using the argument constructor.

Test all of the methods.

Explanation / Answer

#include <iostream>

using namespace std;

class Student{

public:
    int roll_no;
    string name;
    string course;
    void Input_student(){
        cout<<"enter data of student"<<endl;
        cin>>roll_no;
        cin>>name;
        cin>>course;
    }
    void display_student(){
      cout<<"roll number of student is"<<" " <<roll_no<<endl;
      cout<<"name of student is"<<" " <<name<<endl;
      cout<<"course of student id "<<" " << course<<endl;
      }

};

class Exam : public Student{
int marks1;
int marks2;
int marks3;

public:
    void Input_result(){
    cout<<"enter marks in three subject"<<endl;
    cin>>marks1>>marks2>>marks3;
    }
    void Output_result(){
    cout<<"Name of student is "<<" "<<name<<endl;
    cout<<"roll number of student"<<" "<<roll_no<<endl;
    cout<<"course of student"<<" "<<course<<endl;
    cout<<"subject1"<<" "<<marks1<<endl;
    cout<<"subject2"<<" "<<marks2<<endl;
    cout<<"subject3"<<" "<<marks3<<endl;
    }
    };


int main()
{

    Exam ex[2];
    int i;
     for(i=0;i<2;i++){
        ex[i].Input_student();
        ex[i].Input_result();
     }
for(i=0;i<2;i++){
        ex[i].Output_result();

     }
     return 0;
}


sample output

enter data of student                                                                                                                                       
123                                                                                                                                                         
ram                                                                                                                                                         
java                                                                                                                                                        
enter marks in three subject                                                                                                                                
45                                                                                                                                                          
67                                                                                                                                                          
88                                                                                                                                                          
enter data of student                                                                                                                                       
234                                                                                                                                                         
shiva                                                                                                                                                       
data structure                                                                                                                                              
enter marks in three subject                                                                                                                                
Name of student is ram                                                                                                                                     
roll number of student 123                                                                                                                                  
course of student java                                                                                                                                      
shiva                                                                                                                                                       
data structure                                                                                                                                              
enter marks in three subject                                                                                                                                
Name of student is ram                                                                                                                                     
roll number of student 123                                                                                                                                  
course of student java                                                                                                                                      
subject1 45                                                                                                                                                 
subject2 67                                                                                                                                                 
subject3 88                                                                                                                                                 
Name of student is shiva                                                                                                                                   
roll number of student 234                                                                                                                                  
course of student data                                                                                                                                      
subject1 0                                                                                                                                                  
subject2 0                                                                                                                                                  
subject3 0                                                                                                                                                  

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