This week's lab is different from what we have been doing. Lab 9 is worth 20 points, but is done over two weeks. The lab is due on March 20 (for Tuesday students) and March 21 (for Wednesday students). We will hold a normal class both weeks so you can work on and get help with your program. You are allowed to work from home. In fact, in light of the amount of detail in this lab, this is highly encouraged. From home, you are still encouraged to ask questions. You can Email me or IM me on AOL Instant Messenger using the screenname umrDylan. Notice which parts are required this time and which parts are extra credit.
The RARO Management Team has been so impressed with your previous work of making database systems that don't store anything to files that they want you to make a new part of the database system that can actually read from & write to files.
The first phase of this project is to make all the functions the RARO Accounting Team will need in keeping track of employees. Employees can stored in the following struct:
struct employee
{
char name[64];
char gender;
bool hasBeenSacked;
unsigned long hireDate;
double totalSales;
};
| Field | Description |
| name | The employee's name as a C String (NTCA). |
| gender | The employee's gender, 'm' & 'M' are male and 'f' and 'F' are female. |
| hasBeenSacked | true if the employee was previously fired, false if not. |
| hireDate | The number of seconds since Jan 1, 1970 00:00 UTC that the employee was hired (see Part VI). |
| totalSales | The amount of sales the employee has generated for RARO. |
In order to work with this struct, we will need the following functions:
In your main() function, test all three functions and make sure they behave well.
Take your Part I and create an array of 4 employees. Change your main() function accordingly. Also, your supervisor saw your work and was very impressed. He wanted you to add a void printEmployee(employee &salesPerson) function that will print a particular employee in a human-readable (i.e, easy-to-read) format.
Take your Part II and add menu system that will allow the user to change the array, and write it to a file. So, for example:
1) Create Employee
2) Enter Employee Sale
3) Fire Employee
4) Print Employee Database
5) Write Employee Database to File
6) Quit
Menu options 1 - 3 should have already been implemented in Parts I & II. When the user is asked to write the database to the file, the following steps should occur:
You can use employees.txt as an example of what your output file should look like. Also, you may want to add another option to the menu: Print Database. This option will loop through the array and print all the employee information using the printEmployee() function you wrote in Part II.
Take your Part III and add another menu option: Read Employee Database from File. This option will basically do the reverse of writing the employee database. It will first see how many employees are in the file, then read each employee one by one and build the database by using the functions you wrote in Part I.
RARO wants you write one more function: unsigned short findBestPerson(employee database[], char gender = '\0');. This function will go through the database and find the “best” employee of that gender, which would be the person with the highest sales numbers that hasn't been fired. The function should return the index of the best employee or the size of the database if nobody are currently employed. If bestGender is the NUL character, then the function should find the best employee, male or female.
NOTE: The RARO Accounting Team is of the opinion that 4 employees is not enough to test this last functionality. So, test this part with 6 employees instead of 4.
An inquisitive programmer from the RARO Software Engineering Team (i.e., you) asked why the hireDate was constantly 0. The Pointy-Haired Boss from the Management Team claimed you should have known about it and that the hireDate should have been set using the time() function all along. Change your makeEmployee() function to ask the user for string that contains the date of hiring (e.g., "10/21/1997") and then finds the number of seconds elapsed between January 1, 1970 00:00 and that date (HINT: mktime()). You can format the date string as you wish, just tell the user what you're expecting when prompting for the date. So, for example:
Enter the hire date (MM/DD/YYYY):
Enter the hire date (YYYY.MM.DD):
Enter the hire date (DD.MM.YYYY):
You can use any of the above formats or one of your own. The only requirements are you tell the user about your format, use a string to parse the date (do NOT ask for the information as integers or other numerical variables), and that you use four digit years to avoid Y3K problems.
Hints are listed in the order of the part(s) they apply to:
Part I is worth 8 points. Part II is worth 10 points (Part I + 2 more points). Part III is worth 14 points (Part II + 4 points more points). Part IV is worth 18 points (Part III + 4 more points). Part V is worth 20 points (Part IV + 2 more points). Part VI is worth 24 points (Part V + 4 extra credit points). The lab is out of 20 points. When you're done, submit your lab09.tar.gz file on Blackboard. I will be grading your program on the following criteria:
![[Dilbert]](dilbert.gif)