Write a C++ Program that: 1. Declares an array of intergers a maximum size(you d
ID: 3556378 • Letter: W
Question
Write a C++ Program that:
1. Declares an array of intergers a maximum size(you decide it)
2. Has a function for the user to initialize the size of the array. (It does not need to be the maximum size)
3. A function that displays the contents of the array
4. One function that calculates the min, max, sum, and avg of all the elements of the array. **You cannot use cout/cin statements in this function. The values must be passed to either main() or to the displayFunction.
5. A function that accepts a number and determines how many times (if any) that number appears in the array.
6. A function that allows the user to input a specified number at a specified location within the currently filled portion of the array.
7. A function that allows the user to remove an element in the array.
Explanation / Answer
// all the required functions have been defined. You can use them in the main function as you want
#include <iostream>
#define N 20
using namespace std;
struct Vals{
int max,min,sum;
float avg;
};
void init(int a[],int s){
for(int i=0;i<s;i++){
a[i] = 0;
}
}
void disp(int a[].int s){
cout<<"Array contents: "
for(int i=0;i<s;i++){
cout<<a[i]<<" ";
}
}
Vals calculate(int arr[],int s){
Vals v;
v.sum = 0;
int mn,mx;
mn = mx = arr[0];
for(int i=0;i<s;i++){
v.sum+=s[i];
if(arr[i]>mx){
mx = arr[i];
}
if(arr[i]<mn){
mn = arr[i]
}
}
v.avg = (float)(v.sum)/(float)s;
v.max = mx;
v.min = mn;
return v;
}
int numTimes(int a[],int s,int n){
int c = 0;
for(int i=0;i<s;i++){
if(a[i]==n)
c++;
}
return c;
}
void fillArray(int a[],int s,int pos,int n){
a[pos] = n;
}
void removeNum(int a[],int s,int n){
for(int i=0;i<s;i++){
if(a[i]==n){
a[i] = s;
return;
}
}
}
int main(int argc, char const *argv[])
{
int arr[N];
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.