You will be writing a program using cstrings and an array of
You will be writing a program using cstrings and an array of objects. The behavior of the program will be menu based with options to add a new employee to an array of employees, print one employee record, and print employee paychecks.
START FROM HERE:
Employee Structure
The employee structure definition will include the following member variables:
a character array for the first name
a character array for the last name
an integer for the employee\'s id
an integer for the number of hours
a float for the employee\'s payrate
Functions
Employee addEmployee() - This function will instantiate a temporary employee object, prompt the user for first name, last name, id, hours, and payrate, inputting each value to the corresponding member variable, and returns the temporary object
void printEmployee(Employee) - This function will print the member variables of the passed Employee object
void printEmployeePaychecks(Employee[], int) - This function will accept and array of employee objects and an integer for the amount of entered employees within the array. This function will traverse the array and print each object\'s first and last initial of it\'s name, the id, and the caclulation of hours * payrate (displayed in monetary format)
Menu Options
This will call the function addEmployee. Assign the returned value to your employee object array at index \'count\' and update count.
If no employee has been entered, disallow this feature and alert to the user that he/she must add at least one employee. Otherwise, prompt the user for an index and print the employee. (ex. if the user enters 1, then print the first employee which will be in the array at subscript 0 index-1)
If no employee has been entered, disallow this feature and alert to the user that he/she must add at least one employee. Otherwise, print each employee\'s paycheck
OUTPUT should look like this:
Solution
Code to Copy:
// Employeearrayofobjects.cpp : Defines the entry point for the console application.
//
#include \"stdafx.h\"
#include<iostream>
#include<cstring>
#include<cstringt.h>
using namespace std;
#define MAX 64
#define SIZE 20
//Structure Definition Employee
struct Employee {
char firstname[100];
char lastname[100];
int empID;
int numberOfhours;
float payrate;
};
//Employee Function Prototypes
void displayMenu();
Employee addEmployee();
void printEmployee(Employee);
void printEmployeePaychecks(Employee);
int main() {
Employee emps[SIZE];
// Declare an array of Employee objects
int count = 0, choice, index,ID;
do {
displayMenu();
cin >> choice;
while (count == 0 && choice != 1)
{
cout << \"Must enter an employee! please enter valid choice:\" << endl;
cin >> choice;
}
switch (choice) {
case 1:
emps[count]= addEmployee();
count++;
break;
case 2:
cout << \"Enter employee index #:\";
cin >> index;
printEmployee(emps[index]);
break;
case 3:
cout << \"Enter employee index #:\";
cin >> index;
printEmployeePaychecks(emps[index]);
break;
case 0: break;
default:
cout << \"Invalid Option\ \";
}
} while (choice != 0);
system(\"pause\");
return(0);
}
//Employee Function Definitions
void displayMenu()
{
cout << \"\ ---------------------------- \ \"
<< \"| Employee Control Center |\ \"
<< \"|----------------------------|\ \"
<< \"| 1.Add New Employee |\ \"
<< \"| 2.Print Employee |\ \"
<< \"| 3.Print Employee Paychecks |\ \"
<< \"| 0.Exit |\ \"
<< \" ---------------------------- \ \"
<< \" Enter Choice: \";
}
Employee addEmployee()
{
Employee temp;
cout << \"Enter the first name of employee:\";
cin >> temp.firstname;
cout << \"Enter the last name of employee:\";
cin >> temp.lastname;
cout << \"Enter the employee ID:\";
cin >> temp.empID;
cout << \"Enter number of hours:\";
cin >> temp.numberOfhours;
cout << \"Enter the employee payrate:\";
cin >> temp.payrate;
return temp;
}
void printEmployee(Employee obj)
{
cout << \"First\" << \"\\t\" << \"Last\" << \"\\t\" << \"ID#\" << \"\\t\" << \"Hours\" << \"\\t\" << \"$payrate\ \";
cout << obj.firstname <<\"\\t\" << obj.lastname << \"\\t\" << obj.empID << \"\\t\" << obj.numberOfhours << \"\\t\" << obj.payrate;
}
void printEmployeePaychecks(Employee obj)
{
double weekly_pay = obj.payrate * obj.numberOfhours;
cout << \"The weekly pay of the Employee: \ \";
cout<<obj.firstname << obj.lastname;
cout << \"\\t\" << \"Hours: \" << obj.numberOfhours << \"\\t\" << \"Weekly Pay: \";
cout << weekly_pay << endl;
}


