CS 2400 Lab # 4 Grade Frequencies solved


Category: You will receive a download link of the .ZIP file upon Payment


5/5 - (1 vote)

Topics Covered:
File streams, loops, if statements, value-returning functions, void functions.
Step 1: Set up a separate directory for this lab.
First create a subdirectory called lab4.
a. Type cd 2400/Labs
b. Type mkdir lab4
c. Type cd lab4
Step 2: Program
Write a C++ program that repeatedly inputs students’ scores and determines the letter grades. The
scores should be stored in a file called “scores.txt”. For each score, output the score along
with its letter grade. Your program should count the number of A’s, B’s, etc. Use five counters
(aCount, bCount, etc). See main program below.
The letter grade is determined based on the following scale:
>= 90 (A), >= 80 (B), >= 70(C), >= 60(D), >= 0(F).
Output all frequencies.
Your program must, at least, include the following functions:
• A function (getGrade) that takes a score as a parameter and returns a letter grade.
o char getGrade(double score); //prototype
• A void function to print the score and the grade.
o void printGrade(double score, char grade);
• A void function to print the frequencies.
void printFrequencies(int aCount, int bCount,
int cCount, int dCount, int fCount);
Main Program:
int main() {
double score;
int aCount = 0, bCount = 0, cCount = 0, dCount = 0, fCount = 0;
//open the file for input
//get the first score
while(not end of file) {
char grade = getGrade(score);
//output the score and the grade
//determine which counter is updated
//get the next score
//output the frequencies
Submit your program on Blackboard.
CS2400 Lab # 4 June 4, 2019
Grade Frequencies (100 points)
Sample Input File:
44 55 66 77 88 99 50
60 70 80 90 78.5 99.5
Sample output:
Score: 44.0, Grade: F
Score: 55.0, Grade: F
Score: 66.0, Grade: D
Score: 77.0, Grade: C
Score: 88.0, Grade: B
Score: 99.0, Grade: A
Score: 50.0, Grade: F
Score: 60.0, Grade: D
Score: 70.0, Grade: C
Score: 80.0, Grade: B
Score: 90.0, Grade: A
Score: 78.5, Grade: C
Score: 99.5, Grade: A
Grade Frequency
A 3
B 2
C 3
D 2
F 3