Help finishing up code?

March 7, 2009 at 15:17:11
Specs: Windows XP
ok the following is an assignment that im having problems with, i cant seem to know how to put more than one student, and overall im stuck!
I'll appreciate any help.

You are processing a class test file called classtest.txt. The file has the format of:

firstname lastname
test1 test2 test3 test4 test5
... (more students follow)

----------------->///////////////the part im stuck on
You should report for each student:

Their name
Each test grade
The average test grade
At the end of the class you should report the total number of student in the class and the class test average to both the screen and a file called classreport.txt

All numbers should line up nicely

validation - test grades range from 0 to 100, do not accept a test grade outside this range.

This is what i have so far. hopelly someone can help me out.

// classtest.cpp

#include <iostream>
using std::ios;
using std::cout;
using std::endl;

#include <fstream>
using std::ifstream;

#include <sstream>
using std::istringstream;

#include <string>
using std::string;

int main(int argc, char *argv[]){

double test1, test2, test3, test4, test5;
double average;
int NumStudents;
string first, last;
string textLine = " ";
ifstream fin(argv[1],ios::in);

istringstream inStream(textLine);

while( (getline(fin,textLine))) {
inStream >> first;

inStream >> last;

inStream >> test1 >> test2 >> test3 >> test4 >> test5;

average = (test1 + test2 + test3 + test4 + test5) / 5.0;

cout << "Student: " << first << " " << last << endl;
cout << "Average grade: " << average << endl << endl;


See More: Help finishing up code?

Report •

March 7, 2009 at 15:26:06
You need to be looking at some kind of loop. You have the basics for one student, now you need to repeat the same for every student.

If you know how many students there are to process then a For Next loop will do. If there is an indeterminate number of students then a While Wend loop will be needed.

The difference is that a For next loop will go through the loop a fixed number of times while a While Wend loop will keep going until a predetermined condition is met, i.e. the end of the file containing the students scores.


Report •

March 7, 2009 at 21:10:22
thats my problem dude i know u have to use a while and a number operator but i dont know how to start it off.

ps. im new in c++ & our instructor handled out this assignment without going over it.

Report •

Related Solutions

Ask Question