IO stream

O

oLgAa25

How do I go to DrNoose? I don't know how?
I don't know how
Thank you
and no,we don't share codes, but my code has been on the net, so may be
someone else took it.
and I don't see Kathy in my class list.
and again, my code compiles with no errors, . But here is my problem,
I don't know where I went wrong.
yes you got me angry, I have ignored my kids on Saturday and Sunday to
write the code, and then I don't get credit for it,even if it wasn't
working

C:\Documents and Settings\Owner\Desktop\COP_2334\AvgTestScore.cpp
compiled successfully
 
B

BobR

oLgAa25 wrote in message
one more thing,
how do I get to that group. ;-)
it would be nice to find out how,

and apologies accepted;-)

Oooops! I 'slashed' where I should have 'dashed'!


I don't know Mozilla, but, you should be able to paste the above into Google
as a last resort.
However you got here, you should be able to get there. <G>
(assuming your ISP carries that NG)
 
O

oLgAa25

This is more frustrating than solving my problem.
I got there, but then I have to set up my outlook, which I don' know
how. I need to set it up.
 
O

oLgAa25

Ok here is the latest with me,
I have listed again the program
it compiles fine, but when I run it, I get this output

Student Test1 Test2 Test3 Test4 Test5 Average Grade
Balto85.00 85.00 85.00 85.00 85.00 0.00 F
7791.00 91.00 91.00 91.00 91.00 0.00 F
Mickey80.00 80.00 80.00 80.00 80.00 0.00 F
9593.00 93.00 93.00 93.00 93.00 0.00 F
Minnie79.00 79.00 79.00 79.00 79.00 0.00 F
1190.00 90.00 90.00 90.00 90.00 0.00 F
Doc92.00 92.00 92.00 92.00 92.00 0.00 F
3069.00 69.00 69.00 69.00 69.00 0.00 F
Goofy23.00 23.00 23.00 23.00 23.00 0.00 F
9638.00 38.00 38.00 38.00 38.00 0.00 F
Duckey60.00 60.00 60.00 60.00 60.00 0.00 F
4539.00 39.00 39.00 39.00 39.00 0.00 F
Grumby27.00 27.00 27.00 27.00 27.00 0.00 F
5274.00 74.00 74.00 74.00 74.00 0.00 F
Sunny93.00 93.00 93.00 93.00 93.00 0.00 F
8977.00 77.00 77.00 77.00 77.00 0.00 F
Piggy79.00 79.00 79.00 79.00 79.00 0.00 F
2893.00 93.00 93.00 93.00 93.00 0.00 F
Pluto85.00 85.00 85.00 85.00 85.00 0.00 F
4975.00 75.00 75.00 75.00 75.00 0.00 F
4975.00 75.00 75.00 75.00 75.00 0.00 F
average 0.00
4975.00 75.00 75.00 75.00 75.00 0.00 F

while my output shouldn't be that way,

It should be as follows
Student Test1 Test2 Test3 Test4 Test5 Average Grade
Balto 85 83 77 91 76
Mickey 80 90 95 93 48
Minnie 79 81 11 90 73
Doc 92 83 30 69 87
Goofy 23 45 96 38 59
Duckey 60 85 45 39 67
Grumby 27 31 52 74 83
Sunny 93 94 89 77 97
Piggy 79 85 28 93 82
Pluto 85 72 49 75 63

classAverage =

I know I missing up a loop somewhere, but I have no idea where.
My brain is dead
//*********************************************************************************
// Write a program that reads a student's name together with his or her
test *
// scores. The program should then compute the average test score for
each student*
// and assign the appropriate grade. The grade scale is as follows:
*
// 90-100, A; 80-89, B ; 70-79, C; 60-69, D; 0-59, F.
*
// Your program must use the following functions:
*
//
*
//a. A void function, calculateAverage, to determine the average of the
five *
// test score for each student. Use a loop to read and sum the five
test score *
// This function doesn't output the average test score. That task
must be done *
// in the function main)
*
//
*
// b. A value return function, calculateGrade, to determine and return
each *
// student's grade. This function doesn't output the grade. That
task must be *
// done in the function main)
*
//*******************************************************************************
*

