Problem 20.docx

  • Uploaded by: Jan Ryan R. Relunia
  • 0
  • 0
  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Problem 20.docx as PDF for free.

More details

  • Words: 1,297
  • Pages: 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 Write Write Write Write Write Write

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

Format of file is EMPLOYEES.TXT[/b]

1 2 3 4 5 6 7 8 9 10

Hours Pay Rate Employee Number First Name Last name 40.0 10.00 A1234 Jane Adams 50.0 10.00 L8765 Mary Lincoln 25.5 10.85 W7654 Martha Washington 52.0 15.75 A9876 John Adams 45.0 25.00 W1235 George Washington 40.25 55.00 L9087 Abraham Lincoln 30.0 9.75 T9876 William Tell 42.5 12.50 M7654 Missy Muffett 30.0 10.00 P8765 Peter Piper

HERE IS MY CODE SO FAR:

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1

#include #include #include #include <string> #include using namespace std; void tellUser(); double regular(int &); int main() { const int SZ = 55; // size of arrays to hold employees string firstname, lastname, fullname, employee; //name of golfer float hours, rate, overtime; //scores of four golfer // int total; // total of four rounds of golfer bool screenonly = false; ifstream inputFile; //input filename in program ofstream outputFile; //read input from file employees.txt tellUser(); inputFile.open("employees.txt"); if (inputFile.fail()) { cout <<"Error! opening file golfers.txt\n\n"; cout <<"end of program"; }

Ed it & Ru n

9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4

else { outputFile.open("payroll.txt"); if (outputFile.fail()) { screenonly = true; cout <<" output file did not open\n"; cout <<" output file will only be sent to the screen\n"; } cout <<" First Last Employee Hours Rate Regular Overtime Gross\n"; cout <<" Name Name Number Worked of Pay Pay Pay Pay\n"; cout <<"===================================================================== =========================\n"; outputFile <<" First Last Employee Hours Rate Regular Overtime Gross\n"; outputFile <<" Name Name Number Worked of Pay Pay Pay Pay\n"; outputFile <<"===================================================================== ====================\n"; while (inputFile >> firstname) // there is a line of data to read { inputFile >> lastname; // read golf score inputFile >> employee; // read golf score inputFile >> hours; // read golf score inputFile >> rate; // read first name of golfer // inputFile >> lastname[i];// read last name of golf // cout<< setw(7) << firstname << setw(13) << lastname; cout<< setw(12) << employee << " " << setw(10) << hours << " "; cout<< setw(11) << rate << " " << setw(11) << regular << " \n"; // cout<< setw(5) << total << " " << setw(7) << fixed << setprecision(2) << average << " \n"; // cout<< firstname << " " << lastname << "\n"; // cout <<"===================================================================== ==============================\n"; // cout <<" Total Gross Pay \n"; if (!screenonly) { fullname = firstname + " " + lastname; outputFile << setw(14) << left << fullname outputFile << setw(4) << fixed << right << outputFile << setw(4) << fixed << right << outputFile << setw(4) << fixed << right << }

<< " "; employee << " "; hours << " "; rate << " \n";

} inputFile.close(); //close the file after reading it cout << "\nInput file closed\n\n"; if (!screenonly) outputFile.close();

7 4 8 4 9 5 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 6 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

} return 0; } /* *function * */ void tellUser() { cout<<"\nThis program reads a file called golfers.txt,\n"; cout<<"and it calculates the total and average for each golfer.\n"; cout<<"output is written to the screen. \n\n"; //tell user what program does } /* *kkk * */ double regular(int &) { int empCount; double grossPay; double hours, rate; if(hours <= 40) grossPay = hours * rate; }

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 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9

First

Last

Employee

Hours

Rate

Regular

Ove Name Name Number Worked of Pay Pay P ========================================================================== ====== Jane Adams A1234 40 10 1 Mary Lincoln L8765 50 10 1 Martha Washington W7654 25.5 10.85 1 John Adams A9876 52 15.75 1 George Washington W1235 45 25 1 Abraham Lincoln L9087 40.25 55 1 William Tell T9876 30 9.75 1 Missy Muffett M7654 42.5 12.5 1 Peter Piper P8765 30 10 1 Input file closed

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

Related Documents

Problem
June 2020 31
Problem
June 2020 29
Problem
December 2019 39
Problem
December 2019 43
Problem
May 2020 21
Problem
November 2019 33

More Documents from ""

Problem 18.docx
April 2020 6
Problem 20.docx
April 2020 8
Prob16 - 20.pptx
April 2020 6
Problem07-10.pptx
April 2020 5
001
August 2019 32
Golicyn_klamstwa
June 2020 19