Question

Write a program named ClassifyScores that classifies a series of scores entered by the user into...

Write a program named ClassifyScores that classifies a series of scores entered by the user into ranges (0-9, 10-19, and so forth). The scores will be numbers between 0 and 100.

Design and implement a program to prompt the user to enter each score separately.

If the score is within the correct range, then increment the appropriate range

If the score entered is greater than 100, display an error message, ignore the incorrect score, and prompt for the user to enter the next score.

If the score entered is less than 0, the program should display the result and terminate.

For example, if the user enters 1 score between 20 and 29, 2 scores between 40 and 49, 3 scores between 50 and 59, etc. The program should display the following.

                                Range Number of scores

   0-9                0

10-19                 0

20-29                 1                     

30-39                 0

40-49                 2

50-59                 3

60-69                 1

70-79                 7

80-89                 5

90-100               3

Hint: Create an array with 10 elements, one for each range. When each score is entered, increment the appropriate array element. The array index for each range can be calculated by (score / 10). Please note that when the score is 100, the appropriate array index cannot be calculated this way.

Note: The user of your program can enter as many scores as (s)he wishes. The user identifies the end by entering a negative number for score; your program then should display the tabulated scores and exit.

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

Java code:

create a file name Score.java and paste given code into it!

import java.util.Scanner;
import java.lang.*;
public class Score {

    public static void main(String[] args)
    {
   
    int v[]=new int[10];
    for (int i = 0; i < 10; ++i)
    {
        v[i] = 0;
    }
    while(true)
    {
        System.out.println("Enter the Score between 0 and 100!");
        int s ;
        Scanner scanner = new Scanner(System.in);
        s = scanner.nextInt();
        if(0<= s && s <= 100)
        {
            if(0 <= s && s <= 9 )
            {
                v[0] = v[0] + 1;
            }
            else if(10 <= s && s <= 19 )
            {
                v[1] = v[1] + 1;
            }
            else if(20 <= s && s <= 29 )
            {
                v[2] = v[2] + 1;
            }
            else if(30 <= s && s <= 39 )
            {
                v[3] = v[3] + 1;
            }
            else if(40 <= s && s <= 49 )
            {
                v[4] = v[4] + 1;
            }
            else if(50 <= s && s <= 59 )
            {
                v[5] = v[5] + 1;
            }
            else if(60 <= s && s <= 69 )
            {
                v[6] = v[6] + 1;
            }
            else if(70 <= s && s <= 79 )
            {
                v[7] = v[7] + 1;
            }
            else if(80 <= s && s <= 89 )
            {
                v[8] = v[8] + 1;
            }
            else if(90 <= s && s <= 100 )
            {
                v[9] = v[9] + 1;
            }

        }
        else if(s > 100)
        {
            System.out.println("Please enter the Score between 0 and 100!");
        }
        else
        {
            int start = 0;
            for (int i = 0; i < 10; ++i)
            {
                System.out.println(start + "-" + (start + 9) + "\t\t" + v[i]);
                start = start + 10;
            }
            break;
        }
    }

   
   
    }
   
}

C++ code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
vector<int> v(10);
for (int i = 0; i < 10; ++i)
{
v[i] = 0;
}
while(true)
{
cout << "Enter the Score between 0 and 100!\n";
int s ;
cin >> s;
if(0<= s and s <= 100)
{
if(0 <= s and s <= 9 )
{
v[0] = v[0] + 1;
}
else if(10 <= s and s <= 19 )
{
v[1] = v[1] + 1;
}
else if(20 <= s and s <= 29 )
{
v[2] = v[2] + 1;
}
else if(30 <= s and s <= 39 )
{
v[3] = v[3] + 1;
}
else if(40 <= s and s <= 49 )
{
v[4] = v[4] + 1;
}
else if(50 <= s and s <= 59 )
{
v[5] = v[5] + 1;
}
else if(60 <= s and s <= 69 )
{
v[6] = v[6] + 1;
}
else if(70 <= s and s <= 79 )
{
v[7] = v[7] + 1;
}
else if(80 <= s and s <= 89 )
{
v[8] = v[8] + 1;
}
else if(90 <= s and s <= 100 )
{
v[9] = v[9] + 1;
}

}
else if(s > 100)
{
cout << "Please enter the Score between 0 and 100!\n";
}
else
{
int start = 0;
for (int i = 0; i < 10; ++i)
{
cout << start << "-" << (start + 9) << "\t\t" << v[i] << endl;
start = start + 10;
}
break;
}
}
return 0;
}

