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

C++ (The Person, Student, Employee, Faculty, and Staff classes) Design a class n

ID: 3844211 • Letter: C

Question

C++

(The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two derived classes named Student and Employee. Make Faculty and Staff derived classes of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). An employee has an office, salary, and datehired. Define a class named MyDate that contains the fields year, month, and day. A faculty member has office hours and a rank. A staff member has a title. Define a constant virtual toString function in the Person class and override it in each class to display the class name and the person’s name.

Draw the UML diagram for the classes. Implement the classes. Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() functions.

Explanation / Answer

#include<iostream>

using namespace std;

class person {

   private: string name, address, phone, email;

    public: person(){}

    public:   
   person(string nme) {
name = nme;
}

   person(string n, string add, string ph, string em){          

       name = n;
       address = add;
       phone = ph;
       email = em;
   }

   public: string getName(){
                return name;
    }

   public: void setName(string nme){
       name = nme;
    }

    public: string getAddress(){
        return address;
    }

   public: void setAddress(string addr){
        address = addr;
    }

    public: string getPhone(){
        return phone;
    }

    public: void setPhone(string phne){
        phone = phne;
    }

   public: string getEmail(){
      return phone;
   }

    public: void setEmail(string eml){
        email = eml;
    }

    public: string toString(){
        return getName() + " " + name;
    }
};

class Student: public person {

protected: string status;

public: Student(string nme) : person(nme){}

public: Student(string nme, string stat) : person(nme){
status = stat;
}

public: string toString() {
return "Name: " + getName() + " Class: " + getName();
}
};

class Employee : public person {

protected: double salary;
protected: string office;
protected: string dateHired;

public: Employee(string name) : person(name){}

public: Employee(string name, double slary, string offce, string dteHired) : person(name){
  
salary = slary;
office = offce;
dateHired = dteHired;
}

public: double getSalary() {
return salary;
}

public: void setSalary(double slary) {
salary = slary;
}

public: string getOffice() {
return office;
}

public: void setOffice(string ofice) {
office = ofice;
}

public: string getDateHired() {
return dateHired;
}

public: void setDateHired(string dteHired) {
dateHired = dteHired;
}

public: string toString() {
return "Name: " + getName() + " Class: " + getName();
}
};

class Faculty : public Employee {

/*public: static String LECTURER = "Lecturer";
public: static String ASSISTANT_PROFESSOR = "Assistant Professor";
public: static String ASSOCIATE_PROFESSOR = "Associate Professor";
public static String PROFESSOR = "Professor";*/

protected: string officeHours;
protected: string rank;

//public: Faculty(string name) {
// this(name, "9-5PM", "Employee");
//}

public: Faculty(string name, string offceHours, string rnk) : Employee(name) {
  
officeHours = offceHours;
rank = rnk;
}

public: string getOfficeHours() {
return officeHours;
}

public: void setOfficeHours(string oficeHours) {
officeHours = oficeHours;
}

public: string getRank() {
return rank;
}

public: void setRank(string rnk) {
rank = rnk;
}

public: string toString() {
return "Name: " + getName() + " Class: " + getName();
}
};

class Staff :public Employee {

protected: string title;

public: Staff(string name) : Employee(name){
}

public: Staff(string name, string tle) : Employee(name){
  
title = tle;
}

public: string getTitle() {
return title;
}

public: void setTitle(string ttle) {
title = ttle;
}

public: string toString() {
return "Name: " + getName() + " Class: " + getName();
}
};


int main(){
  
       // Create a Person, Student, Employee, Faculty, and Staff objects
       person persn("John", "12 Bell street", "3473339999", "john12@aol.com");

       Student student("Mary", "100 Town Ave", "5149993333", "mary100@aol.com", "Sophomer");

       Employee employee("Mike", "34 West street", "6189999999","mike80@aol.com", 910, 60000);

       Faculty faculty("Sue", "28 Well street", "4133333333","sue28@aol.com", 101, 50000, "4pm to 6pm", "Professor");

       Staff staff("Tom", "90 Country road", "2030000000","tomcat@aol.com", 12, 65000, "Executive Assistant");

       // Invoke toString of Person, Student, Employee, Faculty and Staff
       cout<<person.toString();
       cout<<student.toString();
       cout<<employee.toString();
       cout<<faculty.toString();
       cout<<staff.toString();
}