-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab 4 Q 1.cpp
More file actions
77 lines (65 loc) · 1.61 KB
/
Lab 4 Q 1.cpp
File metadata and controls
77 lines (65 loc) · 1.61 KB
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
//Liam Salazar, P21439665 (Navigator)
//Muhammad Ghazi, P(ID) (Driver)
//April 4, 2017
/*Program uses struct. Main program will generate
ID's and a score for 20 students. A function will be called
to determine the letter grade with the score. Lastly, it
will count each grade.*/
#include <iostream>
#define length 20
using namespace std;
char letter(double &score);
struct Student
{
int id;
double score;
char grade;
};
int countA = 0;
int countB = 0;
int countC = 0;
int countD = 0;
int countF = 0;
int main()
{
Student P[length];
//This for loop will generate the students and give them ID #'s, scores, and a letter grade.
for (int i = 0; i < length; i++)
{
P[i].id = 1 + i; //Originally P[i].id= 1 + rand() % 20, changed because other group notified me of the correct way
P[i].score = 10 + rand() % 90;
cout << "P" << P[i].id << endl;
cout << "Score: " << P[i].score << endl;
cout << "Grade: " << letter(P[i].score) << endl;
cout << endl;
}
cout << "(A) Execellent grades: " << countA << endl; //Counts A's
cout << "(B) Above average: " << countB << endl; //Counts B's
cout << "(C) Average: " << countC << endl; //Counts C's
cout << "(D) Below Average: " << countD << endl; //Counts D's
cout << "(F) Failing: " << countF << endl << endl;
return 0;
}
char letter(double &score)
{
if (score >= 90)
{
countA++; return 'A';
}
else if (score >= 80)
{
countB++; return 'B';
}
else if (score >= 70)
{
countC++; return 'C';
}
else if (score >= 60)
{
countD++; return 'D';
}
else
{
countF++; return 'F';
}
}