home *** CD-ROM | disk | FTP | other *** search
- // Get our needed include files
- #include <fstream.h>
- #include <iomanip.h>
- #include "employee.h"
- #include "expense.h"
-
- void GetNewExpenseItem(ofstream& outfile, const unsigned itemnum)
- {
- Expense NewExpense;
- float ExpenseAmount;
- char TempBuffer[256], ChompNewline;
-
- // User friendly stuff
- cout << "\nExpense #" << itemnum+1 << "\n";
-
- // Fill in the basics
- cout << "Expense date : ";
- cin.get(TempBuffer, 256);
- cin.get(ChompNewline);
- NewExpense.SetDate(TempBuffer);
- cout << "Description : ";
- cin.get(TempBuffer, 256);
- cin.get(ChompNewline);
- NewExpense.SetDescription(TempBuffer);
- cout << "Expense amount : ";
- cin >> ExpenseAmount;
- cin.get(ChompNewline);
- NewExpense.SetExpenseAmount(ExpenseAmount);
-
- // Write the expense record to the file
- outfile << NewExpense;
- }
-
- void GetNewEmployee(ofstream& outfile)
- {
- Employee NewEmployee;
- unsigned long NewZip;
- unsigned loop, NewID, NewNumExpenses;
- char TempBuffer[256], ChompNewline, NewInitial;
-
- // User friendly stuff
- cout << "\nNew employee record\n";
- cout << "===================\n";
-
- // Fill in the basics
- cout << "Employee ID : ";
- cin >> NewID;
- cin.get(ChompNewline);
- NewEmployee.SetID(NewID);
- cout << "First name : ";
- cin.get(TempBuffer, 256);
- cin.get(ChompNewline);
- NewEmployee.SetFirstName(TempBuffer);
- cout << "Middle initial : ";
- cin >> NewInitial;
- cin.get(ChompNewline);
- NewEmployee.SetMiddleInitial(NewInitial);
- cout << "Last name : ";
- cin.get(TempBuffer, 256);
- cin.get(ChompNewline);
- NewEmployee.SetLastName(TempBuffer);
- cout << "Address : ";
- cin.get(TempBuffer, 256);
- cin.get(ChompNewline);
- NewEmployee.SetAddress(TempBuffer);
- cout << "City : ";
- cin.get(TempBuffer, 256);
- cin.get(ChompNewline);
- NewEmployee.SetCity(TempBuffer);
- cout << "State : ";
- cin.get(TempBuffer, 256);
- cin.get(ChompNewline);
- NewEmployee.SetState(TempBuffer);
- cout << "ZIP code : ";
- cin >> NewZip;
- cin.get(ChompNewline);
- NewEmployee.SetZip(NewZip);
- cout << "\nNumber of expense items for this employee? ";
- cin >> NewNumExpenses;
- cin.get(ChompNewline);
- NewEmployee.SetNumExpenses(NewNumExpenses);
-
- // Write the employee record to the file
- outfile << NewEmployee;
-
- // Now get the expense records
- for (loop = 0; loop < NewEmployee.GetNumExpenses(); loop++)
- GetNewExpenseItem(outfile, loop);
- }
-
- void main(int argc, char *argv[])
- {
- // Check for right number of command-line arguments
- if (argc != 2) {
- cout << "USAGE: expmaker <outfile name>\n\n";
- return;
- }
-
- // Open the outfile
- ofstream outfile(argv[1]);
-
- // Place our dummy employee count
- unsigned EmployeeCount = 0;
- outfile << setw(5) << EmployeeCount << setw(0) << " ";
-
- // Main employee loop
- char Again;
- do {
- char ChompNewline;
- EmployeeCount++;
- GetNewEmployee(outfile);
- cout << "\nEnter another employee (Y/N)? ";
- cin >> Again;
- cin.get(ChompNewline);
- } while (Again == 'y' || Again == 'Y');
-
-
- // Go to the beginning of the file and fill in the
- // real employee count
- outfile.seekp(0, ios::beg);
- outfile << setw(5) << EmployeeCount;
-
- // Close the outfile _ we're done!
- outfile.close();
- }