Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Christian Ballard
- //COSC 1330 - 003
- //This program should calculate students weighted averages.
- #include <iostream>
- #include <iomanip>
- using namespace std;
- double averageGrade(double &);
- double classAverage(double &, double, double, double);
- void getLetterGrade(char &, double);
- void displayGradeReport(double, double, double, double, char);
- int main()
- {
- double labAverage = 0.0;
- double testAverage = 0.0;
- double projectAverage = 0.0;
- double finalAverage = 0.0;
- char letterGrade = ' ';
- char loopQ = ' ';
- letterGrade = toupper(letterGrade);//Keeping the characters entered uppercase.
- cout << fixed << setprecision(2);//Just putting this here so it doesn't get in the way.
- do//Where the loop will start.
- {
- cout << "Please enter your lab grades." << endl;
- averageGrade(labAverage);//Calls the averageGrade function.
- system("cls");
- cout << "Your lab average is " << labAverage << endl << endl;
- cout << "Please enter your test grades." << endl;
- averageGrade(testAverage);//Calling the averageGrade function once again.
- system("cls");
- cout << "Your test average is " << testAverage << endl << endl;
- cout << "Please enter your project grades." << endl;
- averageGrade(projectAverage);//Calling th averageGrade function AGAIN!.
- system("cls");
- finalAverage = classAverage(finalAverage, labAverage, testAverage, projectAverage);//Calling the classAverage function, and also sending some variables.
- getLetterGrade(letterGrade, finalAverage);//Calling this function will give us a letter grade.
- displayGradeReport(labAverage, testAverage, projectAverage, finalAverage, letterGrade);//This function will display everything.
- cout << "Would you like to enter data for a new student? " << endl; //posttest loop
- cin >> loopQ;
- system("cls");
- } while (loopQ == 'y');
- if (loopQ == 'n')
- {
- cout << "Thank you for using this program!" << endl;
- }
- system("pause");
- return 0;
- }
- double averageGrade(double &gradeAverage)
- {
- double grades = 0.0;
- int numGrades = 0;
- double sum = 0.0;
- char loopies = 'Y'; //Kind of like the primeread.
- do
- {
- cin >> grades;
- numGrades++; //Acumulator
- sum = grades + sum;
- cout << "Would you like to enter more grades? (Y/N)";//This is really annoying but the only way I found to do this.
- cin >> loopies;
- loopies = toupper(loopies);
- switch (loopies) { //Switch to determine what to do if they have no more grades.
- case 'N':
- gradeAverage = sum / numGrades;
- }
- } while (loopies == 'Y'); //End of the loops.
- return gradeAverage;
- }
- double classAverage(double &averageClass, double labAverage, double testAverage, double projectAverage)
- {
- double const LAB_WEIGHT = .50;
- double const TEST_WEIGHT = .40;
- double const PROJECT_WEIGHT = .10;
- averageClass = (labAverage * LAB_WEIGHT) + (testAverage * TEST_WEIGHT) + (projectAverage * PROJECT_WEIGHT);
- return averageClass;
- }
- void getLetterGrade(char &gradeLetter, double finalAverage)
- {
- if (finalAverage >= 90.00)
- {
- gradeLetter = 'A';
- }
- else if (finalAverage >= 80.00 && finalAverage < 90.00)
- {
- gradeLetter = 'B';
- }
- else if (finalAverage >= 70.00 && finalAverage < 80.00)
- {
- gradeLetter = 'C';
- }
- else if (finalAverage >= 60.00 && finalAverage < 70.00)
- {
- gradeLetter = 'D';
- }
- else
- {
- gradeLetter = 'F';
- }
- }
- void displayGradeReport(double averageLab, double averageTest, double averageProject, double averageFinal, char gradeLetter)
- {
- cout << "Your lab average is " << averageLab << endl;
- cout << "Your test average is " << averageTest << endl;
- cout << "Your project average is " << averageProject << endl << endl;
- cout << "Your overall class average is " << averageFinal << endl;
- cout << "You currently have a " << gradeLetter << " in this class." << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment