Question: s#include #include #include #include using namespace std; char getGradeLetter ( float grade ) { if ( grade > = 9 0 . 0 ) return

s#include
#include
#include
#include
using namespace std;
char getGradeLetter(float grade){
if (grade >=90.0) return 'A';
if (grade >=80.0) return 'B';
if (grade >=70.0) return 'C';
if (grade >=60.0) return 'D';
return 'F';
}
int main(){
ifstream inFile("grades.txt");
ofstream outFile("statistics.csv");
if (!inFile.is_open()){
cerr << "Error opening input file!" << endl;
return 1;
}
if (!outFile.is_open()){
cerr << "Error opening output file!" << endl;
return 1;
}
string name;
float grade;
map count ={{'A',0},{'B',0},{'C',0},{'D',0},{'F',0}};
while (inFile >> name >> grade){
char gradeLetter = getGradeLetter(grade);
count[gradeLetter]++;
}
// Output to terminal
for (const char grade : {'A','B','C','D','F'}){
cout << count[grade]<<""<< grade << endl;
}
// Output to statistics.csv
outFile << "Grade,NumStudents
";
for (const char grade : {'A','B','C','D','F'}){
outFile << grade <<","<< count[grade]<<"
";
}
inFile.close();
outFile.close();
return 0;
}
1.
----------------------------
HW4A - Compilation Test (0/0)
2. COMPILATION SUCCESSFUL!!
3.
4. Input File - grades.txt
5.
6. Kelden Amadiro 57
7. Daneel Olivaw 89.0
8. Elijah Baley 84
9. Giskard Reventlov 88.8
10. Alfred Lanning 68
11. Susan Calvin 94
12. Han Fastolfe 92
13. Gregory Powell 73
14. Mike Donovan 67
15. Laurance Robertson 76
16. Hari Seldon 98
17. Dors Venabili 82
18. Eto Demerzel 89.0
19. Raych Seldon 78
20. Salvor Hardin 86
21. Yugo Amaryl 96
22. Ebling Mis 87
23. John Watson 43
24. Sherlock Holmes 92
25. Violet Crawley 83
26. Greg Lestrade 74
27. Missus Hudson 85
28. Jim Moriarty 99.99999999999
29. Molly Hooper 65
30. Irene Adler 91
31. Mycroft Holmes 82
32. Tom Branson 83
33. John Bates 89
34. Mister Carson 79
35. HW4A - Output File - 'statistics.csv'(1/1)
36. PASSED!! Found output File 'statistics.csv'
37. HW4A - Contents of 'statistics.csv'(0/6)
38. Grade,NumStudents
39.- A,0
40.- B,0
41.- C,0
42.- D,0
43.- F,0
44.+ A,7
45.+ B,12
46.+ C,5
47.+ D,3
48.+ F,2
49.
50. FAILED!! Contents of 'statistics.csv' are incorrect.
51.
52. Test Failed: False is not true :
53. HW4A - Terminal Output (I/O Formatting)(0/2)
54.-0 A
55.-0 B
56.-0 C
57.-0 D
58.-0 F
59.+7 A
60.+12 B
61.+5 C
62.+3 D
63.+2 F
64.
65. FAILED!!
66.
Test Failed: False is not true :
--------------------------------------------
Kelden Amadiro 57
Daneel Olivaw 89.0
Elijah Baley 84
Giskard Reventlov 88.8
Alfred Lanning 68
Susan Calvin 94
Han Fastolfe 92
Gregory Powell 73
Mike Donovan 67
Laurance Robertson 76
Hari Seldon 98
Dors Venabili 82
Eto Demerzel 89.0
Raych Seldon 78
Salvor Hardin 86
Yugo Amaryl 96
Ebling Mis 87
---------------------------
Problem A: Making the grade (5 points)
The file grades.txt contains a list of names with grades, separated by spaces. Note that the grades may contain decimal values.
John Watson 43
Sherlock Holmes 92
Violet Crawley 83
...
Write a program that reads in the grades from grades.txt and then outputs the distribution of letter grades to the terminal. Have your program also create an excel-friendly, comma delimited file called statistics.csv that contains the grade distribution. The necessary format for both the terminal output and statistics.csv are shown in the examples below.
Your program should read in the grade for each person, then determine their letter grade using the breakdown shown here. These grade boundaries are inclusive, so an A is anything >=90.0.
Grade A B C D F
Min %908070600
Your program should display the distribution of letter grades to the terminal, as shown in the Example Terminal Output below and create a similar excel-friendly file called statistics.csv, shown in Example File Output below. Make sure to match the format in the examples below exactly. Notice that the format is different between the terminal output and the .csv output, so double check that you are using the correct format for each.
Example Terminal Output
3 A
5 B
2 C
1 D
1 F
Example File Output (statistics.csv)
Grade,NumStudents
A,3
B,5
C,2
D,1
F,1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!