CS2400 Lab 4 Solved

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

Rate this product

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.

  1. Type        cd 2400/Labs
  2. Type mkdir lab4
  3. 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

}

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

—————-

  • 3
  • 2
  • 3
  • 2

F        3

  • lab4-zzkeqr.zip