Lab Exercise -- C++ Structures Objective: The purpose of the program is to: 1. Write functions...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 <iostream> O main.cpp #include <iomanip> 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 <« fixed « showpoint <« setprecision(2); 16 for (int i = 0; i < NUM_EMPL; i++) { employeeArray[i] = readEmployee(); cin.ignore(256, '\n'); } 17 18 19 20 21 22 cout <« endl; 23 for (int i - e; i < NUM_EMPL; i++) { printEmployee(employeeArray[i]); 24 25 26 27 28 //----Add code below for Step2---- 29 //prompt the user for an id 30 31 // call the findEmployee function 32 33 //if found, display the name of the employee that goes with the id 34 35 Files Employee.h 1 Finclude <string> 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 <iostream> O main.cpp #include <iomanip> 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 <« fixed « showpoint <« setprecision(2); 16 for (int i = 0; i < NUM_EMPL; i++) { employeeArray[i] = readEmployee(); cin.ignore(256, '\n'); } 17 18 19 20 21 22 cout <« endl; 23 for (int i - e; i < NUM_EMPL; i++) { printEmployee(employeeArray[i]); 24 25 26 27 28 //----Add code below for Step2---- 29 //prompt the user for an id 30 31 // call the findEmployee function 32 33 //if found, display the name of the employee that goes with the id 34 35 Files Employee.h 1 Finclude <string> 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 <iostream> O main.cpp #include <iomanip> 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 <« fixed « showpoint <« setprecision(2); 16 for (int i = 0; i < NUM_EMPL; i++) { employeeArray[i] = readEmployee(); cin.ignore(256, '\n'); } 17 18 19 20 21 22 cout <« endl; 23 for (int i - e; i < NUM_EMPL; i++) { printEmployee(employeeArray[i]); 24 25 26 27 28 //----Add code below for Step2---- 29 //prompt the user for an id 30 31 // call the findEmployee function 32 33 //if found, display the name of the employee that goes with the id 34 35 Files Employee.h 1 Finclude <string> 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 <iostream> O main.cpp #include <iomanip> 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 <« fixed « showpoint <« setprecision(2); 16 for (int i = 0; i < NUM_EMPL; i++) { employeeArray[i] = readEmployee(); cin.ignore(256, '\n'); } 17 18 19 20 21 22 cout <« endl; 23 for (int i - e; i < NUM_EMPL; i++) { printEmployee(employeeArray[i]); 24 25 26 27 28 //----Add code below for Step2---- 29 //prompt the user for an id 30 31 // call the findEmployee function 32 33 //if found, display the name of the employee that goes with the id 34 35 Files Employee.h 1 Finclude <string> 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 ...
Expert Answer:
Answer rating: 100% (QA)
Code Employeeh include using namespace std const unsigned int NUMEMPL5 struct Emplo... View the full answer
Related Book For
Vector Mechanics for Engineers Statics and Dynamics
ISBN: 978-0073212227
8th Edition
Authors: Ferdinand Beer, E. Russell Johnston, Jr., Elliot Eisenberg, William Clausen, David Mazurek, Phillip Cornwell
Posted Date:
Students also viewed these economics questions
-
What happens when out-of-bound access occur? For example; Int scores[3] ={4,5,6} Cout < < scores[5]; a. Additional array elements are added so array element 5 is in the memory b. The compiler...
-
Consider the following function main: Int main() { int inStock[10][4]; int alpha [20]; int beta[20]; int gamma[4]= {11,13,15,17}; int delta [10] = {3,5,2,6,10,9,7,11,1,8}; } a) Write the definition...
-
Asset A and B are operated by us. Asset C is operated by another company. The following costs occur: Our Gross Costs Asset A 1,250,000 3,300,000 Asset B What are the NET costs of all 3 assets? 55%...
-
The CFO of the Jordan Microscope Corporation intentionally misclassified a downstream transportation expense in the amount of $575,000 as a product cost in an accounting period when the company made...
-
In May 2011, M1 was $537 billion; M2 was $1,034 billion; personal chequable deposits were $206 billion; non-personal chequable deposits were $273 billion; personal non-chequable deposits were $162...
-
1. What are the main arguments that Jerry and Sharon will need to counter? That is, what are the reasons and rationalizations they will need to address? 2. What is at stake should they not convince...
-
You receive a tip on the company's hot line that there has been some fraud in the collections area. What five audit steps would you suggest using in order to find the fraud?
-
The bookkeeper for Lowells Country Music Bar left this incomplete balance sheet. Lowells working capital is $90,000 and its debt to assets ratio is 40 percent. Required Complete the balance sheet by...
-
??????? Determine the amount of taxable dividend, nontaxable distribution, and capital gain for the distributions made in each of the following cases: Required: a. Corporate E\&P of \( \$ 10,600 \),...
-
Centrum Manufacturing makes a single product with the following attributes: Product per Unit Price $130.00 Variable costs per unit: Direct materials $30.00 Direct labor $40.00 Total VC $70.00...
-
A 17 - ft ladder is leaning against a house, as shown in the diagram. Find the slope of the ladder. Express numbers as integers or simplified fractions. 0 answers
-
Should Gillham try to improve pay levels? Why or why not and in what ways (e.g., indirect/non-financial components)
-
You bought a car. You paid $20,000 as an initial payment. At the end of the third year, you paid another payment of $2,000. The remaining amount of car's price is to be paid at the end of 10 year....
-
10. Horace uses the cash basis to account for revenue and expenses in his business. He has the following business revenue and expenses during the year: Gross receipts Business expenses Customer...
-
Compile a list of international HR mistakes has made so far. How would you have gone about hiring a European sales manager? Why?
-
During the current fiscal year, Jeremiah Corp. signed a long-term non-cancellable purchase commitment with its primary supplier. Jeremiah agreed to purchase $2,580,000 of raw materials during the...
-
Question: 2 Record Adjusting Journal Entries (5-marks) a) On January 3, 2015, $6,500 of supplies were purchased and recorded as an asset. A count revealed $500 still on hand at December 31, 2015. b)...
-
Find the radius of convergence in two ways: (a) Directly by the CauchyHadamard formula in Sec. 15.2. (b) From a series of simpler terms by using Theorem 3 or Theorem 4.
-
Solve Prob. 7.78 assuming that the 2-kip force applied at E is directed upward. Problem 7.78: For beam AB, (a) Draw the shear and bending-moment diagrams, (b) Determine the location and magnitude of...
-
The uniform thin 5-lb disk spins at a constant rate w2 = 6 rad/s about an axis held by a housing attached to a horizontal rod that rotates at the constant rate w1 = 3 rad/s. Determine the couple...
-
Knowing that at the instant shown the velocity of collar D is 1.6 m/s upward, determine (a) The angular velocity of rod AD, (b) The velocity of point B, (c) The velocity of point A. 240 me mm E 192...
-
Calculate \(|19|\).
-
Use your calculator to calculate 27 - (-13). Explain how the answer agrees with what was expected.
-
Use your calculator to calculate \(4+(-7)\). Explain how the answer agrees with what was expected.
Study smarter with the SolutionInn App