#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;
calculateAverage(inFile, studentAvg);
grade = calculateGrade(studentAvg);
totalAverage = totalAverage + studentAvg;

outFile << setfill(' ') << setiosflags(ios::left) << setw(11) <<
studentName << setw (10) << testScore
<< setw(8) << testScore << setw(8) << testScore << setw(8) <<
testScore <<
setw(8) << testScore
<< setw(9) << studentAvg << setw(8) << grade<<endl;

numberOfStudents++;
}
classAverage = totalAverage / numberOfStudents;
outFile << "average" << classAverage <<endl;

outFile << setfill(' ') << setiosflags(ios::left) << setw(11) <<
studentName << setw (10) << testScore << setw(8) << testScore <<
setw(8) << testScore << setw(8) << testScore <<
setw(8) << testScore << setw(9) << studentAvg << setw(8) <<
grade<<endl;
inFile.close();
outFile.close();
system("PAUSE");
return 0;


}

void calculateAverage(ifstream& inFile, double& studentAverage)
{
double totalScore = 0;
int numberOfTests;

int testScore;

inFile >> testScore;
while(numberOfTests <= 5)
{
totalScore = totalScore + testScore;
numberOfTests++;

inFile >> testScore;
}
studentAverage = ( totalScore / numberOfTests);
}

char calculateGrade(double studentAverage)
{

char grade;

if (studentAverage <= 100 && studentAverage >= 90)
grade = 'A';
else if (studentAverage < 90 && studentAverage >= 80)
grade = 'B';
else if (studentAverage < 80 && studentAverage >= 70)
grade = 'C';
else if (studentAverage < 70 && studentAverage >= 60)
grade = 'D';
else if (studentAverage < 60 && studentAverage >= 0)
grade = 'F';
else
cout << "Invalid grade " << endl;

return grade;

}
 
O

oLgAa25

BobR said:
oLgAa25 wrote in message


Oooops! I 'slashed' where I should have 'dashed'!


I don't know Mozilla, but, you should be able to paste the above into Google
as a last resort.
However you got here, you should be able to get there. <G>
(assuming your ISP carries that NG)
 
O

osmium

oLgAa25 said:
Ok here is the latest with me,
I have listed again the program
it compiles fine, but when I run it, I get this output

Student Test1 Test2 Test3 Test4 Test5 Average Grade
Balto85.00 85.00 85.00 85.00 85.00 0.00 F
7791.00 91.00 91.00 91.00 91.00 0.00 F
Mickey80.00 80.00 80.00 80.00 80.00 0.00 F
9593.00 93.00 93.00 93.00 93.00 0.00 F
Minnie79.00 79.00 79.00 79.00 79.00 0.00 F
1190.00 90.00 90.00 90.00 90.00 0.00 F
Doc92.00 92.00 92.00 92.00 92.00 0.00 F
3069.00 69.00 69.00 69.00 69.00 0.00 F
Goofy23.00 23.00 23.00 23.00 23.00 0.00 F
9638.00 38.00 38.00 38.00 38.00 0.00 F
Duckey60.00 60.00 60.00 60.00 60.00 0.00 F
4539.00 39.00 39.00 39.00 39.00 0.00 F
Grumby27.00 27.00 27.00 27.00 27.00 0.00 F
5274.00 74.00 74.00 74.00 74.00 0.00 F
Sunny93.00 93.00 93.00 93.00 93.00 0.00 F
8977.00 77.00 77.00 77.00 77.00 0.00 F
Piggy79.00 79.00 79.00 79.00 79.00 0.00 F
2893.00 93.00 93.00 93.00 93.00 0.00 F
Pluto85.00 85.00 85.00 85.00 85.00 0.00 F
4975.00 75.00 75.00 75.00 75.00 0.00 F
4975.00 75.00 75.00 75.00 75.00 0.00 F
average 0.00
4975.00 75.00 75.00 75.00 75.00 0.00 F

