aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab5/CST116F2021-Lab5.cpp
blob: 2d86908fe20651da0af6342dbf93c4bc8d891f1e (plain) (blame)
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
// CST116F2021-Lab5.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

using namespace std;

const int NUM_SCORES = 10;
const int NUM_STUD = 5;
const int NUM_GRADE = 5;

int main()
{
    float currStudent[NUM_SCORES]{ 0.0 };
    char Grade[NUM_SCORES];
    int numGrade[NUM_GRADE]{ 0 };
    float avg = 0.0;
    
    //Loop for storing scores to array
    for (int i = 0; i < NUM_SCORES; i++)
    {
        cout << "Enter score #" << i + 1 << " of " << NUM_SCORES << ": ";
        cin >> currStudent[i];
    }

    //Loop for comparing scores to letter grade then storing to another array
    for (int i = 0; i < NUM_SCORES; i++)
    {
        if (currStudent[i] >= 92.0)
            Grade[i] = 'A';
        else if (currStudent[i] >= 84.0)
            Grade[i] = 'B';
        else if (currStudent[i] >= 75.0)
            Grade[i] = 'C';
        else if (currStudent[i] >= 65.0)
            Grade[i] = 'D';
        else
            Grade[i] = 'F';

        cout << "\nTest #" << i + 1 << " scored " << currStudent[i] << " and received grade " << Grade[i];
    }
    
    //Calc class average
    for (int i = 0; i < NUM_SCORES; i++)
    {
        avg += currStudent[i];
    }

    avg /= NUM_SCORES;

    cout << "\n\nThe class average for " << NUM_SCORES << " scores is " << avg << endl;

    //Loop for counting number of each letter grade
    for (int i = 0; i < NUM_SCORES; i++)
    {
        if (Grade[i] == 'A')
            numGrade[0] += 1;
        else if (Grade[i] == 'B')
            numGrade[1] += 1;
        else if (Grade[i] == 'C')
            numGrade[2] += 1;
        else if (Grade[i] == 'D')
            numGrade[3] += 1;
        else
            numGrade[4] += 1;
    }

    cout << "\nThe number of Grade A tests is: " << numGrade[0];
    cout << "\nThe number of Grade B tests is: " << numGrade[1];
    cout << "\nThe number of Grade C tests is: " << numGrade[2];
    cout << "\nThe number of Grade D tests is: " << numGrade[3];
    cout << "\nThe number of Grade F tests is: " << numGrade[4];

    return 0;
}