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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
//This file contains all of the functions in the project. Code by Jordan Harris-Toovy, November 2021
#include "Main_header.h"
//10.6 LBD-Ex #1
void get_scores(float storage[])
{
for (int idx = 0; idx < NUM_SCORES; idx++)
{
while (storage[idx] <= 0)
{
cout << "Enter score #" << idx + 1 << " of " << NUM_SCORES << ": ";
cin >> storage[idx];
if (storage[idx] < 0)
{
cout << "\nError: Score cannot be negative\n";
}
}
}
}
void grade_scores(float score[], char grade[])
{
for (int idx = 0; idx < NUM_SCORES; idx++)
{
if (score[idx] >= 92.0F)
{
grade[idx] = 'A';
}
else if (score[idx] >= 84.0F)
{
grade[idx] = 'B';
}
else if (score[idx] >= 75.0F)
{
grade[idx] = 'C';
}
else if (score[idx] >= 65.0F)
{
grade[idx] = 'D';
}
else
{
grade[idx] = 'F';
}
}
}
void total_grades(char grades[], int grade_total[])
{
for (int idx = 0; idx < NUM_SCORES; idx++)
{
switch (grades[idx])
{
case 'A':
grade_total[0]++;
break;
case 'B':
grade_total[1]++;
break;
case 'C':
grade_total[2]++;
break;
case 'D':
grade_total[3]++;
break;
case 'F':
grade_total[4]++;
break;
default:
break;
}
}
}
float average_scores(float scores[])
{
float total = 0.0F;
for (int idx = 0; idx < NUM_SCORES; idx++)
{
total += scores[idx];
}
return (total / NUM_SCORES);
}
void display_info(float& avg, int total_grades[], char grades[], float scores[])
{
cout << endl << "The average score is: " << avg << endl << "The number of assigned grades are as follows: ";
cout << "A - " << total_grades[0] << ", B - " << total_grades[1] << ", C - " << total_grades[2]
<< ", D - " << total_grades[3] << ", F - " << total_grades[4] << endl;
cout << "The individual scores are as follows: " << endl;
for (int idx = 0; idx < NUM_SCORES; idx++)
{
cout << "Student " << idx + 1 << " scored " << scores[idx] << " (" << grades[idx] << ")\n";
}
}
//10.7 LBD-Ex #2
void getName(char name[], int nameMode = 0)
{
if (nameMode == 0)
{
cout << "Please enter your first name: ";
cin >> name;
}
else if (nameMode == 1)
{
cout << "Please enter your last name: ";
cin >> name;
}
else
{
cout << "\nERROR: INVALID getName MODE\n" << endl;
}
}
int getStringSize(char string[])
{
int idx = 0;
while (string[idx] != '\0')
{
idx++;
}
return idx;
}
//10.8 Ex #7
void get_string(char user_string[], int mode)
{
if (mode == 0)
{
cout << "Please enter a string (alphanumeric and +-,.): ";
}
else
{
cout << "Please enter another string: ";
}
cin >> user_string;
//BUG: some characters, such as the space character, will act as delimiters, causing cin to pickup two strings instantly.
}
bool string_compair_N(char str1[], char str2[], int num_cmp)
{
bool result = true;
for (int idx = 0; idx < num_cmp; idx++)
{
if (str1[idx] != str2[idx])
{
result = false;
}
}
return result;
}
|