Assume the input data is structured as follows: first there is a non-negative in
ID: 3543087 • Letter: A
Question
Assume the input data is structured as follows: first there is a non-negative integer specifying the number of employee timesheets to be read in. This is followed by data for each of the employees. The first number for each employee is an integer that specifies their pay per hour in cents. Following this are 5 integers , the number of hours they worked on each of the days of the workweek. Given this data, and given that an int variable total has been declared , write a loop and any necessary code that reads the data and stores the total payroll of all employees in total . Note that you will have to add up the numbers worked by each employee and multiply that by that particular employee's pay rate to get the employee's pay for the week-- and sum those values into total .
Explanation / Answer
Looks good so far. The assignment doesn't say what to do with that total, so you can try to be a smart aleck and just hand that in, (with appropriate decoration to make it a C++ main program), or you can print out the total to demonstrate that you have the right answer.
You might want to hack up a spreadsheet with some test numbers. Multiply column A by the sum of columns B-F to produce column G, and then sum down column G. Then export the data rows to a comma-separated-value text file, open that in your text editor and change commas to spaces. Add a leading line saying how many data lines follow, and you have a test file where you know the answer without a lot of calculator work. (Or the chance of one mistyped entry ruining the whole sum!)
Edit: Oh yes, to test with that data file, run from the terminal or command prompt:
myprogname <thedata.txt
...from the directory where the executable file was produced during the compile. You'll need to store your data file there too, as "thedata.txt". The < symbol is Unix input redirection, which works on Linux, Windows and Mac too. All standard input (cin) will come from that file during the run instead of the keyboard.
If your terminal/command-prompt window will accept multiple lines in a single paste, you can easily run from the console without redirection and paste the whole test data set in with a single key or click.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.