I'm having a lot of problems writing a program to open a file listing the grades of 4 students, all listed next to their names, and outputting an appended version of the file with the average of the scores next to the numbers on each line.

it goes something like this:
[here is the input]
test_ line_ 10 20 30 40 50 60 70 80 90 100
Price Betty 40 50 60 70 60 50 40 30 60 90
Good John 60 70 80 90 50 60 90 90 100 90
Smith Charles 70 80 90 60 70 60 80 90 90 90
Spangenberg Ward 70 70 80 90 70 80 90 80 70 60


[After]
test_ line_ 10 20 30 40 50 60 70 80 90 100 55.00
Price Betty 40 50 60 70 60 50 40 30 60 90 55.00
Good John 60 70 80 90 50 60 90 90 100 90 78.00
Smith Charles 70 80 90 60 70 60 80 90 90 90 78.00
Spangenberg Ward 70 70 80 90 70 80 90 80 70 60 76.00

I have to use at least one function that has file streams as all or some of its arguments.

Here's what I have so far, and am confused about where to go from here:

#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;

void grade_update(ifstream& student_grades, ofstream& avg_grade, double avg);
int main()
{
	ifstream in_put;
	ofstream out_put;

	in_put.open("gradeBook.txt");
	if (in_put.fail())
	{
		cout << "Input file opening failed.\n";
		exit(1);
	}

	out_put.open("gradeBook2.txt", ios::app);
	if (out_put.fail())
	{
		cout << "Output file opening failed.\n";
		exit(1);
	}

	in_put.close();
	out_put.close();

	system("Pause");

	return 0;


}


void grade_update(ifstream& student_grades, ofstream& avg_grade, double avg);
{

}

Recommended Answers

All 4 Replies

What part are you confused on? How to implement it or the code to use?

I know how to open and close a file, how to check to see if it opened correctly - things like that

I'm thinking that the new averaged scores have to be appended to the old scores, but I am confused about how to get them to appear on the side of each list. I'm used to my textbook only having things appear underneath the old text, not on its side.

I guess I'm more confused on the code to use.

There are a few ways to do it. One of the easiest would be to use std::stringstream so you should look it up and see if that will help you out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.