February 20th, 2007, 11:58 PM
|
#1 (permalink)
|
| Senior Member
Join Date: Aug 2004 Location: Virginia Beach, Va
Posts: 603
|
Hey guys, need a little c++ help if it wouldnt be too much trouble. This is for a programming class. Having a little trouble with the end of file loop. I wasnt allowed to use strings or arrays in this program or else it would look a lot cleaner.
The program reads data from a file, inputdata.txt and outputs to outputdata.txt. It reads a series of integers representing a series of grades. For instance, 76 67 83 49 1111111 75 85 70 90, is one final exam, 3 hourlies (lowest gets dropped), 7 homework assignments (1 is pass 0 is fail), and 4 programs. The homeworks have to be read in as char and then converted to ints to calc the homework grade, which is what that business is about.
The thing I cant figure out is how to put an end of file loop so that I can have multiple series of integers so that multiple students can be put in the inputdata file. So could anyone point me in the right direction as to how to set up an EOF loop for this? Code: inputdata >> finalExam; //inputing final exam grade
finalExamPercent = (finalExam * FINAL_WEIGHT) / 100;
hourlyMin = INT_MAX;
inputdata >> hourlyOne;
if (hourlyOne < hourlyMin)
hourlyMin = hourlyOne;
inputdata >> hourlyTwo;
if (hourlyTwo < hourlyMin)
hourlyMin = hourlyTwo;
inputdata >> hourlyThree;
if (hourlyThree < hourlyMin)
hourlyMin = hourlyThree;
hourlySum = (hourlyOne + hourlyTwo + hourlyThree) - hourlyMin;
hourlyPercent = ((hourlySum / (NUM_HOURLIES - 1)) * HOURLY_WEIGHT) / 100;
homeworkSum = 0;
for (count = 1; count <= NUM_HOMEWORK; count++)
{
inputdata >> homeworkChar;
homeworkInt = homeworkChar & ASCII_CONVERT;
homeworkSum = homeworkSum + homeworkInt;
}
if (homeworkSum > (NUM_HOMEWORK - 1))
{
homeworkSum = homeworkSum - 1;
}
homeworkPercent = (float(homeworkSum) / float(NUM_HOMEWORK-1)) * HOMEWORK_WEIGHT;
programSum = 0;
for (count = 1; count <= (NUM_PROGRAMS); count++)
{
inputdata >> program;
programSum = programSum + program;
}
programPercent = ((programSum / MAX_PROGRAM_GRADE) * PROGRAM_WEIGHT);
grade = finalExamPercent + hourlyPercent + homeworkPercent + programPercent;
outputdata << grade << endl; Sorry for the lack of comments 
__________________
"There are only 10 kinds of people in the world, those that can read binary, and those that cannot."
|
| |