Question

Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

Write a C++ program named, gradeProcessor.cpp, that will do the following tasks:

-Print welcome message

-Generate the number of test scores the user enters; have scores fall into a normal distribution for grades

-Display all of the generated scores - no more than 10 per line

-Calculate and display the average of all scores

-Find and display the number of scores above the overall average (previous output)

-Find and display the letter grade that corresponds to the average above (overall average)

-Calculate an display the average of the scores after dropping lowest score

-Find and display the number of scores above the dropped score average

-Find and display the letter grade that corresponds to the average above (dropped score average)

-Find and display the minimum of all scores

-Find and display the maximum of all scores

-Display a histogram of all scores in terms of their corresponding letter grades (see examples)

-Display the occurrence counts for every score appearing in the list more than once

-Print termination message

The example output shows several executions of this program. Make your output look like these examples, although you input and generated values will be different.

Welcome to the Grade Processor Application
    This app will generate the number of scores desired by the user
    and then perform and display several functions on this data.
    
    How many scores do you want to process: 100
    
    All scores:
       62   71   64   83   60   94   83   60   74   81
       98   70   73   25   80   84   74   74   78   75
       48  100   92   85   72   89   86   86   89   70
       89   75   68   79   72   96   73   73   18   73
       67   60   88   95   93   83   14   74   95   94
       76   89   30   78   91   78   61   32   75   77
       76   76   68   79   28   63   66   75   11   16
       62   84   73   91   81   71   78   64   77   72
       73   97   68    9   86   92   68   93   64   72
       91   77   80   74   90   18   87   71   90   90
    
    
    Average of all scores:                 72.47
    Number of scores above this average:   64
    Letter grade for all scores:           C
    
    Average of all scores without lowest:  73.11
    Number of scores above this average:   58
    Letter grade after dropping lowest:    C
    
    Minimum of all scores:                 9
    Maximum of all scores:                 100
    
    Displaying histogram for 100 scores:
    A: ******************
    B: *******************
    C: ************************************
    D: ****************
    F: ***********
    
    Score occurrence counts > 1:
      95:   2     94:   2         93:   2         92:   2         91:   3       
      90:   3     89:   4         86:   3         84:   2         83:   3       
      81:   2     80:   2         79:   2         78:   4         77:   3       
      76:   3     75:   4         74:   5         73:   6         72:   4       
      71:   3     70:   2         68:   4         64:   3         62:   2       
      60:   3     18:   2       
    
    
    Thanks for using the Grade Processor application.
=============================================================================
=============================================================================

There are requirements for these tasks that will now be explained. Some of the requirements also imply certain restrictions you must follow in your design and implementation. There is a specific list of functions that you must implement. The requirements give you their exact names, parameter lists, and return types. You follow these exactly to get full credit for this assignment.

int generateOneScore()
This first function is
given to you for free!! All you have to do is copy the code below into your own gradeProcessor.cpp file. As the function's prolog states, seed the random number generator in main just after beginning execution of your application, then call this function whenever you need another score to put into the array of scores. You should understand when and where to use this function as you understand more about this program. Here is the code:

/////////////////////////////////////////////////////////////////////////////
// This function uses the random number generator to generate a test score
// that falls into a somewhat typical distribution for grades.  To use this
// function, first, randomly seed the generator in your main function once
// and then call this function as needed. Seed by calling:  srand(time(0))
/////////////////////////////////////////////////////////////////////////////
int generateOneScore() {
   const int A = 14;  // ~14% of scores are A
   const int B = 39;  // ~25% of scores are B
   const int C = 75;  // ~36% of scores are C
   const int D = 89;  // ~14% of scores are D
   const int F = 100; // ~11% of scores are F
   const int MIN_A = 90;
   const int MIN_B = 80;
   const int MIN_C = 70;
   const int MIN_D = 60;
   
   // generate a number bewteen 1 and 100, inclusive
   // to determine which letter grade to generate
   int whichLetter = rand() % 100 + 1;  // 1..100
   
   // Set min and max based on the letter grade
   int min, max;
   if (whichLetter <= A) {
      min = MIN_A;
      max = 101;
   }
   else if (whichLetter <= B) {
      min = MIN_B;
      max = MIN_A;
   }
   else if (whichLetter <= C) {
      min = MIN_C;
      max = MIN_B;
   }
   else if (whichLetter <= D) {
      min = MIN_D;
      max = MIN_C;
   }
   else {
      min = 0;
      max = MIN_D;
   }
   // Generate a random score for the chosen letter grade
   int score = rand() % (max-min) + min;
   return score;
}

NOTE: You may want to use the MIN_A, MIN_B, etc. named constants elsewhere in your code, so you should remove them from this function and paste them before your main where named constants are usually declared.

