-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab8_2.cpp
56 lines (50 loc) · 1.37 KB
/
lab8_2.cpp
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
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
//[Missing Code 1] Write definition of the function findGrade() here.
char findGrade(double stu_score)
{
char grade;
if(stu_score > 90)
grade = 'A';
if(stu_score <= 90 && stu_score > 75)
grade = 'B';
if(stu_score <= 75 && stu_score > 60)
grade = 'C';
if(stu_score <= 60 && stu_score > 45)
grade = 'D';
if(stu_score <= 45)
grade = 'F';
return grade;
}
int main(){
//Input the number of students
int N,i = 0;
cout << "Enter the number of students: ";
cin >> N;
string name[N];
float score[N];
//Store names and scores of students into an array
while(i < N){
cout << "Name of student " << i+1 << ": ";
cin.ignore();
//[Missing Code 2] Get name of the i-th students that may include whitespace.
getline(cin, name[i]);
cout << "Score of student " << i+1 << ": ";
//[Missing Code 3] Get score of the i-th students.
cin >> score[i];
i++;
}
//Print; names scores and grades
i = 0;
cout << "---------------------------------------------\n";
cout << setw(25) << "Name" << setw(8) << "Score" << setw(8) << "Grade" << "\n";
cout << "---------------------------------------------\n";
while(i < N){
cout << setw(25) << name[i] << setw(8) << score[i] << setw(8) << findGrade(score[i]) << "\n";
i++;
}
cout << "---------------------------------------------\n";
return 0;
}