Sample Output:

Enter the Score between 0 and 100!
5
Enter the Score between 0 and 100!
6
Enter the Score between 0 and 100!
7
Enter the Score between 0 and 100!
88
Enter the Score between 0 and 100!
89
Enter the Score between 0 and 100!
87
Enter the Score between 0 and 100!
55
Enter the Score between 0 and 100!
56
Enter the Score between 0 and 100!
57
Enter the Score between 0 and 100!
101
Please enter the Score between 0 and 100!
Enter the Score between 0 and 100!
-1
0-9 3
10-19 0
20-29 0
30-39 0
40-49 0
50-59 3
60-69 0
70-79 0
80-89 3
90-99 0

Add a comment
Know the answer?
Add Answer to:
Write a program named ClassifyScores that classifies a series of scores entered by the user into...
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
  • Write a program that allows the user to enter a series of exam scores. The number...

    Write a program that allows the user to enter a series of exam scores. The number of scores the user can enter is not fixed; they can enter any number of scores they want. The exam scores can be either integers or floats. Then, once the user has entered all the scores they want, your program will calculate and print the average of those scores. After printing the average, the program should terminate. You need to use a while loop...

  • Question: - write a C++ program that asks user to enter students' quiz scores, calculate the...

    Question: - write a C++ program that asks user to enter students' quiz scores, calculate the total score for each students and average for all. Note: - number of students: 1 through 5. That is, at least one student and up to 5. - number of quizes: 8 through 10. That is, at least 8 quizes and up to 10. - quiz score range: 0 through 100. - when entering quiz scores, if user enters -1, that means the user...

  • Write a short C++ program that prompts the user for a series of ten scores in...

    Write a short C++ program that prompts the user for a series of ten scores in the range of  0-10 and adds them into a total. Check to make sure the numbers that are entered are actually in the proper 0-10 range. If a 10 is entered then add the ten to the total then double the total to that point.   If a 5 is entered then add five to the total then divide the total by 2 (throwing away any remainders)...

  • 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...

  • In C++ 2. Write a program that allows the user to enter a series of positive...

    In C++ 2. Write a program that allows the user to enter a series of positive numbers between 1 and 100 and displays the smallest and largest of the numbers entered. The program should not store the numbers that were entered, only keep track of the smallest and largest ones. The program should continue accepting numbers until the value 0 is entered and then display the results. If a number out of range is entered, tell the user it is...

  • (Statistics) a. Write a C++ program that reads a list of double-precision scores from the keyboard...

    (Statistics) a. Write a C++ program that reads a list of double-precision scores from the keyboard into an array named scores. It is assumed that the user will enter no more than 35 scores. The scores are to be counted as they're read, and entry is to be terminated when a negative value has been entered. After all scores have been input, your program should find and display the sum and average of the scores. The scores should then be...

  • Write a Python program that asks the user to type in their three quiz scores (scores...

    Write a Python program that asks the user to type in their three quiz scores (scores between 0 and 100) and displays two averages. The program should be written so one function gets the user to input a score, another function takes the three scores and returns the average of them. And another function takes the three scores and averages the two highest scores (in other words, drops the lowest). Each of these functions should do the computation and return...

  • Write a program that will ask the user to enter 4 quiz scores. These scores should...

    Write a program that will ask the user to enter 4 quiz scores. These scores should be from 0 to 100. Use a procedure and pass by reference to get these scores. Write a function that will find the lowest score. This score will be sent back through the function call. You still need to pass the scores by value to this function. Write a function that will calculate the average score. This value will be sent back to main...

  • This program will ask the user to enter a number of players, then ask the user...

    This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...

  • All scores entered into the program must be validated. In order to do this, the program...

    All scores entered into the program must be validated. In order to do this, the program needs to know the range of point available, from zero to the maximum possible score (MaxScore). To do this, implement the form's load-event handler. It should use an input box to get the MaxScore (i.e. total points available) value from the user. This MaxScore value must be validated, using a separate function, as an integer that is greater than zero before being accepted. The...

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