You are on page 1of 6

Read the input file of data ( employees.txt) and store them in arrays.

This company can


have up to 55 employees

[b]i need to do these following in these program:AND MY CALCULATION IS GOING WRONG

Write a function to read the input file and store the data in arrays.
Write a function to calculate regular pay.
Write a function to calculate overtime pay
Write a function to calculate gross pay.
Write a function to bubble sort the employees into order by last name, first name.
Write any swap functions that are needed.
Write a function to write output to a file called payroll.txt

Format of file is EMPLOYEES.TXT[/b]

1 Hours Pay Rate Employee Number First Name Last name


2 40.0 10.00 A1234 Jane Adams
3 50.0 10.00 L8765 Mary Lincoln
4 25.5 10.85 W7654 Martha Washington
5 52.0 15.75 A9876 John Adams
6 45.0 25.00 W1235 George Washington
7 40.25 55.00 L9087 Abraham Lincoln
8 30.0 9.75 T9876 William Tell
9 42.5 12.50 M7654 Missy Muffett
10 30.0 10.00 P8765 Peter Piper

HERE IS MY CODE SO FAR:


1 #include <iostream> Ed
2 #include <cstdio> it
3 #include <fstream> &
4 #include <string> Ru
5 #include <iomanip> n
6 using namespace std;
7 void tellUser();
8 double regular(int &);
9 int main()
1 {
0 const int SZ = 55; // size of arrays to hold employees
1 string firstname, lastname, fullname, employee; //name of golfer
1
1 float hours, rate, overtime; //scores of four golfer
2 // int total; // total of four rounds of golfer
1 bool screenonly = false;
3
1 ifstream inputFile; //input filename in program
4 ofstream outputFile;
1
5 //read input from file employees.txt
1 tellUser();
6 inputFile.open("employees.txt");
1 if (inputFile.fail())
7 {
1 cout <<"Error! opening file golfers.txt\n\n";
8 cout <<"end of program";
1 }
9 else
2 {
0 outputFile.open("payroll.txt");
2 if (outputFile.fail())
1 {
2 screenonly = true;
2 cout <<" output file did not open\n";
2 cout <<" output file will only be sent to the screen\n";
3 }
2 cout <<" First Last Employee Hours Rate
4 Regular Overtime Gross\n";
2 cout <<" Name Name Number Worked of Pay
5 Pay Pay Pay\n";
2 cout
6 <<"=====================================================================
2 =========================\n";
7
2 outputFile <<" First Last Employee Hours Rate
8 Regular Overtime Gross\n";
2 outputFile <<" Name Name Number Worked of
9 Pay Pay Pay Pay\n";
3 outputFile
0 <<"=====================================================================
3 ====================\n";
1 while (inputFile >> firstname) // there is a line of data to read
3 {
2 inputFile >> lastname; // read golf score
3 inputFile >> employee; // read golf score
3 inputFile >> hours; // read golf score
3 inputFile >> rate; // read first name of golfer
4 // inputFile >> lastname[i];// read last name of golf
3 //
5 cout<< setw(7) << firstname << setw(13) << lastname;
3 cout<< setw(12) << employee << " " << setw(10) << hours << " ";
6 cout<< setw(11) << rate << " " << setw(11) << regular << " \n";
3 // cout<< setw(5) << total << " " << setw(7) << fixed <<
7 setprecision(2) << average << " \n";
3 // cout<< firstname << " " << lastname << "\n";
8 // cout
3 <<"=====================================================================
9 ==============================\n";
4 // cout <<" Total Gross Pay
0 \n";
4
1 if (!screenonly)
4 {
2 fullname = firstname + " " + lastname;
4 outputFile << setw(14) << left << fullname << " ";
3 outputFile << setw(4) << fixed << right << employee << " ";
4 outputFile << setw(4) << fixed << right << hours << " ";
4 outputFile << setw(4) << fixed << right << rate << " \n";
4 }
5 }
4 inputFile.close(); //close the file after reading it
6 cout << "\nInput file closed\n\n";
4 if (!screenonly) outputFile.close();
7 }
4 return 0;
8
4 }
9 /*
5 *function
0 *
5 */
1 void tellUser()
5 {
2 cout<<"\nThis program reads a file called golfers.txt,\n";
5 cout<<"and it calculates the total and average for each golfer.\n";
3 cout<<"output is written to the screen. \n\n"; //tell
5 user what program does
4 }
5 /*
5 *kkk
5 *
6 */
5 double regular(int &)
7 {
5 int empCount;
8 double grossPay;
5 double hours, rate;
9 if(hours <= 40)
6 grossPay = hours * rate;
0
6 }
1
6
2
6
3
6
4
6
5
6
6
6
7
6
8
6
9
7
0
7
1
7
2
7
3
7
4
7
5
7
6
7
7
7
8
7
9
8
0
8
1
8
2
8
3
8
4
8
5
8
6
8
7
8
8
8
9
9
0
9
1
9
2
9
3
9
4
9
5
9
6
9
7
9
8
9
9

