Write a program in C++ 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 following data, the output is: 55 80 78 92 95 55 78 53 92 65 78 95 85 92 85 95 95
#include <iostream>
using namespace std;
int main(){
int freq[101];
int array[100];
cout<<"Enter test scores (enter a negative value to stop)\n";
int count = 0;
for(int i = 0; i < 101; i++){
freq[i] = 0;
}
while(count < 100){
cin>>array[count];
if(array[count] > 100) break;
if(array[count] < 0) break;
freq[array[count]]++;
count++;
}
cout<<"\nNumbers and number of times they occur in increasing order\n";
for(int i = 0; i < 101; i++){
if(freq[i]){
cout<<i<<" : "<<freq[i]<<endl;
}
}
return 0;
}
Comments
Leave a comment