home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

c++ help

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1574
Discussions: 200,933, Posts: 2,379,175, Members: 246,298
Old February 20th, 2007, 11:58 PM   Digg it!   #1 (permalink)
Senior Member
 
BattleToad's Avatar
 
Join Date: Aug 2004
Location: Virginia Beach, Va
Posts: 603
Send a message via AIM to BattleToad
c++ help

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."
BattleToad is offline   Reply With Quote
Old February 21st, 2007, 12:20 AM     #2 (permalink)
Vyx
Ultimate Member
 
Vyx's Avatar
 
Join Date: May 2003
Location: Cheyenne, WY
Posts: 1,087
Send a message via AIM to Vyx Send a message via MSN to Vyx Send a message via Skype™ to Vyx
I'm not sure if this is what you looking for but couldn't you just wrap the whole whole section of code that gets the inputs, does the calculations, and outputs in an eof loop ie.
Code:
while (! inputdata.eof())
{
   code
}
__________________
Gi | Yuu | Jin | Rei | Makoto | Meiyo | Chuugi
Vyx is offline   Reply With Quote
Old February 21st, 2007, 12:24 AM     #3 (permalink)
Senior Member
 
BattleToad's Avatar
 
Join Date: Aug 2004
Location: Virginia Beach, Va
Posts: 603
Send a message via AIM to BattleToad
I could kiss you. Thats all I needed to know, the book for this class is rather limited and EOF loops are covered in a single paragraph, which doesnt mention that bit of code at all. Thanks for the help.
BattleToad is offline   Reply With Quote
Old February 21st, 2007, 12:26 AM     #4 (permalink)
Vyx
Ultimate Member
 
Vyx's Avatar
 
Join Date: May 2003
Location: Cheyenne, WY
Posts: 1,087
Send a message via AIM to Vyx Send a message via MSN to Vyx Send a message via Skype™ to Vyx
Np lol, glad I could help. It's usually me thats asking for the help
Vyx is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2878)
Obama the Muslim (14)
California Passes Anti-Flat-HDTV Le.. (39)
Is the PSU I received dead? (10)
windows vista security holes (9)
Install XP pro and a Vista laptop ?.. (11)
HIS HD5770 graphic card question (15)
Print spooler problem (13)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
A good PSU? (10)
EVGA 9800 gtx help with finding a g.. (8)
New Computer wont recognize XP disc (7)
Ideal cheap graph card for PC-Gamin.. (17)
Recent Discussions
CPU fan stops spinning randomly (1)
Wireless Televisions. (1)
Ideal cheap graph card for PC-Gaming? (17)
BIOS won't read disk when I try to fl.. (0)
Install XP pro and a Vista laptop ?? (11)
Partition Magic caused HDD problem (2)
Graphics Card Upgrade Question (1)
favorit (1)
solutions for virtical white lines on.. (1)
Regular Build (3)
Fire in DVD (2)
Modern Warfare For the PC (33)
radeon x850xt platinum & shader 3 (3)
Have you switched yet? (84)
Wireless Router+Cable Modems and Much.. (0)
Optical Audio A-B Switch (1)
windows vista security holes (9)
The NTDVM CPU has encountered an ille.. (24)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (34)
Wireless speakers for PC? (11)
Print spooler problem (13)
Help getting around port 80 for camer.. (2)
Display shows 3x5 inch in middle of s.. (3)
monitor will not turn on at all, (1)
World's largest Monopoly Game using G.. (331)


All times are GMT -4. The time now is 09:05 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28