-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab9_2.cpp
39 lines (36 loc) · 1001 Bytes
/
lab9_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
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
char findGrade(double grade)
{
return grade>90 ? 'A':grade>75 ? 'B':grade>60 ? 'C':grade>45 ? 'D':'F';
}
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();
getline(cin,name[i]);
cout << "Score of student " << i+1 << ": ";
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;
}