Starting from:

$15

Laboratory Exercise Week 10 solution

Task One: Debugging
Programs subtract.cpp and CSL.cpp contain various errors; syntax, logical and/or with respect to the sample output. Find and fix bugs in subtract.txt and CSL.txt.
Task Two: Binary file I/O
Create a class named Employee in a file Employee.h. Data members include the Employee’s ID number, first and last names, and the hourly pay rate. Implement member functions include overload insertion (<<) operator in a file Employee.cpp. Implement main() function and other functions in a file EmployeeIO.cpp. Data of employees are stored in a BINARY data file edata.bin.
In the main() function, if the binary file does not exist, you should create an empty binary file. Do not load all Employee records into the memory (such as arrays or other containers).
Use advanced input / output functions (such as read(), write, seekp(), seekg()) and manipulators to add new employee record in the binary file, search a record from the file and update the data in the binary file. Declare and implement separate functions to perform following actions when the program prompts menu and a user input his / her choices.
1. Add a new employee.
2. Search an employee.
3. Update an employee hourly pay rate.
0. Exit.
Input your choice:
When the user chose 1, the program prompts input for an employee record and adds the record into the binary file edata.bin:
Employee ID: 1001
First name: Adam
Last name: Smith
Pay rate /hour: 128.35
A record has been added.
Employee ID: 100
First name: Alice
Last name: Spring
Pay rate /hour: 135.75
A record has been added.
Employee ID: 1001
The employee ID already exists.
When the user chose 2, the program prompts input for an employee ID, searches the record from the binary file edata.bin and displays the formatted results:
Employee ID: 100
Employee ID: 100
First name: Alice
Last name: Spring
Pay rate/hour: $00135.75
When the user chose 3, the program prompts input for an employee ID, searches the record from the binary file edata.bin and displays the formatted results, then ask the new value for hourly pay rate:
Employee ID: 100
Employee ID: 100
First name: Alice
Last name: Spring
Pay rate/hour: $00135.75
New pay rate/hour: 145.38
A record has been updated.
When the user chose 0, the program terminated.
Hint: You should define fixed size char arrays to store the values for the first name and the last name.

More products