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

In C++ Develop a set of classes representing various people at a university or c

ID: 3602591 • Letter: I

Question

In C++

Develop a set of classes representing various people at a university or college. You may model this after your own institution, and you must include at least four classes. Create a base class that describes the characteristics and functions of people in general. Then, create at least three classes that are derived from the base class, representing students, staff, and faculty.

Develop a small program that instantiates objects of all three derived classes so that your project will compile and link.

Explanation / Answer

#include<iostream>
#include<string>

using namespace std;

class Person{
   private:
     string name;
   public:
      Person(string nm){
         name = nm;
      }
      string getName(){
           return name;
      }
};

class Student : public Person {
    private:
       string course;
    public:
        Student(string nm, string cr) : Person(nm){
           course = cr;
        }
        string getCourse(){
            return course;
        }
};

class Staff : public Person {
    private:
       string dept;
       string empid;
    public:
        Staff(string nm, string dp, string id) : Person(nm){
           dept = dp;
           empid = id;
        }
        string getId(){
            return empid;
        }
        string getDept(){
            return dept;
        }
};

class Professor : public Person {
    private:
       string subject;
       string empid;
    public:
        Professor(string nm, string sub, string id) : Person(nm){
           subject = sub;
           empid = id;
        }
        string getId(){
            return empid;
        }
        string getSubject(){
            return subject;
        }
};

int main(){

   Person p("John");
   Student s("Mike", "CS110");
   Staff st("Mary","Finance","1234");
   Professor p1("Michael","Computers","2345");

   cout << p.getName() << endl;
   cout << s.getCourse() << endl;
    cout << st.getDept() << endl;
    cout << p1.getSubject() << endl;
   return 0;
}