1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/*************
Program: Asg_14.cpp
Author: Alan P. Matie
Date: 03 May 2009
Description:
Assignment 14 - Grade program with functions. This is the last program assignment!
We are now at the end of the semester, so you can complete work with your grade program.
As of week 15 (4/27), you will have completed
· 13 labs (maximum 65 points)
· 12 assignments includes introduction discussion (185 points)
· 4 quizzes and 1 exam (162 points)
Labs and assignments are worth 40% of your grade, while exams and quizzes
are worth 60%.
Design a program to input your name, plus the total points to date of your labs,
assignments, and quiz/exam grades.
· Then determine your grade with the weights above.
· For input use these codes: (L/l for labs, A/a for assignments,
E/e for quiz/exam, X/x for stopping).
· The total points to date and percentages should be constants.
· The output will be your overall numeric grade expressed as a percent
and your letter grade based on the common scale (60, 70,,,,,).
· Use a while loop with X/x as the value for the code to end the loop.
o The loop must contain only functions!
Functions must be of the proper type and pass by value or reference as appropriate.
There must be functions for all tasks (input, processes, and output) or the
program will earn a grade of zero.
New Concepts:
Challenges:
Last Modified:
**************/
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
// Declare constants
const double POSSIBLE_LAB = 65;
const double POSSIBLE_ASG = 185;
const double POSSIBLE_EXAM = 162;
const double ASGPCT = 0.40;
const double LABPCT = 0.40;
const double EXAMPCT = 0.60;
// Function Prototypes
void welcome();
void get_name(string& first_name, string& last_name);
void input_code(char& grade_code);
void printGrade(string first_name, string last_name, double numGrade, char letterGrade);
void get_grade(double asgGrade, double labGrade, double examGrade, char grade_code);
double calcGrade(double labScore, double asgScore, double examScore, double asgGrade, double labGrade, double examGrade, double numGrade);
void calcLetter(double numGrade, char letterGrade);
int main()
{
// Declare variables below here
string first_name, last_name;
char letterGrade, grade_code;
double numGrade, labGrade, examGrade, labScore, asgGrade;
double asgScore, examScore;
// Initialization Section for real number output. DO NOT MOVE!
cout <<setiosflags(ios::fixed | ios::showpoint);
cout <<setprecision(2);
// Begin your "main processing" below here
welcome();
get_name(first_name, last_name);
while (toupper(grade_code != 'X'))
{
input_code(grade_code);
}
calcGrade(asgScore, labScore, examScore, asgGrade, labGrade, examGrade, numGrade);
printGrade(first_name, last_name, numGrade, letterGrade);
return 0;
}
// function definitions below here
void welcome()
{
cout <<"Welcome to your Personal Grading Program!"<<endl<<endl;
}
void get_name(string& first_name, string& last_name)
{
cout <<"Please enter your name"<<endl;
cin >>first_name >>last_name;
}
void input_code(char& grade_code)
{
cout <<"Please enter the grade code (A/a, L/l, E/e). Enter X/x to stop.==> ";
cin >>grade_code;
}
void get_grade(double asgGrade, double labGrade, double examGrade, char grade_code)
{
if ((toupper(grade_code) = 'A'))
{
cout <<"Please enter your total grade for assignments ==> ";
cin >>asgGrade;
}
else if ((toupper(grade_code) = 'L'))
{
cout <<"Please enter your total grade for labs ==> ";
cin >>labGrade;
}
else if ((toupper(grade_code) = 'E'))
{
cout <<"Please enter your total grade for exams ==> ";
cin >>examGrade;
}
}
double calcGrade(double labScore, double asgScore, double examScore, double asgGrade, double labGrade, double examGrade, double numGrade)
{
labScore = ((labGrade / POSSIBLE_LAB) * LABPCT);
asgScore = ((asgGrade / POSSIBLE_ASG) * ASGPCT);
examScore = ((asgGrade / POSSIBLE_EXAM) * EXAMPCT);
numGrade = ((labScore + asgScore + examScore) * 100);
}
void calcLetter(double numGrade, char letterGrade)
{
if (numGrade <60)
{
letterGrade = 'F';
}
else if ((numGrade >= 60) && (numGrade <70))
{
letterGrade = 'D';
}
else if ((numGrade >= 70) && (numGrade <80))
{
letterGrade = 'C';
}
else if ((numGrade >= 80) && (numGrade <90))
{
letterGrade = 'B';
}
else
{
letterGrade = 'A';
}
}
void printGrade(string first_name, string last_name, double numGrade, char letterGrade)
{
cout <<first_name <<" "<<last_name<<" has earned a grade of "<<numGrade<<"%"<<endl;
cout <<"corresponding to a letter grade of: "<<letterGrade<<endl;
}
|