I don't know how to do this c++ code dealing with opening files and editing them.

Create a text file containing the following data (without the headings):

Name Social Security Number Hourly Rate Hours Worked
B Caldwell 555-88-2222 7.32 37
D Memcheck 555-77-4444 8.32 40
R Potter 555-77-6666 6.54 40
W Rosen 555-99-8888 9.80 35

(b) Write a C++ program that reads the data file created in Exercise (a) and computes and displays on the screen a payroll schedule. The output should list the Social Security number, name, and gross pay for each person, calculating gross pay as Hourly Rate × Hours Worked.
do you have a layout? method for writing this? what exactly do you not understand? we need something to work off.
Sorry, the information was supposed to be in table format.
Well, I have sort of a the beginning of the pseudocode set up but I'm not quite sure how to edit the file and just display Social Security number, name, and gross pay for each person, instead of the original file.

Pseudocode:
Declare variables
Declare input and output stream objects
Read filename
Open input stream

do you have any code written?
this is what I have so far:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream payroll;
  payroll.open ("payroll.txt");
  payroll.close();
  return 0;
}
Do you know how to read in each variable from the file? I need to know what exactly you're having trouble with.
No. I don't know how exactly to read the file, firstly. Then which code could I use to edit the file?
heres a couple videos that should solve this problem for you easily, the examples he does are almost exactly alike.
http://thenewboston.org/watch.php?cat=16&number=67
http://thenewboston.org/watch.php?cat=16&number=66
EDIT: Watch both, first then second.
Last edited on
Thank you very much.
Topic archived. No new replies allowed.