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

Write a program that reads in a set of positive integers and outputs how many ti

ID: 3543991 • Letter: W

Question

Write a program that reads in a set of positive integers and outputs how many times a particular number appears in the list. Assume that the data set has at most 100 numbers and -999 marks the end of the input data. The numbers must be output in increasing order. For example, for the data


15 40 28 62 95 15 28 13 62 65 48 95 65 62 65 95 95 -999


the output is


Number                        Count

13                                 1

15                                 2

28                                 2

40                                 1

48                                 1

62                                 3

65                                 3

95                                 4

Explanation / Answer

#include "iostream"

using namespace std;


int main()

{

const int array_size = 100;

int array[array_size];

int i = 0;

int number;

int c;


for(int c = 0;c < array_size; c++)

{

array[c] = 0;

}

cout << "Enter the sequence of digits: " ;

while((cin >> number) && (number >= 0) &&(number!=-999))

{

if(number >=array_size)

{

cout << "Input: " << number << " is out ofrange. ";

continue;

}

array[number]++;

i++;

}

cout << "The digit frequency counts: " << " ";

for(c=0;c < array_size; c++)

{if(array[c]!=0)

cout << " Digit " << c<< " has frequency " << array[c] <<" ";

}

system ("PAUSE");

return 0;


}





Comment

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