void getNumberOfScores( int& )
One
Parameters: type int, passed by reference
-Description: Prompts the user to enter the number of scores that will be used during this execution of the application
-USE: Caller invokes this function to get the number of scores to process at the beginning of the application's execution

void generateScores( int list[], int n )
Two Parameters: array of integers and number of integers currently stored in the array
-Description: This function will write n scores into the array of scores named, list. The scores are generated one at a time by calling generateOneScore.
-USE: Caller invokes this function to populate the array, list, with n scores

double calcAverage (int list[], int n, bool drop)
Three
Parameters: array of integer scores, number of scores currently in list, and boolean flag, drop
-Description: Calculate the average of the first n scores stored n the array. If drop is true, do not include the lowest score in this calculation. If drop is false, include all n scores. When this function needs to drop the lowest score, it should call the function, findLowest (see below). The average should be accurate to fractional values and NOT always be an integer: in other words, watch the expression you use to do the calculation of the average.
-USE: Caller invokes this function to have computed the average of the first n elements of an array; may do so with or without lowest grade.

int findLowest(int list[], int n)
Two parameters: array of integers and an integer holding the number of values currently in the array
-Description: searches the list to find the smallest (lowest or minimum) value, returns that value
-USE: This function is called when the caller need to have the lowest value in the array returned.

int findHighest(int list[], int n)
Two parameters: array of integers and an integer holding the number of values currently in the array
-Description: searches the list to find the highest (largest or maximum) value, returns that value
-USE: This function is called when the caller need to have the highest value in the array returned.

int countAboveAverage (int list[], int n, double average)
Three Parameters: array of integers, number of integers stored in the array, and average of values in array
-Description: count and return the number of values in the array that are above the average.
-USE: Caller invokes this function to have computed the number of the first n scores of the list that are greater than the average of those n scores.
-Note: This function does NOT call a function to calculate the average. The caller passes the value of the average in as the third parameter.

void displayScores(int list[], int n)
Two Parameters: array of integers and number of integers stored in the array
-Description: print the n scores found in the array, list. Print 10 on each line. If n is not divisible by 10, then there should be fewer than 10 scores on the last line only.
-USE: Caller invokes this function to display the contents of the array of scores

char findLetterGrade(double grade)
One Parameter: value of type, double
-Description: determine the letter grade (type, char) for the numeric score, grade
-USE: Caller invokes this function to determine the letter grade appropriate for a given numeric score

void displayHistogram( int list[], int n )
Two Parameters: array of integers and number of integers stored in the array
-Description: Displays a histogram of all scores in terms of the letter grade for each score. The display heading states how many scores ( n ) are in the histogram, then displays one star for each score that is an A on line one of the histogram. On line two there should be one star for each score that is a B. Proceed this way for all five letter grades (A, B, C, D, F). Each line should begin with a label containing the letter grade for that line. See several examples in the example output. Make sure your output is exactly the same.
-USE: Invoked by main to display the histogram of all scores

void displayDuplicateScores( int list[], int n )
Two Parameters: array of integers and number of integers stored in the array
-Description: For all scores appearing in the list more than one time, this function displays those scores and their occurrence counts. See several examples in the example output.
-USE: Invoked by main to display the occurrence counts for scores appearing in the list more than one time

***function: main
Your main function should control the execution of each of the tasks in the list at the top of this page. Use the example output as a guide to help developing main so that this application works as required and looks like the examples in the example output.

***Notice: while the array of scores is always declared to have 100 elements, the number of elements actually used during an execution is the number entered by the user (2..100). This is why the user's input value (n) is passed around to the various functions: so these functions know how many elements of the array to use. The unused elements should be ignored.

Coding Requirements and Restrictions

1) All variables must be declared locally to a function. No global variables.

2) Make sure your program has good prompts and clearly labeled output. Add blank lines to the output to improve its readability.  
OR: Make your output look exactly like the examples.

3) Do NOT use any language constructs that have not been covered in class.

4) Make your code readable by using meaningful variable names, indentation and spacing – in other words, ALL of the coding conventions for this course.

5) All functions must be documented with a description just before the function's header line.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<time.h>

using namespace std;

//function declarations

int generateOneScore();

void getNumberOfScores(int&);

void generateScores(int list[], int n);

double calcAverage(int list[], int n, bool drop);

int findLowest(int list[], int n);

int findHighest(int list[], int n);

int countAboveAverage(int list[], int n, double average);

void displayScores(int list[], int n);

char findLetterGrade(double grade);

void displayHistogram(int list[], int n);

void displayDuplicateScores(int list[], int n);

int main()

