Question: IN C++ (struct.C) Make a programthat will do the following. 1. Download the input file, employees.dat, from my public directory. While you are in your
IN C++ (struct.C) Make a programthat will do the following. 1. Download the input file, employees.dat, from my public directory. While you are in your own cs111 directory, use the copy command (cp). [smith001@empress cs111] cp /cs/slott/cs111/employees.dat . Copying into the current directory Assume this input file contains an unknown number of lines. Each line contains the information about an employee - first name, last name, gender, hourly rate, employee id and age. Assume the number of lines/employees never exceeds 100. Ada Agusta F 10.00 19569 28 Issac Asimov M 18.25 63948 58 : : 2. Create a struct called employee. 3. In the main, create an array of the struct employee type called empAr. Use const for the size (100) of the array. const int MAX_EMP = 100; //Assume the number of employees never exceeds 100. 4. Make a function called readData that will read all the data from the input file into the array. This function should return the number of employees to the caller. Assume you dont know how many employees you have (use the while loop). Declare the input file and open and close it in this function. ??? readData( ??? ) { int num = 0; //the number of employees declare the input file open it if it doesnt exist, display an error message if it exists, read each employee from the file and store it in the array. Keep counting how many employees you have (increment num by 1 in each loop.). close the file. return num; num has the number of employees. } 5. Call readData() in the main and display the number of employees (make sure you have the right number, 16). Run your program now and make sure you get 16 from readData(). Sample Run There are 16 employees. 6. Make a function called findMale that will output the employee ids and first and last names of all the male employees to the output file (name it maleOut.dat) in the following format. Allocate 10 spaces for each column. Hint: Declare the output file and open and close it in this function. Dont go through the entire array. Pass the number of employees returned from readData() to this function and check only the slots being occupied. NOT 100. The actual number of employees in the input file. for(int i = 0; i < numEmp; i++) 63948 Issac Asimov 48482 Humphry Bogart 7. Call findMale() in the main and check if the output file maleOut.dat contains all the male employees. Run your program now. Output file 63948 Issac Asimov There should be 11 males 48482 Humphry Bogart : : 8. Make a function called findEmployee. Ask the user to enter an employee id that she is looking for in the main. This function will return true if the id is found or false otherwise. Do not use cout to show a result in this function. You will show it in the main. Dont go through the entire array. Pass the number of employees returned from readData() to this function and check only the slots being occupied. Refere to page 4 in our lecture notes in Week 11-2. ????? findEmployee(???????, ???????, ?? key) NOT 100. The actual number of employees in the input file. for(int i = 0; i < numEmp; i++) 9. Call findEmployee () in the main. Tell the user whether or not the id was found. Sample Run 1 Enter the employee id: 48482 The employee was found. Sample Run 2 Enter the employee id: 11111 The employee was not found. -------------------------------------------------- employees.dat is --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Ada Agusta F 10.00 19569 28
Issac Asimov M 18.25 63948 58
Humphry Bogart M 20.00 48482 56
Albert Einstein M 11.10 47474 67
Emmylou Harris F 33.50 72647 38
James Kirk M 18.85 82828 46
Ted Kopple M 22.25 37376 48
David Letterman M 15.50 19338 47
Stevis Nicks F 18.85 23459 38
Monty Python M 33.35 80939 44
Roger Rabbit M 15.00 91343 24
Sally Ride F 25.50 91123 30
Rod Serling M 55.50 93939 56
Luke Skywalker M 19.95 12343 35
Kit Ross F 11.00 20000 21
Mike Smith M 23.35 10000 30
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
