10.5 Programming Project #5:File I/OBackgroundRecall that we are iterating on the development of a payroll program. At this point, youshould have a working Employee class. In this project you will add the ability forobjects of your Employee class to write themselves out to a file, and be read in from afile. The ability for an object to save itself in a file is called persistence.You will also throw an exception if there are any file I/O errors. Get your programworking without exception handling first. Then add the exception handling.Objectives Continue to refine your object oriented design skills. Create the proper structure and code for a C++ program containing a class ofyour design. Create a class that has persistence. Throw and handle an exception. Create a main() function to test the additions to your class.The Employee ClassFor this project you need to add the following member functions to your Employeeclass.Employee read(ifstream&)void write(ofstream&)The function Employee::read is a static member function. It returnsan Employee object based on the data it reads from a file. It must be calledas Employee::read() since its job is to create an object. If there is a read error,it throws a std::runtime_error(defined in <stdexcept>) exception with anappropriate message. Note that you are passing the stream by reference, not by value(streams cannot be copied).The main() functionThe major goal of main() is to test the additions to your Employee class. Usethe printCheck() function from your previous Employee project. The output of yourprogram will look similar to the output of your previous Employee project.Your driver will contain a main() function that does the following:Present the user with a menu of choices, create a data file, or read data from a file andprint checks:This program has two options:1 Create a data file, or2 Read data from a file and print paychecks.Please enter <1> to create a file or <2> to print checks:If the user selects the first option, your program should: Create an ofstream object using a file name obtained from the user. Pass justthe file name as the parameter (no path) so that your program assumes the fileto be in the same folder as your executable file. Create three employee objects as shown: Employee joe(37, Joe Brown, 123 Main St., 123-6788, 45.00, 10.00) Employee sam(21, Sam Jones, 45 East State, 661-9000, 30.00, 12.00) Employee mary(15, Mary Smith, 12 High Street, 401-8900, 40.00,15.00) Send messages to each of the three Employee objects to write themselves outto the file. Print a message that creation of the file is complete. Exit.If the user selects the second option, your program should: Prompt for the name of the file that the program saved. Call Employee::read to read in the objects written in step 1, one-by-one. Call the printCheck() function for each of the three new objects, just as youdid in the previous project. Exit.Run the second option twice. Once with the correct filename, and once with anincorrect one. The second run will test your exception handling. In the error case, throwa std::runtime_error (defined in <stdexcept>) with a suitable error messagestring. Catch the exception and print its message in main, then exit the program. Note:you must test for input errors for each input operation.In addition, when reading the file for the second part, you need to check that theexpected data is there. If there are any errors in the data (there shouldnt be, but youshould check anyway), your code should throw a std::runtime_error with amessage explaining which data was corrupted.Submitting Your AssignmentSubmit your 3 source files, just as you did in the previous project.Sample execution follows. Note that only the checks are printed.This program has two options:1 Create a data file, or2 Read data from a file and print paychecks.Please enter (1) to create a file or (2) to print checks:1Please enter a file name: employee.datData file created you can now run option 2.This program has two options:1 Create a data file, or2 Read data from a file and print paychecks.Please enter (1) to create a file or (2) to print checks:2Please enter a file name: employee.dat..UVU Computer ScienceDeptPay to the order of JoeBrown$344.38United Community Credit Union…Hours worked: 45.00Hourly wage: 10.00..UVU Computer ScienceDeptPay to the order of SamJones$261.00United Community Credit Union…Hours worked: 30.00Hourly wage: 12.00..UVU Computer ScienceDeptPay to the order of MarySmith$435.00United Community Credit Union…Hours worked: 40.00Hourly wage: 15.00This program has two options:1 Create a data file, or2 Read data from a file and print paychecks.Please enter (1) to create a file or (2) to print checks:2Please enter a file name: foo.datCouldnt open file for input
CS-1410
[Solved] CS-1410-project 5-File_IO
$25
File Name: CS-1410-project_5-File_IO.zip
File Size: 235.5 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.