oLgAa25 said:
How about This,
why don't you guys stop making fun of people like us. May be if you had
a useful thing to say, then that would be appreciated, but just sitting
down and comparing the blue link to a shoe store, that is not fun. It
is called disrespect.
Yes I saw the blue link last night , and I am not sure what line you
are talking about.
I mean I know that I have to add a line to get the next score, but my
question is where?
you help is appreciated, but your disrespect is not.
Google has single handedly just about ruined Usenet. Much of the
frustration is actually directed at them. They stupidly ignored ten years
of successful usage and said "I have seen the future and here it is". So we
now have Googlenet embedded in Usenet.
This is a copy from Google with my suggested reading mode.
------------ snip ------------
From: osmium - view profile
Date: Tues, Feb 28 2006 7:59 pm
Email: "osmium" <
[email protected]>
Groups: comp.lang.c++
Not yet ratedRating:
show options
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse | Find messages by this author
- Hide quoted text -
- Show quoted text -
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void calculateAverage(ifstream& inFile, double& studentAverage);
char calculateGrade(double studentAvg);
int main()
{
ifstream inFile;// input stream variable
ofstream outFile;
string studentName;
int numberOfStudents = 0;
double studentAvg = 0;
double totalAverage = 0;
double classAverage;
char grade;
double testScore;
inFile.open("c:\\studentFile.txt");
outFile.open("c:\\student_out.txt");
if (!inFile)
{
cout << "Unable to open the file." <<endl;
return 1;
}
outFile << setfill(' ') <<setiosflags(ios:: left) << setw(11) <<
"Student" << setw(10) << "Test1"
<< setw(8) << "Test2" << setw(8) << "Test3" << setw(8) << "Test4"
<< setw(8) << "Test5"
<< setw(8) << "Average" << setw(8) << "Grade" << endl;
while(inFile)
{
outFile.setf(ios::fixed, ios::floatfield);
outFile.setf(ios::showpoint);
outFile << setprecision(2);
inFile >> studentName;
inFile >> testScore;
What is the purpose of that line? To read the first test score? In a
moment you are going to tell calculate average to read the test scores.
Files are like miniature tape players. If you go forward, you have to
rewind (or at least reposition) if you want to hear something again. I'm
sure there is a lot more to be found but that is the first thing I noticed.
------------- end snip----------------
"that line" refers to the line immediately above the point where I inserted
my comment. The one that says
inFile >> testScore;
I believe the assignment is worded such that a non-ugly solution can not be
made. You are forbidden to use the function calculate average (whatever the
formal name is ) as a function, i.e., you are directed to return a void. IMO
it should return a bool, indicating whether EOF was detected or not. Then,
most of the logic could be done in the calculate function. The reading of
the file, capturing the needed data, and writing the output file. It
returns to the caller (main) whether it was successful or not and the
numeric score for the most recent student. main would be almost empty, it
would open and close the two files, aggregate the cumulative class score and
keep track of how many are in the class. After the last student is
processed it would compute and print the class average. Reading of the
students name and the five scores would all be done in the calculate average
function. The best workaround I see is this prototype:
void calculateAverage(ifstream& in, ofstream& out, double& numeric_score,
bool& success);
The last parameter passes the EOF information back to the caller despite the
straight jacket you instructor has put you in.
Note that you do not need names for five test scores *or* an array of test
scores.