Answer to Question #265544 in C++ for Usama

Question #265544

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


1
Expert's answer
2021-11-17T17:40:18-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS