Untitled

 avatar
unknown
plain_text
2 years ago
2.4 kB
3
Indexable
/*
    declare your ownership here!
*/

#include <iostream>
#include <iomanip>
#include <vector>
#include<algorithm> // it is not recommended to use std::sort or any other sorting functions to complete this homework, but if that is the only way you can think of, you are allowed to uncomment this line and use 'sort' in your code.

using namespace std;


void read_grades(vector<double>& quiz, double& project, double& exam){
    quiz.resize(6);
    cout << "Please enter quiz grades 0-100: ";
    for (int i = 0; i < 6; i++){
        cin >> quiz[i];
    }
    cout << "Please enter project grade 0-100: ";
    cin >> project;
    cout << "Please enter exam grade 0-100: ";
    cin >> exam;
    
    for (int i = 0; i < 6; i++){
        cout << setw(8) << right << "Quiz " << i+1 << setw(8) << quiz[i] << endl;
    }
    cout << setw(9) << right << "Project" << setw(8) << project << endl;
    cout << setw(9) << right << "Exam" << setw(8) << exam << endl;
    
}

double compute_average (vector<double>quiz, double project, double exam) {
    sort(quiz.begin(), quiz.end());
    double totalScore;
    for (int i = 2; i < 6; i++){
        totalScore += quiz[i]; //to compute the average, we first need to add all of the integers from the vector then divide it by 4 since that is the total amount of tests we are using
    }
    
    double average;
    //using an if else statement in order to know which scheme gives the higher score.
    if (((totalScore/4)*0.30) + (project*0.25) + (exam*0.45) > ((totalScore/4)*0.22) + (project*0.32) + (exam*0.46)) {
        average = ((totalScore/4)*0.30) + (project*0.25) + (exam*0.45);
        cout << "Scheme I is used." << endl;
    }
    else if (((totalScore/4)*0.30) + (project*0.25) + (exam*0.45) < ((totalScore/4)*0.22) + (project*0.32) + (exam*0.46)) {
        average = ((totalScore/4)*0.22) + (project*0.32) + (exam*0.46);
        cout << "Scheme II is used." << endl;

    }
    
    return average;
}




int main()
{
    
    vector<double> quiz(6);
    double exam, project; // contains midterm and final
    
    // read grades from user
    read_grades(quiz, project, exam);

    // compute average based on the grading scheme
    // print items to the console, including dropped situation
    double average = compute_average(quiz, project, exam);

    // output average grade
    cout << "The average grade is " << average << "." << endl;

    return 0;
}

Editor is loading...