Write a C++ program called business.cpp to accomplish the following:
- Read from a user supplied filename containing employee data (example: /usr/local/share/business.dat)
The information is in the following order, one per line:- Hourly wage as a floating point number
- First Name as a string
- Last Name as a string
- Position or title (may have spaces)
100.50 Bill Gates Vice President 35 Terry Bradshaw Secretary 42.45 Wally Cleaver Senior Vice President 23.45 James Taylor Welder 13.45 TJ McCall Senior Programmer
- Obtain the number of employes by reading the data until you reach the end of the file and incrementing for each set of data (hourly wage, first name, last name, title). Use the program called filer.c as a model for how this can be done.
- The Employee class should look something like this (you can and should extend this but you need to have at least what is shown):
class Employee { private: public: float HourlyRate; string FirstName; string LastName; string Position; void fired(void); void changerate(float amount); }; void Employee::fired(void) { HourlyRate=0; cout << FirstName << " " << LastName << ", you are fired! You are currently earning $" << HourlyRate << " per hour." << endl; } void Employee::changerate(float amount) { HourlyRate+=amount; if (HourlyRate < 5.15) HourlyRate = 5.15; cout << FirstName << " " << LastName << ", you are currently earning $" << HourlyRate << " per hour." << endl; } - Use your swap and sort functions from your program array3.c in order to sort your employees from highest hourly rate of pay to lowest. You will need to make only MINOR changes to each function. For example, the two swap function parameters will be of type Employee rather than type int or float. Also, you will compare something like A[ii].HourlyRate < A[ii].HourlyRate in the sort function rather than just comparing something like A[ii] < A[jj].
- Output your employees to the screen in a nice formatted order like the following example indicates:
Hourly Wage First Name Second Name Position ----------------------------------------------------------- 100.50 Bill Gates Vice President 42.45 Wally Cleaver Senior Vice President 35.00 Terry Bradshaw Secretary 23.45 James Taylor Welder 13.45 TJ McCall Senior ProgrammerFor example, if you had a Product object array with MAX elements and wanted to print out its float dollaramount values in one column and string description in the second column, this code would do it for you:
for (int ii=0 ; ii<MAX ; ++ii) { cout << setiosflags( ios::fixed | ios::showpoint ) << setw(11) << setprecision(2) << Product[ii].dollaramount << " " << setw(15 - Product[ii].description.length()) << resetiosflages( ios::left ) << Product[ii].description << endl; }
0 comments:
Post a Comment