[Last Call] Learn how to a build a cloud-first strategyRegister Now


Structure program to grading for a class.

Posted on 2005-05-09
Medium Priority
Last Modified: 2007-12-19
Write a grading program for a class with the following grading policies;
there are two quizzes, each graded on the basic of 10 point
thre is one midterm exam and one final exam, each graded on the basis of 100 points
the final exam counts for 50% of the grade, the mideterm counts for 25% and two quizzes together count for total 25%.

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

#include <iostream>

using namespace std;

void outputRecord (StudentRecord record)
  cout << endl;
  cout << "Quiz Scores: " << record.quiz1 << "  " << record.quiz2 << endl;
  cout << "Midterm Exam Score: " << record.midtermExam << endl;
  cout << "Final Exam Score: " << record.finalExam << endl;
  cout << endl;
  cout << "Course Average: " << record.courseAverage << endl;
  cout << "Final Letter Grade: " << record.letterGrade << endl;
  cout << endl;

void computeAverage (StudentRecord& record)
  const double EXAM_WT = 0.5;
  const double MIDTERM_WT = 0.25;
  const double QUIZ_WT = 0.25;
  double quiz1Percent, quiz2Percent;

  // Convert the 10 point quizzes to a percent, then find the average
  quiz1Percent = 100 * record.quiz1 / 10.0;
  quiz2Percent = 100 * record.quiz2 / 10.0;
  double quizAvg = (quiz1Percent + quiz2Percent) / 2;

  // Compute the weighted average to get the numeric course grade
  record.courseAverage = quizAvg * QUIZ_WT + record.midtermExam * MIDTERM_WT +
    record.finalExam * EXAM_WT;

  // Call the letterGrade function to find the corresponding letter grade
  record.letterGrade = letterGrade (record.courseAverage);


char letterGrade (double numericGrade)
  char letter;

  if (numericGrade < 60)
    letter = 'F';
  else if (numericGrade < 70)
    letter = 'D';
  else if (numericGrade < 80)
    letter = 'C';
  else if (numericGrade < 90)
    letter = 'B';
    letter = 'A';

  return letter;

I dont know this is right or not, someone help me to figure it out.
Question by:cuong5985
LVL 11

Expert Comment

ID: 13963345
Well, you seem to be missing a "main" function, and there is no definition for "StudentRecord", but you may have just left that out.  The rest doesn't look problematic.

Is there any reason why you don't just run it and see if it works?

Accepted Solution

novitiate earned 400 total points
ID: 13966486
like KurtVon said every thing seems to be ok. Some optimization can be done, but its not that significant. What exactly are you looking for.

Besides I suggest you change the signature of void outputRecord (StudentRecord record) to void outputRecord (const StudentRecord & record)
overload << operator
ostream & operator <<(ostream & os , StudentRecord & record)
  os << endl;
  os << "Quiz Scores: " << record.quiz1 << "  " << record.quiz2 << endl;
  os << "Midterm Exam Score: " << record.midtermExam << endl;
  os << "Final Exam Score: " << record.finalExam << endl;
  os << endl;
  os << "Course Average: " << record.courseAverage << endl;
  os << "Final Letter Grade: " << record.letterGrade << endl;
  os << endl;
  return os;



Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question