{

int n;

int list[100];

double Avg;

getNumberOfScores(n);

generateScores(list, n);

displayScores(list, n);

Avg = calcAverage(list, n, false);

cout << "Average of all scores: \t" << Avg << endl;

cout << "Number of scores above this average: " << countAboveAverage(list, n, Avg) << endl;

cout << "Lette grade for all scores: " << findLetterGrade(Avg) << endl;

Avg = calcAverage(list, n, true);

cout << "Average of all scores without lowest: " << Avg << endl;

cout << "Number of scores above this average: " << countAboveAverage(list, n, Avg) << endl;

cout << "\nMinimum of all scores : " << findLowest(list, n) << endl;

cout << "Maximum of all scores : " << findHighest(list, n) << endl << endl;

cout << "Displaying histogram for " << n << " scores: " << endl;

displayHistogram(list, n);

displayDuplicateScores(list, n);

cout << "\nThanks for using Grade Processor application." << endl;

}

int generateOneScore()

{

const int A = 14; // ~14% of scores are A

const int B = 39; // ~25% of scores are B

const int C = 75; // ~36% of scores are C

const int D = 89; // ~14% of scores are D

const int F = 100; // ~11% of scores are F

const int MIN_A = 90;

const int MIN_B = 80;

const int MIN_C = 70;

const int MIN_D = 60;

// generate a number bewteen 1 and 100, inclusive

// to determine which letter grade to generate

int whichLetter = rand() % 100 + 1; // 1..100

// Set min and max based on the letter grade

int min, max;

if (whichLetter <= A) {

min = MIN_A;

max = 101;

}

else if (whichLetter <= B) {

min = MIN_B;

max = MIN_A;

}

else if (whichLetter <= C) {

min = MIN_C;

max = MIN_B;

}

else if (whichLetter <= D) {

min = MIN_D;

max = MIN_C;

}

else {

min = 0;

max = MIN_D;

}

// Generate a random score for the chosen letter grade

int score = rand() % (max - min) + min;

return score;

}

void getNumberOfScores(int&n)

{

cout << "How many scores do you want to process: ";

cin >> n;

}

void generateScores(int list[], int n)

{

for (int i = 0; i < n; i++)

{

list[i] = generateOneScore();

}

}

double calcAverage(int list[], int n, bool drop)

{

int min,sum=0;

if (drop)

{

min = findLowest(list, n);

}

int count = 0;

for (int i = 0; i < n; i++)

{

if (drop)

{

if (list[i] != min)

{

sum += list[i];

}

else

++count;

}

else

{

sum += list[i];

}

}

return (double)sum / (n-count);

}

int findLowest(int list[], int n)

{

int min=list[0];

for (int i = 0; i < n; i++)

{

if (min > list[i])

{

min = list[i];

}

}

return min;

}

int findHighest(int list[], int n)

{

int max = list[0];

for (int i = 0; i < n; i++)

{

if (max < list[i])

{

max = list[i];

}

}

return max;

}

int countAboveAverage(int list[], int n, double average)

{

int aboveAvg = 0;

for (int i = 0; i < n; i++)

{

if (list[i] > average)

aboveAvg++;

}

return aboveAvg;

}

void displayScores(int list[], int n)

{

cout << "All scores: " << endl;

for (int i = 0; i < n; i++)

{

if ( (i % 10) >= 1)

{

cout << list[i] << " ";

}

else

{

cout << "\n"<<list[i] << " ";

}

}

}

char findLetterGrade(double grade)

{

char ret;

if (grade >= 90 && grade <= 100)

ret = 'A';

if (grade >= 80 && grade < 90)

ret = 'B';

if (grade >= 70 && grade < 80)

ret = 'C';

if (grade >= 60 && grade < 70)

ret = 'D';

if (grade < 60)

ret = 'F';

return ret;

}

void displayHistogram(int list[], int n)

{

int countA=0, countB=0, countC=0, countD=0, countF=0;

for (int i = 0; i < n; i++)

{

char grade = findLetterGrade(list[i]);

if ( grade == 'A')

++countA;

if (grade == 'B')

++countB;

if (grade == 'C')

++countC;

if (grade == 'D')

++countD;

if (grade == 'F')

++countF;

}

cout << "A: ";

for (int i = 0; i < countA; i++)

{

cout << "*";

}

cout << "\nB: ";

for (int i = 0; i < countB; i++)

{

cout << "*";

}

cout << "\nC: ";

for (int i = 0; i < countC; i++)

{

cout << "*";

}

cout << "\nD: ";

for (int i = 0; i < countD; i++)

{

cout << "*";

}

cout << "\nF: ";

for (int i = 0; i < countF; i++)

{

cout << "*";

}

cout << endl;

}

void displayDuplicateScores(int list[], int n)

