Question
C++ help Program asks user to enter a number N that is supposed to be from 1 to 50. The program reads all numbers from
C++ help
Program asks user to enter a number N that is supposed to be from 1 to 50.
The program reads all numbers from a file named "numbers.txt". The number values are between 1 and 50. While reading each number from the input file, program keeps track of the occurrences (frequency counts) of each number whose value is 1 to N and store the frequency in an array (size N). Program reads but does not process number that is larger than N. The frequency of a number is the count of how many times the number occurs. Program should NOT store the numbers it reads from the file because there is no need to and there are too many numbers.
You must have the following Functions in the program:
int main()
Ask user to enter input N
Define and inititalize the array of size N
Open the file numbers.txt as input
Calls the 3 functions below
Display the output results
int readNumbersAndCount(int occurrences[ ], int size, ifstream &infile);
Function to read all the numbers in input file using a loop
Keep track of the occurrence of each number if it is < or equal N using the array parameter
Read but do no process numbers that are greater than N
Does not print any thing (main function does the printing)
Return the count of numbers that have value from 1 to N
void printCounts(int occurrences[ ], int size);
Print the values of the occurrence counts in the array using a loop
void findMostAndLeastOccurrence(int occurrences[ ], int size, int &most, int &least);
Find the number with the most and the number with the least occurrence in the array
Does not print any thing (main function does the printing)
Hint:
You should store the frequency of 1 in the first element of the frequency array, frequency of 2 in the second element of array,....
Use simple arithmetic expression to calculate the array subscript from the number that is read from file. Do not use a gigantic if statement to get the array subscript.
Remember the rules about array subscript range.
There should be only ONE array of size N (value is 1 to 50) to be defined in main(). The array is passed as a parameter to other functions.
You should use function prototypes.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started