Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab Exercise -- C++ Structures Objective: The purpose of the program is to: 1. Write functions to read in and print an Employee struct
Lab Exercise -- C++ Structures Objective: The purpose of the program is to: 1. Write functions to read in and print an Employee struct 2. Write an additional function that passes in an array of Employees and returns the index to a found id. Step 1: Copy three files into your directory by entering the following command: cp /net/data/ftp/pub/class/115/04-structure-083/Exercise/*.* Create an Employee.cpp file to go with the existing Employee.h. This involves defining the two functions: o void printEmployee(const Employee& c) -print the values of the Employee structure (each record on one line) o Employee readEmployee() --ask the user for input and return the Employee structure Remember, you can compile and link the three files with the following commands: o g++ -c main.cpp o g++ -c Employee.cpp o g++ main.o Employee.o -o output At this point, your run should look like the following: Employee Name?: Mary Contrary Employee Id?: 1222222 Employee Yearly Salary?: 32003.33 Employee Name?: Sue Morgan Employee Id?: 2444444 Employee Yearly Salary?: 78087.88 Employee Name?: Tom Hinks Employee Id?: 6777777 Employee Yearly Salary?: 89018.38 Employee Name?: Jack Sprat Employee Id?: 8999999 Employee Yearly Salary?: 42018.09 Employee Name?: Scott Burns Employee Id?: 3444444 Employee Yearly Salary?: 22002.89 The Employee info is: Mary Contrary, 1222222, $32003.33 The Employee info is: Sue Morgan, 2444444, $78087.88 The Employee info is: Tom Hinks, 6777777, $89018.38 The Employee info is: Jack Sprat, 8999999, $42018.09 The Employee info is: Scott Burns, 3444444, $22002.89 Step 2: Add this new function prototype to Employee.h: int findEmployee(const Employee array[], int tId, int num); Define the findEmployee function in Employee.cpp the following are the specifications: Arguments: o array: array of Employee(s) o tId: the id you are searching for o num: the size of the array Returns: o -1 if the id is not found o an index to the array of Employees where the id was found Add code in main to call the findEmployee function and print out the corresponding name to go with the id. Sample output is: Employee Name? : Mary Contrary Employee Id?: 1222222 Employee Yearly Salary?: 32003.33 Employee Name?: Sue Morgan Employee Id?: 2444444 Employee Yearly Salary?: 78087.88 Employee Name?: Tom Hinks Employee Id?: 6777777 Employee Yearly Salary?: 89018.38 Employee Name?: Jack Sprat Employee Id?: 8999999 Employee Yearly Salary?: 42018.09 Employee Name?: Scott Burns Employee Id?: 3444444 Employee Yearly Salary?: 22002.89 The Employee info is: Mary Contrary, 1222222, $32003.33 The Employee info is: Sue Morgan, 2444444, $78087.88 The Employee info is: Tom Hinks, 6777777, $89018.38 The Employee info is: Jack Sprat, 8999999, $42018.09 The Employee info is: Scott Burns, 3444444, $22002.89 Enter an id to look for: 8999999 Found Employee: Jack Sprat By contrast, if the employee id was not found, you should display a message of: Did not find an Employee with that Id! Files main.cpp 1 #include O main.cpp #include D Employee.h using namespace std; #include "Employee.h" 4 5 O text.txt int main() { // declare array of Employees Employee employeeArray[NUM_EMPL]; // declare variable for the Employee id to search for in array 10 int employeeId; // declare variable for index of Employees array where the id was found 11 12 13 int index; 14 15 cout Files Employee.h 1 Finclude main.cpp 2 using namespace std; Employee.h const unsigned int NUM_EMPL = 5; 4 5 O text.txt struct Employee { string name; int id; double salary; 6. 8. 10 11 }; 12 void printEmployee(const Employee& c); Employee readEmployee(); //----Add findEmployee prototype for Step 2---- 13 14 15 16 ... Files text.txt hary Contrary 1. main.cpp 1222222 3. 32003.33 Employee.h Sue Morgan 4 2444444 text.bxt 6. 78087.88 7 Tom Hinks 8. 6777777 6. 89018.38 10 Jack Sprat 11 8999999 12 42018.09 13 Scott Burns 14 3444444 15 22002.89 16 1222222 17 18 ... Lab Exercise -- C++ Structures Objective: The purpose of the program is to: 1. Write functions to read in and print an Employee struct 2. Write an additional function that passes in an array of Employees and returns the index to a found id. Step 1: Copy three files into your directory by entering the following command: cp /net/data/ftp/pub/class/115/04-structure-083/Exercise/*.* Create an Employee.cpp file to go with the existing Employee.h. This involves defining the two functions: o void printEmployee(const Employee& c) -print the values of the Employee structure (each record on one line) o Employee readEmployee() --ask the user for input and return the Employee structure Remember, you can compile and link the three files with the following commands: o g++ -c main.cpp o g++ -c Employee.cpp o g++ main.o Employee.o -o output At this point, your run should look like the following: Employee Name?: Mary Contrary Employee Id?: 1222222 Employee Yearly Salary?: 32003.33 Employee Name?: Sue Morgan Employee Id?: 2444444 Employee Yearly Salary?: 78087.88 Employee Name?: Tom Hinks Employee Id?: 6777777 Employee Yearly Salary?: 89018.38 Employee Name?: Jack Sprat Employee Id?: 8999999 Employee Yearly Salary?: 42018.09 Employee Name?: Scott Burns Employee Id?: 3444444 Employee Yearly Salary?: 22002.89 The Employee info is: Mary Contrary, 1222222, $32003.33 The Employee info is: Sue Morgan, 2444444, $78087.88 The Employee info is: Tom Hinks, 6777777, $89018.38 The Employee info is: Jack Sprat, 8999999, $42018.09 The Employee info is: Scott Burns, 3444444, $22002.89 Step 2: Add this new function prototype to Employee.h: int findEmployee(const Employee array[], int tId, int num); Define the findEmployee function in Employee.cpp the following are the specifications: Arguments: o array: array of Employee(s) o tId: the id you are searching for o num: the size of the array Returns: o -1 if the id is not found o an index to the array of Employees where the id was found Add code in main to call the findEmployee function and print out the corresponding name to go with the id. Sample output is: Employee Name? : Mary Contrary Employee Id?: 1222222 Employee Yearly Salary?: 32003.33 Employee Name?: Sue Morgan Employee Id?: 2444444 Employee Yearly Salary?: 78087.88 Employee Name?: Tom Hinks Employee Id?: 6777777 Employee Yearly Salary?: 89018.38 Employee Name?: Jack Sprat Employee Id?: 8999999 Employee Yearly Salary?: 42018.09 Employee Name?: Scott Burns Employee Id?: 3444444 Employee Yearly Salary?: 22002.89 The Employee info is: Mary Contrary, 1222222, $32003.33 The Employee info is: Sue Morgan, 2444444, $78087.88 The Employee info is: Tom Hinks, 6777777, $89018.38 The Employee info is: Jack Sprat, 8999999, $42018.09 The Employee info is: Scott Burns, 3444444, $22002.89 Enter an id to look for: 8999999 Found Employee: Jack Sprat By contrast, if the employee id was not found, you should display a message of: Did not find an Employee with that Id! Files main.cpp 1 #include O main.cpp #include D Employee.h using namespace std; #include "Employee.h" 4 5 O text.txt int main() { // declare array of Employees Employee employeeArray[NUM_EMPL]; // declare variable for the Employee id to search for in array 10 int employeeId; // declare variable for index of Employees array where the id was found 11 12 13 int index; 14 15 cout Files Employee.h 1 Finclude main.cpp 2 using namespace std; Employee.h const unsigned int NUM_EMPL = 5; 4 5 O text.txt struct Employee { string name; int id; double salary; 6. 8. 10 11 }; 12 void printEmployee(const Employee& c); Employee readEmployee(); //----Add findEmployee prototype for Step 2---- 13 14 15 16 ... Files text.txt hary Contrary 1. main.cpp 1222222 3. 32003.33 Employee.h Sue Morgan 4 2444444 text.bxt 6. 78087.88 7 Tom Hinks 8. 6777777 6. 89018.38 10 Jack Sprat 11 8999999 12 42018.09 13 Scott Burns 14 3444444 15 22002.89 16 1222222 17 18 ...
Step by Step Solution
★★★★★
3.55 Rating (148 Votes )
There are 3 Steps involved in it
Step: 1
Code Employeeh include using namespace std const unsigned int NUMEMPL5 struct Emplo...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started