Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Top of Form in C++ Processing an Array with Functions Objectives: Define an arra

ID: 3864367 • Letter: T

Question

Top of Form in C++

Processing an Array with Functions

Objectives:

Define an array to store data (use random numbers this week)

Design and code a function to generate random data in an array

Design multiple functions to process the data in the array

Design and code a function to print the data from the array

Instructions:

In this lab, you will be processing an array of 25 random numbers between 1-100 (do not use srand command so all results are the same). You will be required to write functions to:

Generate random numbers in the array

Find and print the highest value in the array and its position in the array

Find and print the lowest number in the array and its position in the array

Find the average of the values in the array – return the value to main

Print the array position, the value in the array, and its difference from the average for all 25 positions in the array. Put a heading on the top of this table of information.

Table Format:

Position Value Difference from the Average

0 ? +/- ???

1 ? +/- ???

Data:

Random numbers

Run: Run the program and be sure to check the results to see if they are correct.

Explanation / Answer

#include<iostream>
#include<cstdlib>
using namespace std;
void insertData(int *arr){
   cout<<"Entered 25 random number : ";
   for(int i=0;i<25;i++){
       arr[i]=rand()%100+1;
       cout<<arr[i]<<" ";
   }
   cout<<endl;
}
void highestValue(int *arr){
   int max=arr[0];
   int index=0;
   for(int i=1;i<25;i++){
       if(arr[i]>max){
           max=arr[i];
           index=i;
       }
   }
   cout<<"Max Value : "<<max<<" at index : "<<index;
}
void lowestValue(int *arr){
   int min=arr[0];
   int index=0;
   for(int i=1;i<25;i++){
       if(arr[i]>min){
           min=arr[i];
           index=i;
       }
   }
   cout<<" Min Value : "<<min<<" at index : "<<index;
}
double avgValue(int *arr){
   int avg=0;
   for(int i=0;i<25;i++)
       avg+=arr[i];
   return avg/25.0;
}
int main(){
   int *arr = new int[25];
   insertData(arr);
   highestValue(arr);  
   lowestValue(arr);
   cout<<" Average Value : "<<avgValue(arr);  
  
}