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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Lab5 Exercises 10.5, 10.6, 10.7, and 10.8#7 Benjamin Schroeder
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Exercise 10.6 and 10.7
//HEADER FILE "Scores.h" /////////////////////////////////////////////////////////////////////
#pragma once
#include <iostream>
using namespace std;
const int NUM_SCORES = 1;
const int NUM_STUDENT = 10;
void ReadScores(float[]);
void LetterG(char[], float[], int[]);
void average(float[]);
void displayG(float[], char[], int[]);
//FUNCTIONS FILE "ScoresFunctions.cpp" ///////////////////////////////////////////////////////////
#include "Scores.h"
void ReadScores(float testScore[])
{
cout << "Enter percent score of student: \n";
for (int i = 0; i < NUM_STUDENT; i++) // starting at 0, array numbered 0 to 9
{
cout << " \t# " << i + 1 << " of " << NUM_STUDENT << " students:\t";
cin >> testScore[i];
}
}
void LetterG(char letterGrade[], float testScore[], int gradeCounts[])
{
for (int i = 0; i < NUM_STUDENT; i++)
{
if (testScore[i] >= 92.0)
{
letterGrade[i] = 'A';
gradeCounts[0] = gradeCounts[0] + 1;
}
else if (testScore[i] >= 84.0 && testScore[i] < 92.0)
{
letterGrade[i] = 'B';
gradeCounts[1] = gradeCounts[1] + 1;
}
else if (testScore[i] >= 75.0 && testScore[i] < 84.0)
{
letterGrade[i] = 'C';
gradeCounts[2] = gradeCounts[2] + 1;
}
else if (testScore[i] >= 65.0 && testScore[i] < 75.0)
{
letterGrade[i] = 'D';
gradeCounts[3] = gradeCounts[3] + 1;
}
else if (testScore[i] < 65.0)
{
letterGrade[i] = 'F';
gradeCounts[4] = gradeCounts[4] + 1;
}
}
}
void average(float testScore[])
{
float average = 0.0;
float total = 0.0;
for (int i = 0; i < NUM_STUDENT; i++)
{
total = total + testScore[i];
}
average = total / NUM_STUDENT;
cout << "\n\n\tClass Average: " << average << "%\n\n";
return;
}
void displayG(float testScore[], char letterGrade[], int gradeCounts[])
{
for (int i = 0; i < NUM_STUDENT; i++)
{
cout << " Student # " << i + 1 << ",\tScore: " << testScore[i] << ", Letter Grade: " << letterGrade[i] << "\n";
}
cout << "\n\tThere were " << gradeCounts[0] << " A's\n";
cout << "\tThere were " << gradeCounts[1] << " B's\n";
cout << "\tThere were " << gradeCounts[2] << " C's\n";
cout << "\tThere were " << gradeCounts[3] << " D's\n";
cout << "\tThere were " << gradeCounts[4] << " F's\n";
}
///// main() FILE /////////////////////////////////////////////////////////////////////////////////
#include "Scores.h"
int main()
{
int gradeCounts[5]{ 0 };
float testScore[NUM_STUDENT]{ 0.0 };
char letterGrade[NUM_STUDENT]{ 'A' };
ReadScores(testScore);
LetterG(letterGrade, testScore, gradeCounts);
cout << "\n\n";
displayG(testScore, letterGrade, gradeCounts);
average(testScore);
}
///////
Run from Exercises 10.5-10.6 Learn By Doing
Enter percent score of student:
# 1 of 10 students: 95
# 2 of 10 students: 85
# 3 of 10 students: 75
# 4 of 10 students: 86
# 5 of 10 students: 89
# 6 of 10 students: 91
# 7 of 10 students: 81
# 8 of 10 students: 72
# 9 of 10 students: 52
# 10 of 10 students: 93
Student # 1, Score: 95, Letter Grade: A
Student # 2, Score: 85, Letter Grade: B
Student # 3, Score: 75, Letter Grade: C
Student # 4, Score: 86, Letter Grade: B
Student # 5, Score: 89, Letter Grade: B
Student # 6, Score: 91, Letter Grade: B
Student # 7, Score: 81, Letter Grade: C
Student # 8, Score: 72, Letter Grade: D
Student # 9, Score: 52, Letter Grade: F
Student # 10, Score: 93, Letter Grade: A
There were 2 A's
There were 4 B's
There were 2 C's
There were 1 D's
There were 1 F's
Class Average: 81.9%
C:\Users\Lenovo\Source\Repos\cst116-lab5-BensProgramma\x64\Debug\CST116F2021-Lab5.exe (process 14272) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Exercise 10.7 Learn By Doing
int main()
{
char First[41]{};
char Last[41]{};
char Full[81]{};
cout << "Enter your first name: ";
cin.ignore(cin.rdbuf()->in_avail());
cin.getline(First, 41);
cin.clear();
cin.ignore(cin.rdbuf()->in_avail());
cout << "Enter your last name: ";
cin.ignore(cin.rdbuf()->in_avail());
cin.getline(Last, 41);
cin.clear();
cin.ignore(cin.rdbuf()->in_avail());
for (int i = 0; i < strlen(Last); i++)
Full[i] = Last[i];
Full[strlen(Last)] = ',';
Full[strlen(Last)+1] = ' ';
for (int j = 0; j <strlen(First); j++)
Full[strlen(Last)+2+j] = First[j];
cout <<"Contents of the 'Full Name Array': "<< Full;
}
//////
RUN from Exercise 10.7 Learn By Doing
Enter your first name: Benjamin
Enter your last name: Schroeder
Contents of the 'Full Name Array': Schroeder, Benjamin
C:\Users\Lenovo\Source\Repos\cst116-lab5-BensProgramma\x64\Debug\CST116F2021-Lab5.exe (process 22292) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Exercise 10.8 #7
#include<iostream>
using namespace std;
char string_1[] = "Frank";
char string_2[] = "Franklyn";
int main()
{
int compare = strncmp(string_1, string_2, 6);
cout << "Comparing the first 6 chars of strings: '" << string_1 << "' and '" << string_2 << "'";
if (compare == 0)
cout << "\nSame\n";
else if (compare < 0)
cout << "\nDifferent\n";
}
//////
Run from Exercise 10.8 #7
Comparing the first 6 chars of strings: 'Frank' and 'Franklyn'
Different
C:\Users\Lenovo\Source\Repos\cst116-lab5-BensProgramma\x64\Debug\CST116F2021-Lab5.exe (process 21936) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|