Design the following classes in C++ . Person class is the base class for other c
ID: 665431 • Letter: D
Question
Design the following classes in C++. Person class is the base class for other classes.
Person – A Person contains a first name, last name, street address, zip code, and phone number. The class also includes a method that sets each data field, using a series of output/input commands and a display method that displays all of a Person’s information on a multiple lines at the command line on the screen.
CollegeEmployee – A CollegeEmployee descends from Person. A CollegeEmployee also includes a Social Security number, an annual salary, and a department name, as well as methods that override the Person methods to accept and display all CollegeEmployee data.
Faculty – Faculty descends from CollegeEmployee. This class also includes a Boolean field that indicates whether the Faculty member is tenured, as well as methods that override the CollegeEmployee methods to accept and display this additional piece of information.
Student – Student descends from Person. In addition to the fields available in Person, a Student contains a major field of study and a grade point average, as well as methods that override the Person methods to accept and display these additional facts.
Write an application named CollegeList that declares an array of four “regular” CollegeEmployees, three Faculty, and seven Students. Prompt the user – using a menu to specify which type of person’s data will be entered (‘C’, ‘F’, or ‘S’), or allow the user to quit (‘Q’). While the user chooses to continue (that is, does not quit), accept data entry for the appropriate type of Person. If the user attempts to enter data for more than four CollegeEmployees, three Faculty, or seven Students, display an error message. When the user quits, display a report on the screen listing each group of Persons under the appropriate heading “College Employees,” “Faculty,” or “Students.” If the user has not entered data for one or more types of Persons during a session, display an appropriate message under the appropriate heading.
Explanation / Answer
Comments added
-----------------------------------------------------------------------------------------------------------------------
class Person //person class
{
protected:
string first_name, last_name, address, zip, phone; //variables declared
public:
void set_data (string first, string last, string address, string zip, string phone ) //constructor
{
first_name = a;
last_name = b;
address = address;
zip = zip;
phone = phone;
}
};
class CollegeEmployee : public Person
{
public:
string security, departmentName;
float salry;
public:
void setCollegeEmployeeData( string security, string deptname, float salary) //setting variables employee
{
security = security;
departmentName=deptname;
salary = salary;
}
};
class Faculty: public Person //Faculty class
{
public:
boolean tentured;
public:
void setTentured (bool val) //setting varoabels to Faculty
{
tentured = val;
}
};
class Student: public Person //student calss
{
public:
string field;
float average;
public:
void setStudent (string field, float average) //setting variables to student
{
field = field;
average = average;
}
};
int main () //main method starts
{
//local variables declared to read input
int college=0,faulty=0,student=0;
string first_name, last_name, address, zip, phone;
string security, departmentName;
string field;
float average;
float salary;
boolean tentured;
while(true){ //creating objects
cout<<"Enter C : college F: Faculty S : Student";
string choice;
cin>>choice;
if(choice == "C" && college<4){//as per choice creating college
cout<<"Enter first name";
cin>>first_name;
cout<<"Enter last_name";
cin>>last_name;
cout<<"address";
cin>>address;
cout<<"Zip: ";
cin>>zip;
cout<<"Phone";
cin>>phone;
CollegeEmployee college;
college.set_data(first_name, last_name, address, zip, phone);
cout<<"Enter security number";
cin>>security;
cout<<"Enter departmentName";
cin>>departmentName;
cout<<"Enter salary";
cin>>salary;
college.setCollegeEmployeeData(security,departmentName,salary);
college++;
}
else if(choice == "C" && college>4){
cout<<"sorry you are not allowed to create new Employee";
}
if(choice == "S" && student<7){//as per choice creating student
cout<<"Enter first name";
cin>>first_name;
cout<<"Enter last_name";
cin>>last_name;
cout<<"address";
cin>>address;
cout<<"Zip: ";
cin>>zip;
cout<<"Phone";
cin>>phone;
Student student;
student.set_data(first_name, last_name, address, zip, phone);
cout<<"Enter area of field";
cin>>field;
cout<<"Enter average";
cin>>average;
student.setStudent(field,average);
student++;
}
else if(choice == "S" && student>7){
cout<<"sorry you are not allowed to create new student";
}
if(choice == "F" && faculty<3){//as per choice creating faculty
cout<<"Enter first name";
cin>>first_name;
cout<<"Enter last_name";
cin>>last_name;
cout<<"address";
cin>>address;
cout<<"Zip: ";
cin>>zip;
cout<<"Phone";
cin>>phone;
Faculty faculty;
faculty.set_data(first_name, last_name, address, zip, phone);
cout<<"Enter area of field";
cin>>field;
cout<<"Enter average";
cin>>average;
faculty.setTentured(tentured);
faculty++;
}
else if(choice == "F" && faculty>3){
cout<<"sorry you are not allowed to create new faculty";
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.