diff options
| author | JacobAKnox <[email protected]> | 2021-10-27 19:45:16 -0700 |
|---|---|---|
| committer | JacobAKnox <[email protected]> | 2021-10-27 19:45:16 -0700 |
| commit | 7964cee704aaf29d63999055795a13121763bdeb (patch) | |
| tree | c3c3b379e8cd534231428155fdccfb26e1569099 /9b/10.6/10.6.cpp | |
| parent | 5.9a complete (diff) | |
| download | cst116-lab5-jacobaknox-7964cee704aaf29d63999055795a13121763bdeb.tar.xz cst116-lab5-jacobaknox-7964cee704aaf29d63999055795a13121763bdeb.zip | |
9b finished
Diffstat (limited to '9b/10.6/10.6.cpp')
| -rw-r--r-- | 9b/10.6/10.6.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/9b/10.6/10.6.cpp b/9b/10.6/10.6.cpp new file mode 100644 index 0000000..5a09b87 --- /dev/null +++ b/9b/10.6/10.6.cpp @@ -0,0 +1,108 @@ +// 10.6.cpp : This file contains the 'main' function. Program execution begins and ends there. +// Written by Jacob Knox +// + +#include <iostream> + +using namespace std; + +void GetInputs(float[], int); +void GetCounts(float[], char[], int[], int); +int CalcAvg(float[], int); +void Output(float[], char[], int[], int, int, int); + +int main() +{ + const int NUM_SCORES = 10, NUM_GRADES = 5; + float scores[NUM_SCORES] = {}; + char grades[NUM_SCORES] = {}; + int counts[NUM_GRADES] = { 0, 0, 0, 0, 0 }; + float avg = 0; + + GetInputs(scores, NUM_SCORES); + GetCounts(scores, grades, counts, NUM_SCORES); + avg = CalcAvg(scores, NUM_SCORES); + Output(scores, grades, counts, avg, NUM_SCORES, NUM_GRADES); + +} + +void GetInputs(float scores[], int size) +{ + for (int i = 0; i < size; i++) + { + cout << "Enter score #" << i + 1 << " of " << size << ": "; + cin >> scores[i]; + } +} + +void GetCounts(float scores[], char grades[], int counts[], int sizeS) +{ + for (int i = 0; i < sizeS; i++) + { + if (scores[i] >= 90) + { + grades[i] = 'A'; + counts[0]++; + } + else if (scores[i] >= 80) + { + grades[i] = 'B'; + counts[1]++; + } + else if (scores[i] >= 70) + { + grades[i] = 'C'; + counts[2]++; + } + else if (scores[i] >= 60) + { + grades[i] = 'D'; + counts[3]++; + } + else + { + grades[i] = 'F'; + counts[4]++; + } + } +} + +int CalcAvg(float scores[], int size) +{ + float avg = 0, tot = 0; + + for (int i = 0; i < size; i++) + { + tot += scores[i]; + } + + avg = tot / size; + + return avg; +} + +void Output(float scores[], char grades[], int counts[], int avg, int sizeS, int sizeC) +{ + for (int i = 0; i < sizeS; i++) + { + cout << "The " << i + 1 << " student recived a " << scores[i] << "% and got a(n) " << grades[i] << ".\n"; + } + + cout << "The average score is: " << avg << "%.\n"; + + char letter; + for (int i = 0; i < sizeC; i++) + { + + if (i != 4) + { + letter = 65 + i; + } + else + { + letter = 70; + } + + cout << "There were " << counts[i] << letter << "'s.\n"; + } +} |