1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
#include <string>
#include <iomanip>
#include <cctype>
#include <fstream>
using namespace std;
struct employeetype
{
string fname, lname;
int id;
char status;
double payrate;
double hoursworked;
};
void data_out(string, string, int, char, double, double);
string format(string);
int main ()
{
employeetype employee;
cout << "Kevin Hunt Assignment #5 Section #1010" "\n\n";
ifstream infile;
string filename1;
cout << "Enter the name of first data file." "\n";
cin >> filename1;
infile.open(filename1.c_str());
cout << "NAME ID# STATUS RATE" "\n";
infile >> employee.fname;
while(infile)
{
infile >> employee.lname >> employee.id >> employee.status >> employee.payrate >> employee.hoursworked;
data_out(employee.fname, employee.lname, employee.id, employee.status, employee.payrate, employee.hoursworked);
infile >> employee.fname;
}
return 0;
}
void data_out(string fname, string lname, int id, char status, double payrate, double hoursworked)
{
cout << format(lname) << ",";
cout << format(fname);
cout << right << setw(13) << id;
cout << right << setw(11) << status;
cout << right << setw(4) << "$" << right << setw(5) << setprecision(2) << payrate << "\n";
}
string format(string word)
{
string temp = " ";
int wlen;
wlen = word.length();
temp = temp + char(toupper(word[0]));
for(int i = 1; i<wlen; i++)
{
temp = temp + char(tolower(word[i]));
}
return temp;
}
|