This is my last lab assignment for the semester. It was supposed to be due next week, but my instructor will be out next week so he decided today that it would be due on Thursday. He did this because this assignment is harder than the one originally due on Thursday (which I already have completed, just my luck).
I have the assignment pretty much done, but have one glitch and one lack of knowledge problem.
1. I have to display, after reading and manipulating the file, the number of records in the file. I can't find that operation in my book anywhere. If you could point me in the right direction I would appreciate it.
2. I will try to attach an output to show what I am talking about here, as well as the .txt file that I am reading from. Some of my records (the three with the shortest last names) have the info tabbed wrong. I have tried to correct this by modifying the .txt file, but no luck.
And before I get too much grief, my instructor specified all of the names, except the first one, which is the name of the student doing the assignment.
Code follows:
Code://Travis Bryant //CPT-168-A01 //Payroll Sequential File #include<iostream> #include<string> #include<iomanip> #include<fstream> using namespace std; int main() { //declarations string fnam = "",lnam = "", ssn = ""; double hrswrkd = 0.0, parat = 0.0, grpay = 0.0, ntpay = 0.0, d_duk = 0.0; system("color f0"); //header cout<<"\t\t\t***********************************\n"; cout<<"\t\t\t* Travis Bryant *\n"; cout<<"\t\t\t* CPT-168-A0 *\n"; cout<<"\t\t\t* Payroll Seqeuntial File *\n"; cout<<"\t\t\t***********************************\n\n"; ifstream infile; // Open payroll file infile.open("payroll.txt"); cout<<fixed<<setprecision(2); cout<<" SSN\t\tName\t\tHours\tRate\tGross\tDeductions\tNetpay\n"; cout<<" ____\t\t____________\t_____\t____\t_____\t__________\t______\n"; // priming read infile>>fnam>>lnam>>ssn>>hrswrkd>>parat; //begin while loop (priming read instruction) while(infile.eof() != true) { // calculate gross pay if (hrswrkd > 40) grpay = (40 * parat) + (hrswrkd - 40) * (1.5 * parat); else grpay = hrswrkd * parat; //calculate deductions d_duk = grpay * .10; //calculate net pay ntpay = grpay - d_duk; // Display output cout << " " << ssn.substr(7) << "\t\t" << fnam.substr(0,1) << ". " << lnam << "\t" << hrswrkd << "\t" << parat << "\t" << grpay << "\t" << d_duk << "\t\t"<< ntpay<< "\n"; // read next record infile>>fnam>>lnam>>ssn>>hrswrkd>>parat; } infile.close(); //display appreciation cout<<"\n\t\t\t\tTHANK YOU!!!\n\n"; system("pause"); return 0; }