Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

User will enter a value (dsize) which represents the number of values to process user enters size numbers in the range of -2147483648 to 2147483647

User will enter a value (dsize) which represents the number of values to process

user enters size numbers in the range of -2147483648 to 2147483647

The values entered will be stored in an array of type long that has 10,000 elements

User will enter a frequency of choice (Frequency, such as 5, or 2500, etc.)

program will count and display the number of values in the array which occurred exactly Frequency times

and display the specific numbers/values which occurred with the user entered value for the Frequency

Examples using a value of 5 for the required frequency

Example: 2, 3, 4, 3, 3, 5, 2, 9, 5 number of values with a frequency of 5 is 0

Example: 10, 1, 8, 5, 1, 5, 4, 1, 5, 1, 1, 1 occurred with a frequency of 5

Example: 10, 11, 11, 3, 10, 10, 10, 11, 10, 11, 11 10 and 11 occurred with a frequency of 5

*/

#include // required header file for input/output

using namespace std;

// prototypes you must use for this assignment

void input_data(long data[], short size);

void display_data (long data[], short size);

short countOfFrequency (long data[], short size, long FreqNumbers[ ], short Frequency);

int main()

{ // declare local variables

long data[10000], FreqNumbers[10000];

short dsize, Fsize, Frequency; // list may not be complete

// display a message to the user about the number of values to store in the array

cin>>dsize;

while (dsize > 0) //pretest loop - will execute while size > 0

{

// output a message to enter the values to be processed

// call the input_data function

// print a message about the number of values stored in the array

// call the display_data function

// print a message to the user that program will count the number of values which occurred in the array for a

// frequency of their choice; ask use to enter a frequency of their choice.

cin>> Frequency;

while (Frequency > 0) // loop to check more than 1 frequency but only 1 at a time

{

// call countOfFrequency function

// display a message about the number of values in the FreqNumbers array which occurred exactly Frequency times

// call the display_data function to print the values stored in the FreqNumbers array

// this function should not be called if no values occurred with the required frequency

// print a message to user that program will count the number of values which occurred in the array for a frequency

// of their choice; ask user to enter a frequency of their choice or 0 to terminate the loop.

cin>>Frequency;

}// end of inner while loop

cout<<"To run the program again, enter the number of values to store in the array or 0 to terminate the program ";

cin>>dsize;

}// end of outer while loop

// pause the program to see the results

//system("pause"); // this is a windows command; will not work in another operating system

// return 0; // optional statement, may be required for .NET compiler

}

//function definitions are placed after main

// Function to display the data in the array

// print all values on the same line with one space between each number

void display_data(long data[], short size)

{ /*code in function*/ }

// Do not output anything in the functions below

// Function to input(store) data into the array

void input_data(long data[], short size)

{ /*code in function*/}

//Function to return the count of the number of values which occurred exactly Frequency times

// store in the FreqNumbers array the actual values which occurred with a specific frequency

// Look at the last example above, you would store the values of 10 and 11 if the requested frequency was 5.

// If the requested frequency was 1 you would store a 3 in the FreqNumbers array.

short countOfFrequency (long data[], short dsize, long FreqNumbers[ ], short Frequency)

{ /*code in function*/}

Possible algorithms (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number.

No global variable are permitted

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Discuss all branches of science

Answered: 1 week ago