Question: In C++ Write a program that reads in a list of integers into an array with base type int. Provide the facility to either read
In C++
Write a program that reads in a list of integers into an array with base type int. Provide the facility to either read this array from the keyboard or from a file, at the users option. If the user chooses file input, the program should request a file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be a 2-column list. The first column is a list of the distinct array elements; the second column is the count of the number of occurrences of each element. You need to output the result in a file and on the screen.
Example:
For example, for the input
-3 4 1 1 3 4
the output should be
N Count
4 2
3 1
1 2
-3 1
Algorithm/Pseudo-code
1) You need three integer arrays to solve this exercise: inputArray, uniqueArray, countArray. An integer variable size is used to keep track of how many elements are in inputArray.
2) Read the integers into inputArray. The number of elements is saved in variable size.
3) Sort the input array in ascending order.
4) Initialize the elements in countArray to be zero.
for (int i = 0; i < size; i++)
5) {
for each element in inputArray, check if it is there in uniqueArray
already, if so, increment the countArray by 1
if not, copy the element to uniqueArray and set countArray to be 1
}
6) output in the desired format
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