{

int score;

struct occurence

{

int number;

int count;

};

struct occurence occurances[100] = { 0 };

for (int i = 0; i < n; i++)

{

score = list[i];

for (int j = 0; j < n; j++)

{

if (score == list[j])

{

occurances[i].number = score;

occurances[i].count++;

}

}

}

cout << "Score occurences counts >1 :" << endl;

int j = 1;

cout << occurances[0].number << ": " << occurances[0].count << " ";

for (int i = 1; i < n; i++)

{

if (occurances[i].count > 1)

{

if (j % 5 >= 1)

cout << occurances[i].number << ": " << occurances[i].count << " ";

else

{

cout << endl;

cout << occurances[i].number << ": " << occurances[i].count << " ";

}

++j;

}

}

}

/*output:

How many scores do you want to process: 100

All scores:

77 80 74 68 74 97 67 71 2 86

24 100 22 86 85 76 78 72 79 84

97 83 74 71 78 74 77 89 81 88

85 42 66 72 78 75 9 70 94 8

83 64 70 76 88 79 83 88 82 81

85 78 98 66 76 85 82 79 63 12

60 76 77 74 82 70 74 70 97 97

77 73 79 91 88 86 96 97 99 75

91 87 73 21 97 56 70 21 79 74

64 79 88 94 87 83 73 91 96 100 Average of all scores: 74.93

Number of scores above this average: 63

Lette grade for all scores: C

Average of all scores without lowest: 75.6667

Number of scores above this average: 61

Minimum of all scores : 2

Maximum of all scores : 100

Displaying histogram for 100 scores:

A: *****************

B: **************************

C: ***************************************

D: ********

F: **********

Score occurences counts >1 :

77: 4 74: 7 74: 7 97: 6 71: 2

86: 3 100: 2 86: 3 85: 4 76: 4

78: 4 72: 2 79: 6 97: 6 83: 4

74: 7 71: 2 78: 4 74: 7 77: 4

81: 2 88: 5 85: 4 66: 2 72: 2

78: 4 75: 2 70: 5 94: 2 83: 4

64: 2 70: 5 76: 4 88: 5 79: 6

83: 4 88: 5 82: 3 81: 2 85: 4

78: 4 66: 2 76: 4 85: 4 82: 3

79: 6 76: 4 77: 4 74: 7 82: 3

70: 5 74: 7 70: 5 97: 6 97: 6

77: 4 73: 3 79: 6 91: 3 88: 5

86: 3 96: 2 97: 6 75: 2 91: 3

87: 2 73: 3 21: 2 97: 6 70: 5

21: 2 79: 6 74: 7 64: 2 79: 6

88: 5 94: 2 87: 2 83: 4 73: 3

91: 3 96: 2 100: 2

Thanks for using Grade Processor application.

*/

Add a comment
Know the answer?
Add Answer to:
Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Use C++ functions and build a program that does the most basic job all students...

    C++ Use C++ functions and build a program that does the most basic job all students have to contend with, process the grades on a test and produce a summary of the results. The big wrinkle is, it should be a multi-file program. -Requires three simple things: Figure out the best score of all scores produced Figure out the worst score of all scores produced Assign a letter grade for each score produced Complete this lab by writing three functions....

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • 1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if...

    1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if the first two characters and the last two characters of the string are the same. It returns false otherwise. In addition, if the string is empty or has only one character, it also returns false. For example, these are the strings with their expected return values false falsc "AB" true "ABA" false "ABAB" trus "ABBA" false "ABCABC false "ABCCAB" true 1.2 Write a function...

  • Using the following parallel array and array of vectors: // may be declared outside the main...

    Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS =3; // may only be declared within the main function string Students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Write a C++ program to run a menu-driven program with the following choices: 1) Display the grades 2) Add grade 3) Remove grade for all students for a selected assignment 4) Display Average for each student 5) Display the name of...

  • C++ Write a program to calculate final grade in this class, for the scores given below...

    C++ Write a program to calculate final grade in this class, for the scores given below . Remember to exclude one lowest quiz score out of the 4 while initializing the array. Display final numeric score and letter grade. Use standard include <iostream> Implementation: Use arrays for quizzes, labs, projects and exams. Follow Sample Output for formatting. May use initialization lists for arrays. Weight distribution is as follows: Labs: 15% Projects: 20% Quizzes: 20% Exams: 25% Final Project: 20% Display...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • Consider the following program that reads students’ test scores into an array and prints the contents of the array. You will add more functions to the program. The instructions are given below.

    Consider the following program that reads students’ test scores into an array and prints the contents of the array.   You will add more functions to the program.  The instructions are given below.              For each of the following exercises, write a function and make the appropriate function call in main.Comments are to be added in the program. 1.       Write a void function to find the average test score for each student and store in an array studentAvgs. void AverageScores( const int scores[][MAX_TESTS],                       int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT