Site hosted by Angelfire.com: Build your free website today!

Program #17Write a program that will ask for a student’s test score.  The program will determine the letter grade they should get.  Sum the scores as you go.  Calculate the class average.  Determine grade distribution (how many A’s, B’s…).  Print out a chart with all scores, grades and class average… to printer. (You have to send output to a file).  The name of the file should be called p17out.cpp (check the ditto that shows you how to print a file that has been given to you).

 

Intro C++Hand in your chart with the initialized program sheet.

Output like this to the screen…

Please enter test score #1(to quit enter-99) 88

Please enter test score #2(to quit enter -99) 98

Please enter test score #3(to quit enter -99) 78

Please enter test score #4(to quit enter -99) 68

Please enter test score #5(to quit enter -99) -99

 

Thank you, you have entered 4 test scores.  To see the tests and results please load the file called p17out.cpp

 
 

 

 

 

 

 

 

 

 


The chart in the file should look like this…                                            

            TEST RESULTS

#          SCORE           GRADE

1            88                    B

2            98                    A

3            78                    C

4            68                    D

 

4 tests have been entered.

Class average is 83.00

 

Grade Distribution: A: 1            B: 1      C: 1      D: 1      E:0

There were 0 failures.

 

TO WRITE TO A FILE:

1)      Have the library #include<fstream.h>

2)      Have an output file stream declared… this will work like cout does, but prints to a file.

3)      Open a path for the stream to follow

dzwon.open(\\\\ucs-irc-bld\\student\\studennt<<44stud??\\p17out.cpp);

use dzwon like you would cout, but it goes to the file.

4)      print to the file as you need, then close

dzwon.close( );

 
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Hints: have a switch assign the grade and count the number of each.  Prime the switch variable like this:

  Cin<<score;

While(score!=-99)

{

                  count++

   sw_score=floor(score/10);

   switch(sw_score)

    {

                   case 9: grade= ‘A’;

    a_count=count++;

    break;