Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program named ClassifyScores that classifies a series of scores entered

ID: 3850943 • Letter: W

Question

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.

Explanation / Answer

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) + " " + 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! ";
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! ";
}
else
{
int start = 0;
for (int i = 0; i < 10; ++i)
{
cout << start << "-" << (start + 9) << " " << 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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote