For the program listed below, modify it to include a “menu” that offers the user
ID: 3638019 • Letter: F
Question
For the program listed below, modify it to include a “menu” that offers the user the following examples:1. add an employee
2. modify employee data
3. delete an employee
4. exit this menu
#include <iostream>
using namespace std;
class employee
{
private:
int id, maxHours;
float payRate;
public:
void setInfo (int pin, float pay, int hours)
{
id = pin;
payRate = pay;
maxHours = hours;
}
void viewInfo () // No parameters req.
{
cout << id;
cout << endl << payRate;
cout << endl << maxHours;
}
};
int main ( )
{
int pin, hours, record;
float pay;
employee empInfo[1000];
cout << "Enter employee 3 digit ID: ";
cin >> pin;
cout << "Enter employee pay rate: ";
cin >> pay;
cout << "Enter employee max hours: ";
cin >> hours;
empInfo[pin].setInfo(pin, pay, hours);
cout << "Enter the employee ID# of the record you wish to view: ";
cin >> record;
empInfo[record].viewInfo();
return 0;
}
Explanation / Answer
#include <iostream>using namespace std;
class employee
{
private:
int id, maxHours;
float payRate;
public:
void setInfo (int pin, float pay, int hours)
{
id = pin;
payRate = pay;
maxHours = hours;
}
void viewInfo () // No parameters req.
{
cout << id;
cout << endl << payRate;
cout << endl << maxHours;
cout<<"enter the new valuse for the id:"<<id cout << "Enter employee 3 digit ID: ";
cin >> pin;
cout << "Enter employee pay rate: ";
cin >> pay;
cout << "Enter employee max hours: ";
cin >> hours;
empInfo[pin].setInfo(pin, pay, hours);
}
};
int main ( )
{
int pin, hours, record;
float pay;
int ch; char ans;
employee empInfo[1000];
cout<<"1.ADD EMP 2.MODIFY EMP 3.DELETE EMP 4.EXIT"; cout<<"enter the choice"; cin>>ch; switch(ch) { case 1:
{
cout << "Enter employee 3 digit ID: ";
cin >> pin;
cout << "Enter employee pay rate: ";
cin >> pay;
cout << "Enter employee max hours: ";
cin >> hours;
empInfo[pin].setInfo(pin, pay, hours);
} case 2: {
cout << "Enter the employee ID# of the record you wish to modify ";
cin >> record;
empInfo[record].viewInfo();
} case 3: { cout << "Enter the employee ID# of the record you wish to modify ";
cin >> record;
empInfo[pin].setInfo("","","");
} case 4: {
return 0;
}
}