while my output shouldn't be that way,

It should be as follows
Student Test1 Test2 Test3 Test4 Test5 Average Grade
Balto 85 83 77 91 76
Mickey 80 90 95 93 48
Minnie 79 81 11 90 73
Doc 92 83 30 69 87
Goofy 23 45 96 38 59
Duckey 60 85 45 39 67
Grumby 27 31 52 74 83
Sunny 93 94 89 77 97
Piggy 79 85 28 93 82
Pluto 85 72 49 75 63

classAverage =

I know I missing up a loop somewhere, but I have no idea where.
My brain is dead
//*********************************************************************************
// Write a program that reads a student's name together with his or her
test *
// scores. The program should then compute the average test score for
each student*
// and assign the appropriate grade. The grade scale is as follows:
*
// 90-100, A; 80-89, B ; 70-79, C; 60-69, D; 0-59, F.
*
// Your program must use the following functions:
*
//
*
//a. A void function, calculateAverage, to determine the average of the
five *
// test score for each student. Use a loop to read and sum the five
test score *
// This function doesn't output the average test score. That task
must be done *
// in the function main)
*
//
*
// b. A value return function, calculateGrade, to determine and return
each *
// student's grade. This function doesn't output the grade. That
task must be *
// done in the function main)
*
//*******************************************************************************
*

#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.
 
O

osmium

oLgAa25 said:
what line?

Do you see a blue line that says "Show quoted text"?

That is not an advisement for a shoe store. It is something to press to
make that idiotic interface semi-useful.
 
O

oLgAa25

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.
 
O

osmium

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.
 
O

osmium

Olga wrote:

I just re-read you post.

The point was to read all five scores in one place. You seems to be reading
one score here and then five more later on. But there are only five scores,
not six.
 
O

oLgAa25

so basically, I will have to change my calculateAverage Function,
hmmm

I have changed the test scores names, I am no longer taking 5 test
scores, I am just doing a loop in the CalculateAverage Function

and thank you again for the input.Although I don't understand what you
said exactly about Google ;-) but for now I will live with that.

Olga
 
O

osmium

oLgAa25 said:
so basically, I will have to change my calculateAverage Function,
hmmm

No, you don't *have* to. I am just saying it is plug ugly to read the
student name in one function and read the scores in another function. A
student *record* is a student's name and his five test scores. I prefer to
concentrate responsibility in one place. You can patch up what you have
and continue if you prefer. I realize the clock is running....
 
D

Daniel T.

"oLgAa25 said:
Hello again,
I am back with Good and bad news.
The good news is: it compiles and no errors;-)
the bad news is the output is not what we are expected to do.
so helppppppppppp please
Olga

Olga, you still have the same problem. You are trying to extract 7
testscores for each student, but they only each have 5. You extract one
in main right after reading the students name, then you go into
calculateAverage where you go through a loop 6 times (0, 1, 2, 3, 4, 5)
is 6 iterations.
 
O

oLgAa25

Ok this is it for me, I am going Nutssss.... here. I don't know what I
am doing wrong any more
I started out by having a problem with my output coming out in bad
way, and now I am back to no where :(

I don't know what else to do

Thank you all for the help
 
B

Ben Pope

oLgAa25 said:
Ok this is it for me, I am going Nutssss.... here. I don't know what I
am doing wrong any more
I started out by having a problem with my output coming out in bad
way, and now I am back to no where :(

I don't know what else to do

Have you learnt how to use your debugger yet?

Ben Pope
 
O

oLgAa25

Guys, do you get paid, or do you that because you like helping people
like me?
because you do a good job, and I realy appreciate that.

Olga
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Chatbot 0
Linker Error Help!! 2
setfill('\t') 5
NullPointerException error 3
Questions about new range for 2
clearing contents of ostringstream object 4
C++ help 3
Little help please 7

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top