// pgm13 -- employee program /* NEW for version g: input file with reading until end of input file */ // 10/5/16 #include #include #include #include using namespace std; int main() { /* Checking the return value of the stream operator << cout << "enter a number: "; int num; if ( cin >> num ) cout << "read the number: " << num << endl; */ // define variables string first, last; int idnum; double rate,hours,pay; // read in data for any number of employees // and keep a count in numemps int numemps=0, total=0; ifstream infile; ofstream outfile; infile.open("emp_data.txt"); outfile.open("emp_output_vf.txt"); if (!infile) { cout << "input file did not open." ; exit(1); } // removed all prompts when working with files // another way of checking for EOF (end of file) // while (!infile.eof()) while (infile >> idnum) { infile >> first >> last; infile >> hours >> rate; // calculate pay pay = hours * rate; // print everything cout << "Name: " << first << ' ' << last << " id: " << idnum << " Hours: " << hours << " rate: " << rate << endl; outfile << "Name: " << first << ' ' << last << " id: " << idnum << " Hours: " << hours << " rate: " << rate << endl; total+=pay; numemps++; cout << "pay for employee " << numemps << " is: " << pay << endl; outfile << "pay for employee " << numemps << " is: " << pay << endl; } // fell out of loop, print counter (numemps which is // number of employees processed.) cout << "Number of employees entered is: " << numemps << endl; cout << "Total pay is: " << total << endl; outfile << "Number of employees entered is: " << numemps << endl; outfile << "Total pay is: " << total << endl; return 0; }