Coded in C++; Visual Studios 2013 Write a program that will prompt the user for
ID: 3786019 • Letter: C
Question
Coded in C++; Visual Studios 2013
Write a program that will prompt the user for the number of elements in a data set of integers. You will then allocate a 1d array of that size and fill this array from the keyboard (test with small data sets and use redirected input). After the array, has been filled from the keyboard you will find the min and max of that data set and output them to the screen. Before you exit the program, free the memory up. You are guaranteed that the size of the data set will be positive and greater than 3. Write a function that has parameters of the array and the number of elements in the array. This function should return the minimum value within the array. A sample of the function call would look like: minval = min(arr, size); Write a function that has parameters of the array and the number of elements in the array. This function should return the maximum value within the array. A sample of the function call would look like: maxval = max(arr, size); A typical run of your program may look like this. My input is In red. Enter the number of elements in your data set: 10 30 40 25 16 20 -6 14 99 4321 876 The Minis 6 The Max is 4321Explanation / Answer
#include<iostream>
using namespace std;
int minval(int *arr,int sze)
{
int min=arr[0];
int i;
for(i=1;i<sze;i++)
{
if(min>arr[i])min=arr[i];
}
return min;
}
int maxval(int *arr,int sze)
{
int max=arr[0];
int i;
for(i=1;i<sze;i++)
{
if(max<arr[i])max=arr[i];
}
return max;
}
int main()
{
cout<<"Enter the number of elements in your data set:";
int noElement;
cin>>noElement;
int *arr=new int[noElement];
int i;
for(i=0;i<noElement;i++)
cin>>arr[i];
int min=minval(arr,noElement);
int max=maxval(arr,noElement);
cout<<"The Min is "<<min<<" ";
cout<<"The Max is "<<max;
delete [] arr;
return 0;
}