\AND THIS IS MY OUTPUT:


1 This program reads a file called golfers.txt,
2 and it calculates the total and average for each golfer.
3 output is written to the screen.
4
5 First Last Employee Hours Rate Regular
6 Ove
7 Name Name Number Worked of Pay Pay
8 P
9 ==========================================================================
1 ======
0 Jane Adams A1234 40 10 1
1 Mary Lincoln L8765 50 10 1
1 Martha Washington W7654 25.5 10.85 1
1 John Adams A9876 52 15.75 1
2 George Washington W1235 45 25 1
1 Abraham Lincoln L9087 40.25 55 1
3 William Tell T9876 30 9.75 1
1 Missy Muffett M7654 42.5 12.5 1
4 Peter Piper P8765 30 10 1
1
5 Input file closed
1
6
1
7
1
8
1
9
Nov 6, 2013 at 1:20am
GokuK97 (73)
need help
Nov 6, 2013 at 1:49am
MikeyBoy (4656)
At line 95, you declare two variables, hours and rate, but you don't initialise them. You then
immediately try to use their values, despite the fact that you haven't given them any values.

Doesn't your compiler warn you about using uninitialised values?


Nov 6, 2013 at 5:08am
GokuK97 (73)
it does and it has to read data from txt file above
that my my whole to read data from txt and store it in array and how to read data, for example if
hours <= 40, so will it know how many hours are there
Nov 6, 2013 at 11:25am
GokuK97 (73)
need help
Nov 6, 2013 at 11:32am
Zhuge (4659)
Try fixing the issue MikeyBoy mentioned and see what happens next.
Nov 6, 2013 at 6:31pm
MikeyBoy (4656)

it does and it has to read data from txt file above


that my my whole to read data from txt and store it in array and how to read data, for example if
hours <= 40, so will it know how many hours are there

I don't understand what you're trying to say here.

But your regular function function isn't working, for the reasons I've explained - it's trying to use the
values of hours and rate , but you haven't given them any values.

Edit: You should pay attention to the compiler warnings. They usually tell you useful things.
Last edited on Nov 6, 2013 at 6:32pm
Nov 6, 2013 at 7:40pm
narutopk1985 (2)
1. Move the file pointer to the next line of your file before starting the loop. One way of doing it can be
char buff[255] = {0}; inputFile.getline(buff, 255);
2. Read the input in a correct sequence as stored in your input file. example:
while (inputFile >> hours) // there is a line of data to read
{
inputFile >> rate;
inputFile >> employee;
inputFile >> firstname;
inputFile >> lastname;
Nov 7, 2013 at 1:14am
GokuK97 (73)
ohh i got it
Nov 7, 2013 at 1:15am
GokuK97 (73)
but give me error it o make one change

You might also like