[Random Number Generator] Write a program that generates 10 random integers between the boundary from the user input. Display all the random numbers, the greatest value, the smallest value and the average of the random numbers. Requirement: Input Validation: Do not accept the lower bound value is greater or equal to the higher bound. Or simply switch the low and high values. Write functions to generate the random numbers and store in an array, find the greatest value, the smallest value and average from the array. Display the programmer info at the beginning of the output Include the function prototypes before the main() All functions definitions should be after the main() Required function headers: void showValues(const int a[], int size); // display the content of the array void fillArray(int a[], int size, int low, int higt); // fill up array elements between low and high int maximum(const int a[], int size); // return the highest value from the passing array int minimum(const int a[], int size); // return the lowest value from the passing array double average(const int a[], int size); // return the average of the passing array

Respuesta :

Answer:

#include<iostream>

#include<cstdlib>

#include<ctime>

using namespace std;

void showValues(const int a[], int size);

void fillArray(int a[], int size, int low, int high);

int maximum(const int a[], int size);

int minimum(const int a[], int size);

double average(const int a[], int size);

int main(){

int size = 10;

int low,high;

cout<<"Low: ";

cin>>low;

cout<<"High: ";

cin>>high;

if(high<low){

high = high + low;

low = high - low;

high = high - low;

}

int a[size];

//Enter your details here e.g. cout<<"Name: Programmer XYZ"

fillArray(a, size, low, high);

showValues(a, size);

cout<<"Maximum: "<<maximum(a, size)<<endl;

cout<<"Minimum: "<<minimum(a, size)<<endl;

cout<<"Average: "<<average(a, size)<<endl;

}

void fillArray(int a[], int size, int low, int high){

unsigned seed = time(0);

  srand(seed);

for (int j = 0;j<size;j++){

 a[j]=low + rand() % (( high+ 1 ) - low);  

}

}

void showValues(const int a[], int size){

for(int i =0;i<size;i++){

cout<<a[i]<<" ";

}

cout<<endl;  

}

int maximum(const int a[], int size){

int max = a[0];

for(int i =1;i<size;i++){  

if(a[i]>max){

 max = a[i];

}

}  

return max;

}

int minimum(const int a[], int size){

int min = a[0];

for(int i =1;i<size;i++){  

if(a[i]<min){

 min = a[i];

}

}  

return min;

}

double average(const int a[], int size){

double total = a[0];

for(int i =1;i<size;i++){  

total+=a[i];

}

return total/size;

}

Explanation:

This solution is implemented in C++. The source code is a bit length. So, I added the explanation as an attachment of the source file where I used comments to explain some lines.

Ver imagen MrRoyal
ACCESS MORE