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
|
// 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";
}
}
|