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...
-
Consider the rechargeable battery: Zn(s) | ZnCl2(aq) || Cl-(aq) | Cl2(l) | C(s) (a) Write reduction half-reactions for each electrode. From which electrode will electrons flow from the battery into a...
-
Prepare any necessary adjusting entries at December 31, 2016, for Melbourn Company's year-end financial statements for each of the following separate transactions and events. 1. Melbourn Company...
-
Visit www.pearsonglobaleditions.com/malhotra to read the video case and view the accompanying video. Subaru: Mr. Survey Monitors Customer Satisfaction presents an interesting overview of Joe...
-
A member of the city commission insists that the citys internal service fund prepare and submit a budget for commission approval. The commissioner argues that it is only through the budget that the...
-
Please indicate each account if its: - Balance sheet or income statment - is it credit or debit - what is the properties for each account as follow:cash, prepaid expenses, long term investments,...
-
The CEO of Kuehner Development Co. has just come from a meeting with his marketing staff where he was given the latest market study of a proposed new shopping center, Parker Road Plaza. The study...
-
Consider the Table below. A. Complete the table, and draw a graph showing Price, MR and MC of this monopoly. B. How many units this monopoly firm should produce in order to maximize profit, and what...
-
Flag Faber Manufacturing inc of st paul purchases 9,649 top of the line semiconductor; the maximum backordering quantity in units 502; lead time = 1.5 month ( the firm operates 12 months per year)....
-
1. Mr. i holds the following preferences over outcomes w, x, y, and z: xPw, xPy, zPx, yPz, wPy, and wPz. (a) Identify all five possible subsets of these outcomes that contain three or more outcomes....
-
Bleeker Street Pizza and Keste Pizza & Vino are located close to each other on Bleeker Street in the West Village. There are 450 potential customers every day, and suppose that each of them is...
-
One way in which economic growth is measured apart from GDP is in Purchasing Power Parity (PPP) terms. The Big Mac Index is the PPP concept applied to the cost of a Big Mac in different countries....
-
Artificial Intelligence (AI) has begun to take over many functions in the firm, including pricing, recruitment, talent promotion, advertising, loan issuance, default risk prediction, supply chain and...
-
Mimi's is developing a Fiery Habanero muffin, which will NOT compete with anything Mimi's currently offers. Unit contribution margin for the new Fiery Habanero muffin would be $3.69. Contribution...
-
Consider the reaction of acetic acid in water CH 3 CO 2 H(aq) + H 2 O(l) CH3CO 22 (aq) + H 3 O + (aq) where Ka 5 1.8 3 1025. a. Which two bases are competing for the proton? b. Which is the stronger...
-
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...
-
What are the stages in the product life cycle?
-
What are the tenets of the design-to-value approach to innovation?
-
How are products and services different?
Study smarter with the SolutionInn App