Answer to Question #324372 in C++ for Kassim

Question #324372

Qn.Implement a super class Person. Make two classes, Student and Instructor, that inherit from

Person. A person has a name and a year of birth. A student has a course and an instructor has a

salary. Write the class definitions, the constructors, and the functions for all classes. Supply a test

program that test these classes and member functions.


1
Expert's answer
2022-04-05T17:28:47-0400




#include<iostream>
#include <string>
using namespace std;




class Person{
private:
	string name;
	int yearBirth;
public:
	Person(){}


	Person(string name,int yearBirth){
		this->name=name;
		this->yearBirth=yearBirth;
	}


	void display(){
		cout<<"Name: "<<name<<"\n";
		cout<<"Year of birth: "<<yearBirth<<"\n";
	}


};


class Student:public Person{
private:
	string course;
public:
	Student(){}


	Student(string name,int yearBirth,string course):Person(name,yearBirth){
		this->course=course;
	}
	void display(){
		cout<<"Student: \n";
		Person::display();
		cout<<"Course: "<<course<<"\n";
	}


};




class Instructor:public Person{
private:
	double salary;
public:
	Instructor(){}


	Instructor(string name,int yearBirth,double salary):Person(name,yearBirth){
		this->salary=salary;
	}
	void display(){
		cout<<"Instructor: \n";
		Person::display();
		cout<<"Salary: "<<salary<<"\n";
	}
};


int main()
{
	
	Student s("Peter", 18,"C++");
	Instructor i("Mike", 18,1800);
	s.display();
	i.display();
	
	system("pause");
	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
APPROVED BY CLIENTS