CPSC 231Fall 2001

D.H.

Programming Assignment 4.

Due: In class December 6th.

NO LATE ASSIGNMENTS WILL BE ACCEPTED.

Total: 30 points

Introduction.

The purpose of this assignment is to have the students practice creation and use of an index (binary) file as well as random access reading, writing, seeking, modifying and appending of a binaryfile in C++ .

Problem Description.

Develop a C++ program that uses binary file “Employee.dat”, created in assignment 1, the index file “EmployeeIndex.dat” created in the assignment 2, and the “Delete a record” feature of assignment of assignment 3. Add a new feature called “Insert a record”.

Your menu should consist of the following items.

1. Print employees ( id, last name, first name, sales).

2. Print employees sorted by Id. //old feature

3. Print employee salary. //old feature

4. Delete employee record. //old feature

5. Insert employee record.//new feature

6. Exit.

If the user chooses 1, then the program reads all the records from the Employee.dat.

The formatted records of data are then printed to the standard output device (screen) and written to a sequential text file “ProgramLog.txt.”

If the user chooses 2, then the program reads the index (already loaded to an array from the index file) and prints the corresponding records from the Employee.dat file to the screen and to “ProgramLog.txt”. The records are printed sorted by the user Id.

If the user chooses 3, the program displays the prompt asking for the employee id. Once the employee id is entered, the index is searched using “binary search” for the corresponding id and the employee info corresponding to it is read from the Employee.dat file, and the employee last name, first name and salary is printed to the screen and to “ProgramLog.txt.”

If the user chooses 4, the program displays the prompt asking for the employee id. Once the employee id is entered, the index is searched using “binary search” for the corresponding id. If the employee id is found, the data record and the corresponding record in the index file are marked for deletion (use –1 as a tombstone). Otherwise an error message “No employee found with Id=entered Id” is displayed and written to “ProgramLog.txt.

If the user chooses 5, the program displays the prompt asking for the employee info: employeeId, lastName, firstName, float rate, hoursOfwork. Once the employee info is entered, the index is searched using “binary search” for the entered user id. If the employee id is found, the following message is displayed: “The record cannot be inserted: the user ID= entered used id already exists”, and the program returns to the main menu. If the employee id is not found, a new record with entered employee info is inserted into the file system. The new record should be inserted in place of a deleted record if such exists (in both the “Employee.dat” file and in the index). Otherwise the new record should be appended at the end of “Employee.dat” and inserted into the index. Remember to resort the index array after insertion. The modified index should be written back to the index file. As before, all messages and employee info displayed on the screen have to be written to the “Program.txt” file.

Note, that it is required to use the index and RRN to locate the corresponding records for items 2,3, 4, 5 of the menu.

If the user chooses to exit, the program should terminate.

Program Input.

A binary file called Employee.dat consisting of the following records of fields:

int employeeId;

char lastName[15];

char firstName[15];

float rate;

int hoursOfWork;

For turning in your project, from the main menu choose:

2;

4 with employeeId = 555 (deleted in assignment 3);

5 with the following employee info employeeId = 555, lastName = Agabala firstName = Sahmarrate = 22.5 hoursOfWork = 25;

5 with the following employee info employeeId = 999, lastName= Gajos, firstName=Kim, rate= 30.0, hoursOfWork=20,

3 with employeeId = 555;

5 with the following employee info employeeId = 666, lastName= Wu, firstName=Gorge, rate= 15.25, hoursOfWork=40;

5 with the following employee info employeeId = 333, lastName= Nowicki, firstName=Jane, rate= 15.50, hoursOfWork=30;

5 with the following employee info employeeId = 150, lastName= Nguyen, firstName=Thui, rate= 20.0, hoursOfWork=35,

3 with employeeId=333,

3 with employeeId=666;

1;

2.

Program Output:

Print file ProgramLog.txt for your project output.

NOTE: Handout(s) about documenting and submitting programming assignments for CPSC 231,and an input data file for your program is posted at