C++ program help

Hello. I am very new to c++ and needed help with a code for my class. Here is the scenario.


You are given an input file (say Lab8_P1_InputFile.txt) with the following data:
Alex Antonio 9 1
John Jeffrey 14 0
Sala Kutha 12 1
Sara David 15 1
Tiffany Peterson 6 0
Justin Alberto 9 0
Nancy Scott 12 1

Each input line consists of a student's first name, last name, number of credits registered for the current term, and a flag that indicates whether the student is eligible for in-state tuition rate or not (1 means in-state rate, and 0 means out-state rate). For example, in the first input line, the first name of the student is Alex, the last name is Antonio, the number of registered credit hours is 9, and the student is eligible for in-state tuition rate.

Write a program that reads data from the specified input file and stores the output in an output file (say Lab8_P1_OutputFile.txt). If the tuition per credit hour is $350 for in-state students and $570 for out-state students. You need to read the information for each student from the input file, compute the total tuition amount, and then write the required information into the output file.
For each student, the data must be written into the output file in the following format:
lastName, firstName NumberOfCreditsRegistered TotalTuitionAmount
For example, the first line in the output file should be as below:
Antonio, Alex 9 3150


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <iostream>

#include <fstream>

#include <string>

using namespace std;

int main ();

{

int name, number_Credit_Hours, cost;

string xyz;

ifstream inFile;

ofstream outFile;

inFile.open ("indata.txt");

outFile.open("outdata.txt");

return 0;

}
Okay, so far so good.

My suggestion is to write in comments what each part of the program needs to do, then turn those comments into working code. Go through it step by step, break up what needs to be done into chunks, and continue from there. Example:

1
2
3
4
5
6
7
inFile.open ("indata.txt");
outFile.open("outdata.txt");
//Check if both files opened, if not, end the program.
//Repeat the following code while the inFile.eof() is false.
//This bit is for you to figure out.
//End of the loop.
//More bits for you to figure out~! 


Remember: you can read and write to file streams just like from cout and cin.

-Albatross
Alright, cool. Where do I go from here now though? This seems so complex that I do not even know where to begin
closed account (9jNRX9L8)
I was just wondering is this just a windows thing but I don't need to have #include <string>. I can just type string xyz with no includes...
@Toggy11
It's not a windows only thing. I believe some C++ standard library implementations have <iostream> include <string>. Don't rely on it. :P

@blackmagic24
How well do you understand file input/output? That's basically what this is an exercise in. If you don't feel you understand it very well, see if this helps at all:
http://www.cplusplus.com/doc/tutorial/files/

Let us know if you have any more questions. :)

-Albatross
Topic archived. No new replies allowed.