12.6k views
3 votes
Write a program to read a list of exam scores given as integer percentages in the range 0 to 100. Display the total number of grades and the number of grades in each letter-grade category as follows: 90 to 100 is a A, 80 to 89 is a B, 70 to 79 is a C, 60 to 69 is a D, and 0 to 59 is an F. Use a negative score as a sentinel value to indicate the end of the input. (The negative value is used only to end the loop, so do not use it in the calculations.) For example, if the input is 98 87 86 85 85 78 73 72 72 72 70 66 63 50 -1 the output would be Total number of grades = 14 Number of A's = 1 Number of B's = 4 Number of C's = 6 Number of D's = 2 Number of F's = 1

2 Answers

0 votes

Answer:

# user is prompt to enter a grade

grade = int(input("Enter your grade: "))

# empty list to hold user grades is declared

grade_list = []

# counter for A grade is initialised to 0

numberOfA = 0

# counter for B grade is initialised to 0

numberOfB = 0

# counter for C grade is initialised to 0

numberOfC = 0

# counter for D grade is initialised to 0

numberOfD = 0

# counter for F grade is initialised to 0

numberOfF = 0

# while loop that continue to receive

# user input as long as it is not -1

# it append each grade into the grade list

while (grade != -1):

grade_list.append(grade)

grade = int(input("Enter your grade: "))

# for loop that goes through

# the grade list and increment

# the respective grade based on

# the interval it fall

for each_grade in grade_list:

if(each_grade >= 90 and each_grade <= 100):

numberOfA += 1

elif(each_grade >= 80 and each_grade < 90):

numberOfB += 1

elif(each_grade >= 70 and each_grade < 80):

numberOfC += 1

elif(each_grade >= 60 and each_grade < 70):

numberOfD += 1

elif(each_grade >= 0 and each_grade < 60):

numberOfF += 1

# total grade is displayed to the user

print("Total number of grades = ", len(grade_list))

# number of A's is displayed to user

print("Number of A's = ", numberOfA)

# number of B's is displayed to user

print("Number of B's = ", numberOfB)

# number of C's is displayed to user

print("Number of C's = ", numberOfC)

# number of D's is displayed to user

print("Number of D's = ", numberOfD)

# number of F's is displayed to user

print("Number of F's = ", numberOfF)

Step-by-step explanation:

The program is written in Python and is commented.

It asked for user input. Then it continues to receive input as long as it is not -1. It append each input to a list.

It then loop through the list and increment the correct counter for each grade.

It then display the total number of grade inputted and the number of various grade.

User RazorHead
by
4.4k points
5 votes

Answer:

I am writing a C++ program.

#include <iostream> //to use input output functions

using namespace std; //to identify objects such as cout, cin

int main(){//start of main() function body

/*integer type variables A B C D and F are used to store the number of grades in each category example 90 to 100 is a A so its stored in A variable*/

int A = 0;

int B = 0;

int C = 0;

int D = 0;

int F = 0;

int total_grades=0; //counts and stores the total number of grades

//prompts user to enter exam scores

cout<<"Enter exam scores as integer percentages from 0 to 100:\\";

int exam_score; // stores exam scores entered by user

cin>>exam_score; // reads exam scores input by user

/* while loop continues to count the total number of grades and grades in each letter grade category until the user enters a negative value to end loop */

while(exam_score>0){ //iterates till value of score is greater than 0

//increments the value of total_grades by 1 every time user enters the grade

total_grades++;

/*if condition checks if the value of exam_score is in the specified range of each grade category and increments that grade variable accordingly*/

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

A++;

else if(exam_score>=80 && exam_score<=89)

B++;

else if(exam_score>=70 && exam_score<=79)

C++;

else if(exam_score>=60 && exam_score<=69)

D++;

else if(exam_score>=0 && exam_score<=59)

F++;

cin>>exam_score; }

/*when the loop ends the total number of grades and number of grades in each letter grade category is displayed*/

cout<<"Total number of grades :"<<total_grades<<endl;

cout<<"Number of A's: "<<A<<endl;

cout<<"Number of B's: "<<B<<endl;

cout<<"Number of C's: "<<C<<endl;

cout<<"Number of D's: "<<D<<endl;

cout<<"Number of F's: "<<F<<endl;

}

Step-by-step explanation:

The program first prompts the user to enter the exam scores. The while loop begins which keeps counting the number of grades and stores it in total_grades variable. Then the if condition checks for each letter grade category and counts the grades in each letter grade accordingly. For example if the exam score entered by user is between 90 to 100 then this means that the letter grade category is A , so the value of A is incremented by 1. The loop continues to execute until the user enters a negative value. For example if the user enters -1, then the loop breaks. At the end the total number of grades and the number of grades in each letter grade category which are computed in the while loop are displayed as output.

Write a program to read a list of exam scores given as integer percentages in the-example-1
Write a program to read a list of exam scores given as integer percentages in the-example-2
User Ughzan
by
4.7k points