By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,068 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,068 IT Pros & Developers. It's quick & easy.

grades.cpp errors and otherwise lost

P: 2
I really just need some pointers... jumping points from here... something

the problem:

Write a grading program for a class with the following grading policies:

1. There are two quizzes, each graded on the basis of 10 points.
2. There is one midterm exam and one final exam, each graded on the basis of 100 points.
3. The final exam counts for 50% of the grade, the midterm counts for 25%, and the two quizzes together count for a total of 25%. (Do not forget to normalize the quiz scores. They should be converted to percent before they are averaged in.)

Any grade of 90 or more is an A, any grade of 80 or more (but less than 90) is a B, any grade of 70 or more (but less than 80) is a C, any grade of 60 or more (but less than 70) is a D, and any grade below 60 is an F. The program will read in the student's scores and output the student's record, which consists of two quiz and two exam scores as well as the student's average numeric score for the entire course and the final letter grade. Define and use a structure for the student record.


the code so far:
Expand|Select|Wrap|Line Numbers
  1. // ******************************************************************
  2. //
  3. //  Grades.cpp
  4. //
  5. //  This program computes student grades. For each student, two
  6. //  quiz grades (graded on a 10 point basis), one midterm exam grade
  7. //  and one final exam grade (each on a 100 point basis) are read
  8. //  in. The final numeric grade is computed weighing the final 
  9. //  exam 50%, the midterm 25%, and the quizzes 25%. The numeric
  10. //  grade and corresponding letter grade are output.
  11. //
  12. // ******************************************************************
  13. #include <iostream>
  14. #include <math.h>
  15. #include <string>
  16. #include <stdlib.h>
  17. using namespace std;                       
  18.  
  19.  
  20. // 
  21. // Structure for a student record
  22. //
  23. double quiz1;
  24. double quiz2;
  25. double midtermExam;
  26. double finalExam;
  27. double courseAverage;
  28.  
  29. struct StudentRecord
  30. {
  31. int quiz1, quiz2, midtermExam, finalExam, courseAverage, letterGrade;
  32. };
  33.  
  34. int main()
  35. {
  36.   cout >> "Please Enter Your Grades Below" >> endl
  37.        >> "Quiz Scores: ";
  38.   cin << quiz1;
  39.   cout >>"and"; 
  40.   cin << quiz2 << endl;
  41.   cout >> "Midterm Exam Score: ";
  42.   cin << midtermExam << endl;
  43.   cout >> "Final Exam Score: ";
  44.   cin << finalExam;
  45. }
  46.  
  47. char letterGrade (double numericGrade)
  48. {
  49.   char letter;
  50.  
  51.   if (numericGrade < 60)
  52.     letter = 'F';
  53.   else if (numericGrade < 70)
  54.     letter = 'D';
  55.   else if (numericGrade < 80)
  56.     letter = 'C';
  57.   else if (numericGrade < 90)
  58.     letter = 'B';
  59.   else
  60.     letter = 'A';
  61.  
  62.   return letter;
  63. }
  64.  
  65.  
  66. void outputRecord (StudentRecord record)
  67. {
  68.   cout << endl;
  69.   cout << "Quiz Scores: " << record.quiz1 << "  " << record.quiz2 << endl;
  70.   cout << "Midterm Exam Score: " << record.midtermExam << endl;
  71.   cout << "Final Exam Score: " << record.finalExam << endl;
  72.   cout << endl;
  73.   cout << "Course Average: " << record.courseAverage << endl;
  74.   cout << "Final Letter Grade: " << record.letterGrade << endl;
  75.   cout << endl;
  76. }
  77.  
  78.  
  79. void computeAverage (StudentRecord& record)
  80. {
  81.   const double EXAM_WT = 0.5;
  82.   const double MIDTERM_WT = 0.25;
  83.   const double QUIZ_WT = 0.25;
  84.   double quiz1Percent, quiz2Percent;
  85.  
  86.   //
  87.   // Convert the 10 point quizzes to a percent, then find the average
  88.   //
  89.   quiz1Percent = 100 * record.quiz1 / 10.0;
  90.   quiz2Percent = 100 * record.quiz2 / 10.0;
  91.   double quizAvg = (quiz1Percent + quiz2Percent) / 2;
  92.  
  93.   //
  94.   // Compute the weighted average to get the numeric course grade
  95.   // 
  96.   record.courseAverage = quizAvg * QUIZ_WT + record.midtermExam * MIDTERM_WT + 
  97.   record.finalExam * EXAM_WT;
  98.  
  99.   //
  100.   // Call the letterGrade function to find the corresponding letter grade
  101.   record.letterGrade = letterGrade (record.courseAverage);
  102.  
  103. }
  104.  
  105.  
Mar 28 '07 #1
Share this Question
Share on Google+
2 Replies


