In: Computer Science
Design and implement a C++ Application that:
Interactively input:
Menu with Option to:
Criteria:
Use this data for input:
MARKETING COMPANY REPORT PROGRAM
FIRST NAME LAST NAME ID HOURS WORKED Hourly Rate Total Pay
Brian Adams 612366 36
David Eisenhower 957654 38
Kathy Jones 123456 43
Janet Williams 245695 39
Steve Bradford 245690 39
Average Hours Worked: 39 Hrs/Week
Program Screen Shot:
Sample Output:
Program Code to Copy:
#include<iostream>
#include <vector>
#include<iomanip> // for cout formatting: decimal places,
width
using namespace std;
struct Employee{
string FirstName;
string LastName;
unsigned int Id;
int HoursWorked; // per week
double PayRate;
// function to display employee info.
void print(){
cout
<<setw(15)<<FirstName<<"\t"
<<setw(15)<<LastName<<"\t"
<<setw(15)<<Id<<"\t"
<<setw(15)<<HoursWorked<<"\t"
<<setw(15)<<setprecision(2)<<fixed<<PayRate<<"\t"
<<setw(15)<<setprecision(2)<<fixed<<HoursWorked*PayRate<<"\n";
}
};
// sort employees ascending by Id
void sortById(vector<Employee>&database){ // database
passed by reference
struct Employee temporary;
for(int i = 0;i<database.size(); ++i){
for(int j = i + 1; j < database.size(); ++j){
if(database[i].Id > database[j].Id){
temporary = database[i];
database[i] = database[j];
database[j] = temporary;
}
}
}
}
int main(){
struct Employee employee; // to hold info for an employee
vector<Employee>database; // to store all employees
int choice = 0;
unsigned int search_id;
bool found;
char more_input;
char more_menu;
cout<<"\nMARKETING COMPANY REPORT PROGRAM\n";
do{
cout<<"\nEnter First Name: ";
cin>>employee.FirstName;
cout<<"\nEnter Last Name: ";
cin>>employee.LastName;
cout<<"\nEnter ID: "; cin>>employee.Id;
cout<<"\nEnter Hours Worked: ";
cin>>employee.HoursWorked;
cout<<"\nEnter Pay Rate: ";
cin>>employee.PayRate;
database.push_back(employee); // store this employee
cout<<"Add More? (Y/N): ";
cin>>more_input;
}while(more_input=='Y' || more_input=='y');
do{
cout<<endl<<"Menu: \n";
cout<<"1 - Print out Employee Report"<<endl;
cout<<"2 - Search for an Employee"<<endl;
cout<<"3 - Display the Report, Sorted based on
ID"<<endl;
cout<<"4 - Calculate the Pay"<<endl;
cout<<"5 - Quit"<<endl;
cin>>choice;
switch(choice){
case 1:
cout
<<setw(15)<<"\nFIRST NAME\t"
<<setw(15)<<"LAST NAME\t"
<<setw(15)<<"ID\t"
<<setw(15)<<"HOURS WORKED\t"
<<setw(15)<<"HOURLY RATE\t"
<<setw(15)<<"TOTAL PAY\n";
for(Employee employee : database)
employee.print();
break;
case 2:
found = false;
cout<<"\nEnter employee id to search: ";
cin>>search_id;
for(Employee employee : database)
if(employee.Id == search_id){
employee.print(); // display this employ
found = true;
}
if (!found)
cout<<"Employee with id "<<search_id<<" is not
found";
break;
case 3:
sortById(database);
cout
<<setw(15)<<"\nFIRST NAME\t"
<<setw(15)<<"LAST NAME\t"
<<setw(15)<<"ID\t"
<<setw(15)<<"HOURS WORKED\t"
<<setw(15)<<"HOURLY RATE\t"
<<setw(15)<<"TOTAL PAY\n";
for(Employee employee : database)
employee.print();
break;
case 4:
found = false;
cout<<"\nEnter employee id to calculate pay: ";
cin>>search_id;
for(Employee employee : database)
if(employee.Id == search_id){
cout<<"\nThe pay is
"<<employee.HoursWorked*employee.PayRate<<endl; //total
pay
found = true;
}
if (!found)
cout<<"\nError calculating pay. Employee with id
"<<search_id<<" is not found\n";
break;
case 5:
cout<<"Good bye!";
exit(0);
break;
default: // do anything
break;
}
cout<<"\nGo back to main menu? (Y/N): ";
cin>>more_menu;
}while(more_menu=='Y'||more_menu=='y');
return 0;
}
------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,
IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~