RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 1052 | Replies: 1
Join Date: Feb 2007
Posts: 2
Reputation: tatumkay is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tatumkay tatumkay is offline Offline
Newbie Poster

struct functions - lost a wee bit (i hope) in calling the functions

  #1  
Mar 29th, 2007
I cannot figure out how to "call" the functions into the main. Please help!!

 
// ******************************************************************
//
//  Grades.cpp
//
//  This program computes student grades. For each student, two
//  quiz grades (graded on a 10 point basis), one midterm exam grade
//  and one final exam grade (each on a 100 point basis) are read
//  in. The final numeric grade is computed weighing the final 
//  exam 50%, the midterm 25%, and the quizzes 25%. The numeric
//  grade and corresponding letter grade are output.
//
// ******************************************************************
#include <iostream>
using namespace std;                       


//declarations
double quiz1;
double quiz2;
double midtermExam;
double finalExam;
double courseAverage;
//
// Structure for a student record
struct StudentRecord
{
//member functions
int quiz1, quiz2, midtermExam, finalExam, courseAverage, letterGrade;
};

//
//function declarations
void inputRecord (StudentRecord record);
//postcondition 
void computeAverage (StudentRecord& record);
//precondition
char letterGrade (double numericGrade);
//precondition
void outputRecord (StudentRecord record);
//precondition

//
//main function - declares StudentRecord, Calls functions into action
int main()
{
StudentRecord record;
void inputRecord (StudentRecord.record);
void computeAverage (StudentRecord.record);
char letterGrade (double numericGrade);
void outputRecord (StudentRecord.record);
}

//
//input definition
void inputRecord (StudentRecord record)
{ 
  cout << "Please Enter Your Grades Below" << endl << "Quiz Scores: ";
  cin >> quiz1;
  cout << " and "; 
  cin >> quiz2; 
  cout << endl;
  cout << "Midterm Exam Score: ";
  cin >> midtermExam; 
  cout << endl;
  cout << "Final Exam Score: ";
  cin >> finalExam;
  cout << endl;
}

//
// average definition
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 letter grade
  record.letterGrade = letterGrade (record.courseAverage);
} 

//
// letterGrade defintion
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';
  else
    letter = 'A';

  return letter;
}


//output definition
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;
}
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:57 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC