Structure program to grading for a class.

Posted on 2005-05-09
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

    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?
    LVL 8

    Accepted Solution

    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;



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now