Write a program that reads in a set of positive integers, representing test scor
ID: 3562024 • Letter: W
Question
Write a program that reads in a set of positive integers, representing test scores for a class, and outputs how many times a particular number appears in the list. You may assume that the data set has, at most, 100 numbers and that -999 marks the end of the input data. The numbers must be output in increasing order. For example, for the data:
55 80 78 92 95 55 78 53 92 65 78 95 85 92 85 95 95
the output is:
Test Score
Count
53
1
55
2
65
1
78
3
80
1
85
2
92
3
95
4
Test Score
Count
53
1
55
2
65
1
78
3
80
1
85
2
92
3
95
4
Explanation / Answer
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int main(){
int x,count[100];
for(int i=0;i<100;i++)count[i]=0;
cout << "Enter a number : "<<"-999 for end of input:";
cin>>x;
while(x != -999){
count[x]++;
cout << "Enter a number : "<<"-999 for end of input:";
cin >> x;
}
for(int i=0;i<100;i++){
if (count[i]!=0){
cout <<i<<" "<<count[i]<<" ";
}
}
return 0 ;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.