Question

In: Computer Science

**** In C++ ****Exercise #3: Design and implement a program (name it ArrayMethods), that defines 4...

**** In C++ ****Exercise #3: Design and implement a program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax(int[] arr) returns the maximum value in the an array int arrayMin(int[] arr) returns the minimum value in an array void arraySquared(int[] arr) changes every value in the array to its square (value²) void arrayReverse(int[] arr) reverses the array (for example: array storing 7 8 9 becomes 9 8 7 ) The program main method creates a single-dimensional array of length 5 elements and initialize it with random integers between 1 and 100. The program displays the original array, then calls each of the above methods and displays their results as shown below. Document your code and organized your output following these sample runs. Sample run 1: Original array: 3, 5, 2, 6, 1 Max value: 6 Min value: 1 Squared array: 9, 25, 4, 36, 1 Reversed array: 1, 36, 4, 25, 9 Sample run 2: Original array: 3, 2, 3, 7, 2 Max value: 7 Min value: 2 Squared array: 9, 4, 9, 49, 4 Reversed array: 4, 49, 9, 4, 9 Sample run 3: Original array: 2, 2, 2, 2, 2 Maxvalue: 2 Min value: 2 Squared array: 4, 4, 4, 4, 4 Reversed array: 4, 4, 4, 4, 4

Solutions

Expert Solution

#include <iostream>

using namespace std;
// finds max element in array
int arrayMax(int arr[]){
   int m=arr[0];
   for(int i=1;i<5;i++)
       if(m<arr[i])
           m=arr[i];
   return m;
}
//finds mine element in array
int arrayMin(int arr[]){
   int m=arr[0];
   for(int i=1;i<5;i++)
       if(m>arr[i])
           m=arr[i];
   return m;
}
//squared every element in array
void arraySquared(int arr[]){
   for(int i=0;i<5;i++)
       arr[i]=arr[i] * arr[i];
}
//reverse the given array
void arraReverse(int arr[]){
   int temp;
   for(int i=0,j=4;i<2;i++,j--){
       temp=arr[i];
       arr[i]=arr[j];
       arr[j]=temp;
   }
}
int main(){
   int arr[5];
   for(int i=0;i<5;i++){
       arr[i]=rand() % 101+1;
       cout<<arr[i]<<" ";
   }
   cout<<"\nMax in Array: "<<arrayMax(arr)<<endl;
   cout<<"Min in Array: "<<arrayMin(arr)<<endl;
   cout<<"Squared Array: "<<endl;
   arraySquared(arr);
   for(int i=0;i<5;i++)
       cout<<arr[i]<<" ";
   arraReverse(arr);
   cout<<"\n Reversed Array: "<<endl;
   for(int i=0;i<5;i++)
       cout<<arr[i]<<" ";
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

DO THIS IN C#. Design and implement a program (name it MinMaxAvg) that defines three methods...
DO THIS IN C#. Design and implement a program (name it MinMaxAvg) that defines three methods as follows: Method max (int x, int y, int z) returns the maximum value of three integer values. Method min (int X, int y, int z) returns the minimum value of three integer values. Method average (int x, int y, int z) returns the average of three integer values. In the main method, test all three methods with different input value read from the...
IN C++ PLEASE!!! Design and implement a program (name it Coins) that determines the values of...
IN C++ PLEASE!!! Design and implement a program (name it Coins) that determines the values of coins in a jar. The program prints out the total dollars and cents in the jar. The program prompts the user to enter the number of coins (quarters, dimes, nickels, and pennies). Print out the number of coins entered for each coin type on separate lines followed by the total amount of money in the jar as dollars and cents as shown below.
I need this in C# with pseudocode Exercise #2: Design and implement a programming (name it...
I need this in C# with pseudocode Exercise #2: Design and implement a programming (name it EvenOdd) that uses a while loop to determine and print out all even numbers between 50 and 100 on a single line, separated by commas. Then another while loop in the same program to print out all odd numbers between 50 and 100 on a new line, separated by commas. Document your code and properly label the outputs as shown below. Even numbers between...
IN C++ LANGUAGE PLEASE::: Design and implement a program (name it Rectangle) to calculate and display...
IN C++ LANGUAGE PLEASE::: Design and implement a program (name it Rectangle) to calculate and display the area and perimeter of a rectangle with width = 4 and height = 8.
In C++ Design and implement a program (name it ProcessGrades) that reads from the user four...
In C++ Design and implement a program (name it ProcessGrades) that reads from the user four integer values between 0 and 100, representing grades. The program then, on separate lines, prints out the entered grades followed by the highest grade, lowest grade, and averages of all four grades. Format the outputs following the sample runs below.
USING C# Design and implement a program (name it Coins) that determines the values of coins...
USING C# Design and implement a program (name it Coins) that determines the values of coins in a jar. The program prints out the total dollars and cents in the jar. The program prompts the user to enter the number of coins (quarters, dimes, nickels, and pennies). Print out the number of coins entered for each coin type on separate lines followed by the total amount of money in the jar as dollars and cents as shown below. Sample run...
Using C# Design and implement a program (name it CheckPoint) that prompts the user to enter...
Using C# Design and implement a program (name it CheckPoint) that prompts the user to enter the x-coordinate then y-coordinate of a point (in a Cartesian plane) as integer values. The program prints out the entered values followed by the location of the point on the plane. The possibilities for a point are: the origin point, on the x-axis, on the y-axis, in the first quadrant, in the second quadrant, in the third quadrant, or in the fourth quadrant. Format...
I need this in C# please. Exercise #2: Design and implement a programming (name it NextMeeting)...
I need this in C# please. Exercise #2: Design and implement a programming (name it NextMeeting) to determine the day of your next meeting from today. The program reads from the user an integer value representing today’s day (assume 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, etc…) and another integer value representing the number of days to the meeting day. The program determines and prints out the meeting day. Format the outputs following the sample...
Using C# Design and implement a program (name it ProcessGrades) that reads from the user four...
Using C# Design and implement a program (name it ProcessGrades) that reads from the user four integer values between 0 and 100, representing grades. The program then, on separate lines, prints out the entered grades followed by the highest grade, lowest grade, and averages of all four grades. Format the outputs following the sample runs below. Sample run 1: You entered:   95, 80, 100, 70 Highest grade:100 Lowest grade:  70 Average grade:86.25
USING C# Design and implement a program (name it SumValue) that reads three integers (say X,...
USING C# Design and implement a program (name it SumValue) that reads three integers (say X, Y, and Z) and prints out their values on separate lines with proper labels, followed by their average with proper label. Comment your code properly.Format the outputs following the sample runs below. Sample run 1: X = 7 Y = 8 Z = 10 Average = 8.333333333333334
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT