C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 26th, 2005, 06:59 PM
saifo saifo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 6 saifo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 8 sec
Reputation Power: 0
c++ Help

Write a program that reads the student id and an exam score for five students. The
program must compute the average, maximum, and minimum of the five exam scores,
as well as a class performance level. The program must generate a report as shown
below. The class performance level is GOOD if the average score is at least 80,
POOR if the average score is less than 60, otherwise it is MEDIUM.
SEQ NO ID NO SCORE
----------- ----------- ----------
1. 123492 85.00
2. 567893 95.00
3. 901291 64.50
4. 634528 74.00
5. 859245 87.50
-------------------------------------------------------------------------------------
AVERAGE SCORE: 81.20
MAXIMUM SCORE: 95.00
MINIMUM SCORE: 64.50
CLASS LEVEL: GOOD

Reply With Quote
  #2  
Old September 27th, 2005, 05:06 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Looks like you're having other people do your homework for you.

And damn easy homework too:

c Code:
Original - c Code
  1. #include <stdio.h>
  2. /*
  3. Write a program that reads the student id and an exam score for five students. The
  4. program must compute the average, maximum, and minimum of the five exam scores,
  5. as well as a class performance level. The program must generate a report as shown
  6. below. The class performance level is GOOD if the average score is at least 80,
  7. POOR if the average score is less than 60, otherwise it is MEDIUM.
  8. SEQ NO ID NO SCORE
  9. ----------- ----------- ----------
  10. 1. 123492 85.00
  11. 2. 567893 95.00
  12. 3. 901291 64.50
  13. 4. 634528 74.00
  14. 5. 859245 87.50
  15. -------------------------------------------------------------------------------------
  16. AVERAGE SCORE: 81.20
  17. MAXIMUM SCORE: 95.00
  18. MINIMUM SCORE: 64.50
  19. CLASS LEVEL: GOOD
  20. */
  21.  
  22. int main(void)
  23. {
  24.         // declarations
  25.         unsigned int i, student[5];
  26.         float grade[5], total, max, min;
  27.         FILE *fp;
  28.  
  29.         // read file
  30.         fp = fopen("input.txt", "r");
  31.         for(i = 0; i < 5; i++)
  32.                 fscanf(fp, "%*c. %u %f\n", &student[i], &grade[i]);
  33.         fclose(fp);
  34.  
  35.         // calculate results
  36.         total = 0.0;
  37.         max = 0.0;
  38.         min = 999.0;
  39.         for(i = 0; i < 5; i++)
  40.         {
  41.                 total += grade[i];
  42.                 if(grade[i] < min)
  43.                         min = grade[i];
  44.                 if(grade[i] > max)
  45.                         max = grade[i];
  46.         }
  47.         total /= 5.0;
  48.  
  49.         // output results
  50.         for(i = 0; i < 5; i++)
  51.                 printf("%u. %u %.2f\n", (i+1), student[i], grade[i]);
  52.         printf("AVERAGE SCORE: %.2f\n", total);
  53.         printf("MAXIMUM SCORE: %.2f\n", max);
  54.         printf("MINIMUM SCORE: %.2f\n", min);
  55.         printf("CLASS LEVEL: %s\n", (total > 80 ? "GOOD" : (total < 60 ? "POOR" : "MEDIUM")));
  56.  
  57.         // exit
  58.         return 0;
  59. }
Comments on this post
MichaelSoft agrees: You've done your homework well Itsacon ;-)
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 280

Last edited by Itsacon : September 27th, 2005 at 10:27 AM.

Reply With Quote
  #3  
Old September 27th, 2005, 05:17 AM
MichaelSoft MichaelSoft is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The Netherlands
Posts: 121 MichaelSoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 20 sec
Reputation Power: 4
Ehhh ... you want us to write a program for you???
Guess again :-s

Reply With Quote
  #4  
Old September 27th, 2005, 05:20 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Could've been shorter, but his teachers would never believe him

Reply With Quote
  #5  
Old September 27th, 2005, 05:42 AM
saifo saifo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 6 saifo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 31 m 8 sec
Reputation Power: 0
thanks Itsacon
i asked u to help me
because i'm beginner
to the world of programming
did u know oman?

Reply With Quote
  #6  
Old September 27th, 2005, 06:02 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Here's the shorter, unreadable version

c Code:
Original - c Code
  1. #include <stdio.h>
  2. #define min(a,b) (((a)<(b))?(a):(b))
  3. #define max(a,b) (((a)>(b))?(a):(b))
  4.  
  5. int main(void)
  6. {
  7.     // declarations
  8.     unsigned int i, student;
  9.     float grade, total, maxi, mini;
  10.     FILE *fp;
  11.  
  12.     // do stuff      -> bad comments! DO NOT TRY THIS AT HOME!
  13.     fp = fopen("input.txt", "r");
  14.     for(i = 0, total = 0.0, maxi = 0.0, mini = 999.0; i < 5; i++, total += grade, mini = min(mini, grade), maxi = max(maxi, grade))
  15.     {
  16.         fscanf(fp, "%*c. %u %f\n", &student, &grade);
  17.         printf("%u. %u %.2f\n", (i+1), student, grade);
  18.     }
  19.     fclose(fp);
  20.     printf("AVERAGE SCORE: %.2f\nMAXIMUM SCORE: %.2f\nMINIMUM SCORE: %.2f\nCLASS LEVEL: %s\n", total / 5.0, maxi, mini, (total > 400 ? "GOOD" : (total < 300 ? "POOR" : "MEDIUM")));
  21.  
  22.     // exit
  23.     return 0;
  24. }

Last edited by Itsacon : September 27th, 2005 at 10:28 AM. Reason: typo...

Reply With Quote
  #7  
Old September 27th, 2005, 04:12 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
Quote:
// do stuff -> bad comments! DO NOT TRY THIS AT HOME!

If he actually turns in that code......
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips.



Reply With Quote
  #8  
Old September 28th, 2005, 06:14 AM
MichaelSoft MichaelSoft is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The Netherlands
Posts: 121 MichaelSoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 20 sec
Reputation Power: 4
Quote:
Originally Posted by Itsacon
for(i = 0, total = 0.0, maxi = 0.0, mini = 999.0; i < 5; i++, total += grade, mini = min(mini, grade), maxi = max(maxi, grade))

Cool looping here. I guess you could make this a 'one-liner' piece of code.

Reply With Quote
  #9  
Old September 28th, 2005, 06:32 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Yeah, but scanf's and printf's in a for-loop condition REALLY make for unreadable code... Even I have limits, unless I'd be participating in the IOCCC

Reply With Quote
  #10  
Old September 28th, 2005, 01:05 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 200