P: 7
Hey. I know what it is like being lost. So here are some pointers. I am not an expert, but rather a newby myself, so please forgive my c++ vocabulary. Anyhow, I think the only header you really need to include is the <iostream>. The other header files are not used in your program. Next you define quiz1, quiz2, etc in two places. The first place the variables are declared they are a double type. The second place they are declared is in the struct student as an int type. The program compiles as listed below with the few minor corrections i mentioned above, but your main function does not invoke the additional functions you have written. Also, if you will need to decide if you are going to use the struct method or the standard variable methods to run your program, once you have decided you will need to implement it throughout your main and other functions (now, you have some functions that use variables, and some functions that are using the struct [which has never been instansiated]).
Expand|Select|Wrap|Line Numbers
  1. // **************************************************  ****************
  2. //
  3. //  Grades.cpp
  4. //
  5. //  This program computes student grades. For each student, two
  6. //  quiz grades (graded on a 10 point basis), one midterm exam grade
  7. //  and one final exam grade (each on a 100 point basis) are read
  8. //  in. The final numeric grade is computed weighing the final 
  9. //  exam 50%, the midterm 25%, and the quizzes 25%. The numeric
  10. //  grade and corresponding letter grade are output.
  11. //
  12. // **************************************************  ****************
  13. #include <iostream>
  14. //#include <math.h>  ...not needed
  15. //#include <string>  ...not needed
  16. //#include <stdlib.h>...not needed
  17. using namespace std;                       
  18.  
  19.  
  20. // 
  21. // Structure for a student record
  22. //
  23. double quiz1;
  24. double quiz2;
  25. double midtermExam;
  26. double finalExam;
  27. double courseAverage;
  28.  
  29. struct StudentRecord
  30. {
  31. int quiz1, quiz2, midtermExam, finalExam, courseAverage, letterGrade;
  32. };
  33.  
  34. int main()
  35. {
  36.   //stream insertion operators were reversed for cout and cin functions
  37.   cout << "Please Enter Your Grades Below" << endl << "Quiz Scores: ";
  38.   cin >> quiz1;
  39.   cout << " and "; 
  40.   //i believe that endl is to be used with cout not cin
  41.   cin >> quiz2; 
  42.   cout << endl;
  43.   cout << "Midterm Exam Score: ";
  44.   //i believe that endl is to be used with cout not cin
  45.   cin >> midtermExam; 
  46.   cout << endl;
  47.   cout << "Final Exam Score: ";
  48.   cin >> finalExam;
  49.   cout << endl;
  50. }
  51.  
  52. char letterGrade (double numericGrade)
  53. {
  54.   char letter;
  55.  
  56.   if (numericGrade < 60)
  57.     letter = 'F';
  58.   else if (numericGrade < 70)
  59.     letter = 'D';
  60.   else if (numericGrade < 80)
  61.     letter = 'C';
  62.   else if (numericGrade < 90)
  63.     letter = 'B';
  64.   else
  65.     letter = 'A';
  66.  
  67.   return letter;
  68. }
  69.  
  70.  
  71. void outputRecord (StudentRecord record)
  72. {
  73.   cout << endl;
  74.   cout << "Quiz Scores: " << record.quiz1 << "  " << record.quiz2 << endl;
  75.   cout << "Midterm Exam Score: " << record.midtermExam << endl;
  76.   cout << "Final Exam Score: " << record.finalExam << endl;
  77.   cout << endl;
  78.   cout << "Course Average: " << record.courseAverage << endl;
  79.   cout << "Final Letter Grade: " << record.letterGrade << endl;
  80.   cout << endl;
  81. }
  82.  
  83.  
  84. void computeAverage (StudentRecord& record)
  85. {
  86.   const double EXAM_WT = 0.5;
  87.   const double MIDTERM_WT = 0.25;
  88.   const double QUIZ_WT = 0.25;
  89.   double quiz1Percent, quiz2Percent;
  90.  
  91.   //
  92.   // Convert the 10 point quizzes to a percent, then find the average
  93.   //
  94.   quiz1Percent = 100 * record.quiz1 / 10.0;
  95.   quiz2Percent = 100 * record.quiz2 / 10.0;
  96.   double quizAvg = (quiz1Percent + quiz2Percent) / 2;
  97.  
  98.   //
  99.   // Compute the weighted average to get the numeric course grade
  100.   // 
  101.   record.courseAverage = quizAvg * QUIZ_WT + record.midtermExam * MIDTERM_WT + 
  102.   record.finalExam * EXAM_WT;
  103.  
  104.   //
  105.   // Call the letterGrade function to find the corresponding letter grade
  106.   record.letterGrade = letterGrade (record.courseAverage);
  107.  
  108. }
  109.  
Like I said, this code should compile. But the only thing your main function is getting is the grades. It doesn't actually use any of your other functions to perform the rest of the required tasks.

I hope this helps.
Mar 29 '07 #2

P: 2
hey, thank you so much.... this got me going in the right direction... i ended up just staring at this code for the longest i knew i needed other input to see the mistakes cause wow... i was bass ackwards... now to figure out how to get struct functions into the main function..

thank you!!
Mar 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.