Question

In: Computer Science

Create a C++ program that will accept any number of grades for an exam. The grades...

Create a C++ program that will accept any number of grades for an exam. The grades will be input as 4 for an A, 3 for a B, 2 for a C, 1 for a D, and 0 for an F. After all grades have been entered, allow the user to enter -1 to exit. Output the number of grades in each category. Using arrays.

Solutions

Expert Solution

#include <iostream>
using namespace std;

int main() {
int grades[5] = {0, 0, 0, 0, 0}; // declaring grades for ABCDF
char letters[5] = {'F', 'D', 'C', 'B', 'A'}; // grades
  
int g; // taking input of a grade
cout << "Enter grades one by one (-1 to stop):\n";
cin >> g;
  
while(g != -1) // as long as grade is not -1, taking input
{
grades[g]++; // incrementing the respective grade by 1
cin >> g;
}
  
for(int i=4; i>=0; i--) // printing output
cout << endl << "# of Grade " << letters[i] << "'s: " << grades[i];
}

// -------- Hit the thumbs up if you are fine with the answer. Happy Learning!


Related Solutions

Create a C++ program which will accept an unlimited number of scores and calculates the average...
Create a C++ program which will accept an unlimited number of scores and calculates the average score. You will also need to prompt for the total points possible. Assume each test is worth 100 points. Requirements. • Enter the Student ID first, then prompt for grades. Keep prompt- ing for grades until the client enters ’calc’. That triggers final pro- cessing. • Make your code as reliable as possible. • Make your program output easy to read. • You cannot...
Modify Java program to accept a telephone number with any numberof the letters, using the...
Modify Java program to accept a telephone number with any number of the letters, using the if else loop. The output should display a hyphen after the first 3 digits and subsequently a hyphen (-) after every four digits. Also, modify the program to process as many telephone numbers as the user wants.
Develop a rudimentary Java program that will allow anyone to enter any number of grades and...
Develop a rudimentary Java program that will allow anyone to enter any number of grades and then calculate grade point average. For reference, a grade point average is a weighted average of a set of grades based on the relative number of credits. For example, a 1 credit “A” (4.0) should count twice as much as a .5 credit “C” (3.0), and a 1.5 credit “A+”(4.33) should count three times as much as the “C” and 1.5 times as much...
DO IN C++ Secret Codes! Create a program that will accept a message from the user...
DO IN C++ Secret Codes! Create a program that will accept a message from the user and either encrypt ordecrypt it with the following algorithms: To encrypt: - get the character you wish to encrypt - find the index of that character in the alphabet array - add the shift offset to the index - add the increment to the index - "wrap around" the new index so the result is between 0 and 29 - find the character at...
Create a working C# Program that will accept an input and has the following class. areaCircle...
Create a working C# Program that will accept an input and has the following class. areaCircle – computes the area of the circle volumeCube – computes the volume of a cube perimeterTraingle – computes the perimeter of a triangle surfaceAreaRect – computes the surface area of a rectangle *You may usePass by Value and/or Pass by Reference *Using ConsoleApp
: Create a Java program that will accept a regular expression and a filename for a...
: Create a Java program that will accept a regular expression and a filename for a text file. The program will process the file, looking at every line to find matches for the regular expression and display them. Regular Expression Format : The following operators need to be accepted: + - one or more of the following character (no groups) * - zero or more of the following character (no groups) [] – no negation, no character spans – the...
Create an Java application that uses a class to convert number grades to letter grades and...
Create an Java application that uses a class to convert number grades to letter grades and another class for data validation. Specifications The Grade class should have only one Instance Variable of type int. Use a class named Grade to store the data for each grade. This class should include these three methods:   public void setNumber(int number)   public int getNumber()   public String getLetter() The Grade class should have two constructors. The first one should accept no parameters and set the...
c ++ program that converts from any base to a decimal number
c ++ program that converts from any base to a decimal number
Create a program in C that counts the number of characters in a word when a...
Create a program in C that counts the number of characters in a word when a user inputs a string. Use stdin to read an input string. For example, if a user inputs: “The dog is good” the output should be a= [The], b=3 a= [dog], b=3 a= [ is], b=2 a= [good], b=4 a= [ ], b=0000 Take into account EOF. If an EOF is reached at the end of the string then the output should be 0000. (example...
Create a program in C that counts the number of characters in a word when a...
Create a program in C that counts the number of characters in a word when a user inputs a string. Use stdin to read an input string. For example, if a user inputs: “The dog is good” the output should be a= [The], b=3 a= [dog], b=3 a= [ is], b=2 a= [good], b=4 a= [ ], b=0000 Take into account EOF. If an EOF is reached at the end of the string then the output should be 0000. (example...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT