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

I need C++ Code that does instructions 1-4. Don\'t worry about 3. or 4 though. 1

ID: 3686990 • Letter: I

Question

I need C++ Code that does instructions 1-4. Don't worry about 3. or 4 though.

1. A void function ReadArray that has an array parameter double inArray[] and an integer parameter numValues that prints out a prompt telling the user to enter numValues double elements, reads in those values, and stores them in inArray.

2. A void function PrintArray that as an array parameter double dataArray[],an integer parameter numValues, and an integer value maxLine that prints out the first numValues of dataArray[] with maxLine values per line.

3. A double function minMax with an array parameter double dataArray[], an integer parameter numValues that is the size of the array dataArray[], a double parameter minVal that is a reference parameter that returns the minimum value of the array . The function should return the maximum value of dataArray[].

4. A void functions reverseArray with an array parameter double dataArray[], an integer parameter numValues that is the size of the array dataArray[] , and another array parameter double reversedArray[] that will return the values of dataArray[] in reverse order.

The general structure of what I think the code would look like a little.

#include< iostream >
using std::cin; using std::cout; using std::endl;

void main(){ int n; double max, minVal;

cout << " Enter the number of elements in the data array";

cin >> n; double * dataArray;

dataArray = new double[n];

ReadArray(dataArray,n); max=minMax(dataArray,n,minVal);

cout << "The maximum value of the array is " << max << " and the minimum value of the array is " << minVal << endl; double * reversedArray;

reversedArray = new double[n];

reverseArray(dataArray,n,reversedArray);

cout << "The array in reverse order is" << endl; PrintArray(reversedArray,n,10);

}

Explanation / Answer

#include<iostream>

using namespace std;

// function prototype
void ReadArray(double inArray[], int numValues);
void PrintArray(double dataArray[], int numValues, int maxLine);
double minMax(double dataArray[], int numValues, double &minVal);
void reverseArray(double dataArray[],int numValues, double reversedArray[]);

int main(){ int n; double max, minVal;

   cout << " Enter the number of elements in the data array";

   cin >> n; double * dataArray;

   dataArray = new double[n];

   ReadArray(dataArray,n); max=minMax(dataArray,n,minVal);

   cout << "The maximum value of the array is " << max << " and the minimum value of the array is " << minVal << endl; double * reversedArray;

   reversedArray = new double[n];

   reverseArray(dataArray,n,reversedArray);

   cout << "The array in reverse order is" << endl; PrintArray(reversedArray,n,10);
  
   return 0;

}

// functions definations
void ReadArray(double inArray[], int numValues){
   cout<<"Enter double "<<numValues<<" : "<<endl;
   for(int i=0; i<numValues; i++)
       cin>>inArray[i];
}

void PrintArray(double dataArray[], int numValues, int maxLine){
  
   int count = 0;
   for(int i=0; i<numValues; i++){
       cout<<dataArray[i]<<" ";
       count++;
       if(count == maxLine){ // printing new line
           count = 0;
           cout<<endl;
       }
   }
}

double minMax(double dataArray[], int numValues, double &minVal){
  
   // initializing with first element
   double maxVal = dataArray[0];
   minVal = dataArray[0];
  
   for(int i=1; i<numValues; i++){
       if(maxVal < dataArray[i])
           maxVal = dataArray[i];
       if(minVal > dataArray[i])
           minVal = dataArray[i];
   }
  
   return maxVal;
}

void reverseArray(double dataArray[],int numValues, double reversedArray[]){
  
   int k=0;
   for(int i= numValues-1; i>=0; i--){
       reversedArray[k++] = dataArray[i];
   }
}

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