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

Write a correct and complete C++ program that inputs 5,000 integer values from t

ID: 3783733 • Letter: W

Question

Write a correct and complete C++ program that inputs 5,000 integer values from the user and performs three calculations. In the main function, input the values from the user. As part of your answer, write a sub-function, named calcAvg(), which takes two arguments and returns the average of all the integers. Also write another sub-function, named reverseArray(), which takes two arguments and reverses the order of the numbers. That is, for example, if the input numbers were 5, 3, 7, then reverseArray would change the order or 7, 3, 5. Include a final sub-function, named printArray (), which takes two arguments and prints the array. Assumptions to be made: you do not have to check errors in the input values, i.e., all input values can be stored as type int.

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;
float calcavg(int n1,int n2)
{
   float avg;
   avg=(n1+n2)/2.0;
   return avg;
}
int reverseArray(int arr[],int size)
{ int l=0;
int r=size-1;
int temp;
   while(l<r)
   { temp=arr[l];
   arr[l]=arr[r];
   arr[r]=temp;
   l++;r--;
     
   }
}
int printArray(int arr[],int size)
{
    for(int i=0;i<size;i++)
    {
        cout<<arr[i]<<" ";
   }
}
int main()
{
   cout<<"enter the number";
   int num1,num2;
   cin>>num1;
   cin>>num2;
   cout<<"average value of two argument is: "<<calcavg(num1,num2);
   cout<<endl;  
   int arr[]={5,3,7};
   int size=sizeof(arr)/sizeof(arr[0]);
   reverseArray(arr,size);

   printArray(arr,size);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote