Answer to Question #204654 in C++ for Ahmad

Question #204654

1) Define a class called student that has the following data members:

- int student number

- string student name

- double student average

The following member functions:

- Constructor that initialize the data members with default values.

- set and get functions for each data member

- Print function to print the values of data members.

Define a class called graduatestudent that inherits data members and functions

from the class student, and then declare the following data members :

- int level

- int year

Member functions:

- constructor

-set and get functions for each data member

- Print function.

Define a class called master that inherits data members and functions from

graduatestudent class, and then declare the following data member:

- int newid.

Member function:

- constructor

- set and get function for the data member

- Print function.

Write a driver program that:

- Declare object of type student with suitab le values then print it


1
Expert's answer
2021-06-08T23:48:43-0400
#include <iostream>


using namespace std;
class student{
    protected:
        int student_number;
        string student_name;
        double student_average;
    public:
        student(){
            student_number=0;
            student_name=" ";
            student_average=0.0;
        }
        void setStudentNumber(int no){
            student_number=no;
        }
        void setStudentName(string n){
            student_name=n;
        }
        void setStudentAverage(double a){
            student_average=a;
        }
        int getStudentNumber(){
            return student_number;
        }
        string getStudentName(){
            return student_name;
        }
        double getStudentAverage(){
            return student_average;
        }
        void print(){
            cout<<"\nStudent Number: "<<getStudentNumber()<<endl;
            cout<<"\nStudent Name: "<<getStudentName()<<endl;
            cout<<"\nStudent Average: "<<getStudentAverage()<<endl;
        }
};
class graduatestudent: public student{
    private:
        int level;
        int year;
    public:
        graduatestudent(){
            level=0;
            year=0;
        }
        void setLevel(int l){
            level=l;
        }
        void setYear(int y){
            year=y;
        }
        int getLevel(){
            return level;
        }
        int getYear(){
            return year;
        }
        void print2(){
            cout<<"\nLevel: "<<getLevel()<<endl;
            cout<<"\nYear: "<<getYear()<<endl;
        }
};


class master: public graduatestudent{
    private:
        int newid;
    public:
        master(){
            newid=0;
        }
        void setNewId(int id){
            newid=id;
        }
        int getNewId(){
            return newid;
        }
        void print3(){
            cout<<"\nNew ID: "<<newid<<endl;
        }
};


int main()
{
    student s;
    s.setStudentNumber(123);
    s.setStudentName("John");
    s.setStudentAverage(80.5);
    s.print();


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog