Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem: Array Traversal, Searching Write a set of C++ programs to implement the following operations listed in the following: Fill the array with random values

Problem: Array Traversal, Searching

Write a set of C++ programs to implement the following operations listed in the following:

  1. Fill the array with random values
  2. Calculate the sum of all array values
  3. Calculate the average value of array elements
  4. Find maximum value in array
  5. Find minimum value in array
  6. Display the array values
  7. Frequency count of the array values

Specific details:

Implement the following functions:

  1. Fill the array with random values : 1000 numbers between LOWEST_NUMBER and HIGHEST_NUMBER. Examples include 0..9, or 50-80
  2. Sum array elements write a function that calculates and returns the sum of array values.
  3. Average value of array elements write a function that calculates and returns the average value of array elements.
  4. Find maximum value in array write a function that finds and returns the largest value in the array. Perform a linear search of all array elements to find the maximum value. Do not sort the array.
  5. Find minimum value in array write a function that finds and returns the smallest value in the array. Perform a linear search of all array elements to find the minimum value. Do not sort the array.
  6. Display the array values nicely format the output so that there are 10 numbers per row and multiple rows. Use spaces in between numbers:

9 1 2 2 3 3 4 5 2 7

0 1 1 2 8 9 9 8 2 1

  1. Create a function that displays a frequency count of randomly generated numbers.

Process

Create an array to store the frequency count of each number generated. A frequency count is a total count of the number of 0s, 1s, 2s, 3s, , 8s, 9s

Count how many times each number is generated. Find the most frequently generated number. If more than one number has the highest count, use the first one found.

Frequency Count Array

When counting numbers, take advantage of C++s array indexing scheme.

  • How many elements does the frequency count array require? (Hint: what is the range of random number values?)
  • Where is a good place to store the count of 0s? 1s? 2s

EXAMPLE

// Example program #include  #include  #include  // Random support using namespace std; void fillRandomArray(int Array[], int count, int max_random); int sumArray(int Array[], int count); float averageArray(int Array[], int count); int minArray(int Array[], int count); int maxArray(int Array[], int count); void printArray(int Array[], int count); void countFrequencyArray(int Array[], int count); void fillRandomArray(int Array[], int count, int lowest_number, int highest_number) { int range = highest _ number - lowest _ number +1 ); for (index=0 ; inde+ count;index =index+1){ Array[index]=round()%range + lowest; int max= Array [o]; for (int index =0 ; index< n; index =index +1 ){ if Array [index]> min){ min = Array[index]; int Xmax; return max; } } int sumArray(int Array[], int count) { int sum = 0; for (int index=0 ; index < count ; index = index+1); cout<< Array(sum)<< endl; } float avarageArray(int Array[], int count); { return 0; } int minArray(int Array[],int count); { } float averageArray(int Array[], int count) { return 0; } int minArray(int Array[], int count) { return 0; } int maxArray(int Array[], int count) { return 0; } void printArray(int Array[], int count) { } void countFrequencyArray(int Array[], int count, int lowest_number, int highest_number ){ } #ifndef MAX_RANDOM_NUMBER #define MAX_RANDOM_NUMBER 10 #endif #ifndef LOWEST_NUMBER #define LOWEST_NUMBER 0 #endif #ifndef HIGHEST_NUMBER #define HIGHEST_NUMBER 9 #endif #ifndef ARRAY_SIZE #define ARRAY_SIZE 100 #endif int main() { int data[ARRAY_SIZE]; srand(23); // Use a number to "seed" random number generator // Generate random numbers fillRandomArray(data,ARRAY_SIZE,LOWEST_NUMBER, HIGHEST_NUMBER); // Print random numbers : 10 per row printArray(data,ARRAY_SIZE); // Output details about the array cout << "Sum value: " << sumArray(data,ARRAY_SIZE) << " "; cout << "Average value: " << averageArray(data,ARRAY_SIZE) << " "; cout << "Min value : " << minArray(data,ARRAY_SIZE) << " "; cout << "Max value : " << maxArray(data,ARRAY_SIZE) << " "; // Generate the frequency array countFrequencyArray(data,ARRAY_SIZE); return 0; }

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: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago

Question

d. How were you expected to contribute to family life?

Answered: 1 week ago

Question

e. What do you know about your ethnic background?

Answered: 1 week ago