Question: C++ Programming II Lab Lab Assignment 4 Overview: This assignment is for the students to practice using inheritance in C++. ThestudentsneedtocompletetheEmployee, Professor, Studentclassesasshownbelow. /** *
C++ Programming II Lab Lab Assignment 4
Overview:
This assignment is for the students to practice using inheritance in C++. ThestudentsneedtocompletetheEmployee, Professor, Studentclassesasshownbelow.
/** * Complete the Employee class, which is a derived class of the Person class */
class Employee { public: // [[ Constructor to initialize jobTitle ]]
void print_info() { cout << name << " works as a " << jobTitle << "." << endl; }
protected:
// [[ jobTitle ]]
};
/** * Complete the Professor class, which is a derived class of the Employee class */
class Professor { public: // [[ Constructor to initialize department and course ]]
void print_info() { cout << name << " is a " << jobTitle << " in the " << department << "
department, teaching " << course << "." << endl; }
private:
// [[ department ]]
// [[ course ]]
};
| /** * Complete the Student class, which is a derived class of the Person class */ class Student { public: // [[ Constructor to initialize major ]] void print_info() { cout << name << " is majoring in " << major << "." << endl; } private: // [[ major ]] }; |
Requirements:
1) Complete the Employee class, Professor class and Student class following the comments in the code.
2) Compile and run the program and check whether the result is correct.
C++ Source Code
#include
#include
using namespace std;
class Person {
public:
Person(string name, int age, string gender) {
this->name = name;
this->age = age;
this->gender = gender;
}
void print_info() {
cout << name << " is a " << age << " year old " << gender << "." << endl;
}
protected:
string name;
int age;
string gender;
};
/**
* Complete the Employee class, which is a derived class of the Person class
*/
class Employee {
public:
// [[ Constructor to initialize jobTitle ]]
void print_info() {
cout << name << " works as a " << jobTitle << "." << endl;
}
protected:
// [[ jobTitle ]]
};
/**
* Complete the Professor class, which is a derived class of the Employee class
*/
class Professor {
public:
// [[ Constructor to initialize department and course ]]
void print_info() {
cout << name << " is a " << jobTitle << " in the " << department << " department, teaching " << course << "." << endl;
}
private:
// [[ department ]]
// [[ course ]]
};
/**
* Complete the Student class, which is a derived class of the Person class
*/
class Student {
public:
// [[ Constructor to initialize major ]]
void print_info() {
cout << name << " is majoring in " << major << "." << endl;
}
private:
// [[ major ]]
};
int main() {
Person person("Susan", 25, "female");
Employee employee("Bob", 30, "male", "human resource manager");
Professor professor("Alice", 40, "female", "professor", "computer science", "programming languages");
Student student("Ronald", 20, "male", "computer science");
person.print_info();
employee.print_info();
professor.print_info();
student.print_info();
return 0;
}
Correct Output
Susan is a 25 year old female. Bob works as a human resource manager.
Alice is a professor in the computer science department, teaching programming languages.
Ronald is majoring in computer science.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
