Help with C++ assignment on inheritance? Inheritance Assignment Create a program
ID: 3695725 • Letter: H
Question
Help with C++ assignment on inheritance?
Inheritance Assignment Create a program that will prompt the user, through a menu, to enter data on various employees within an organization and display their pay. Use the information as specified below 1. Create a class according to the following specifications Class Name: emp EmpName pointer to a character EmpSSN - long integer Data Methods 1. A default constructor to initialize the data members 2. A copy constructor 2. A destructor 4. Accessor functions for both data members 5. A function named display() to display both data members on one line with no labels 2. Derive the following classes from the above Class Name: hourly_emp EmpRate - float, representing the hourly rate of pay EmpHours - an integer representing the number of hours worked Data Methods 1. A default constructor, a copy constructor, and a destructor 2. Accessor functions for the data members of this class 3. A function named display() to display the name, SSN, and the amount of pay (rate * hours) for an hourly employee Class Name: salaried emp Data Methods EmpSalary - float, representing the salary 1. A default constructor, a copy constructor, and a destructor 2. An accessor function for the data member of this class 3. A function named display() to display the name, SSN, and the amount of pay for a salaried employee After you have defined the above classes, write a main function (to include any necessary subfunctions required to create a structured, modularized program !!!) to test your classes. This function should 1. Display a menu to prompt the user to enter an integer value to identify the employee class 1 Salaried 2 = Hourly 3 = UnclassifiedExplanation / Answer
#include <iostream>
using namespace std;
class emp
{
char* EmpName;
long EmpSSN;
public:
emp(char name[20],long ssn)
{
EmpName=name;
EmpSSN=ssn;
}
~emp()
{
}
emp(emp E1)
{
EmpName=E1.EmpName;
EmpSSN=E1.EmpSSN;
}
char* getName()
{
return EmpName;
}
long getSSN()
{
return EmpSSN;
}
void display()
{
cout<<endl<<EmpName<<" "<<EmpSSN;
}
};
class hourly_emp : public emp
{
float EmpRate;
int EmpHours;
public:
hourly_emp(char name[20],long ssn,float rate, int hours):emp(name,ssn)
{
EmpRate=rate;
EmpHours=hours;
}
float getEmpRate()
{
return EmpRate;
}
int getEmpHours()
{
return EmpHours;
}
void display()
{
cout<<endl<<EmpName<<" "<<EmpSSN<<" "<<(EmpRate*EmpHours);
}
};
class salaried_emp : public emp
{
float EmpSalary;
public:
hourly_emp(char name[20],long ssn,float sal):emp(name,ssn)
{
EmpSalary=sal;
}
float getEmpSalary()
{
return EmpSalary;
}
void display()
{
cout<<endl<<EmpName<<" "<<EmpSSN<<" "<<EmpSalary;
}
};
int menu()
{
cout<<endl<<"1. Salaried Employee";
cout<<endl<<"2. Hourly Employee";
cout<<endl<<"3. Unclassified Employee";
cout<<endl<<"Enter your choice: ";
int c;
cin>>c;
return c;
}
int main()
{
emp *E;
hourly_emp *H;
salaried_emp *S;
int e=0;
int h=0;
int s=0;
int i=0;
char name[20];
long ssn;
float salary;
int hours;
float rate;
while(i<5)
{
int choice=menu();
switch(choice)
{
case 1: //salaried
cout<<endl<<"Enter Name: ";
cin>>name;
cout<<endl<<"Enter SSN: ";
cin>>ssn;
cout<<endl<<"Enter Salary: ";
cin>>salary;
S[s++]=new salaried_emp(name,ssn,salary);
break;
case 2: //Hourly
cout<<endl<<"Enter Name: ";
cin>>name;
cout<<endl<<"Enter SSN: ";
cin>>ssn;
cout<<endl<<"Enter rate: ";
cin>>rate;
cout<<endl<<"Enter hours: ";
cin>>hours;
H[h++]=new hourly_emp(name,ssn,rate,hours);
break;
case 3: //unclassified
cout<<endl<<"Enter Name: ";
cin>>name;
cout<<endl<<"Enter SSN: ";
cin>>ssn;
E[e++]=new emp(name,ssn);
break;
}
i++;
}
cout<<endlendl<<"unclassified employee information";
for(int j=0;j<e;j++)
{
E[j].display();
}
cout<<endl<<"Salaried employee information";
for(int j=0;j<s;j++)
{
S[j].display();
}
cout<<endl<<"Hourly employee information";
for(int j=0;j<h;j++)
{
H[j].display();
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.