Question

C++ ArrayMethods Program

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

Max value:       2

Min value:       2

Squared array:   4, 4, 4, 4, 4

Reversed array:  4, 4, 4, 4, 4


1 0
Add a comment Improve this question Transcribed image text
Answer #1

#include
#include
#include
using namespace std;
int arrayMin(int arr[],int size)
{
int minimum=arr[0];
for(int i=1;i {
if(arr[i] minimum=arr[i];
}
return minimum;
}
int arrayMax(int arr[],int size)
{
int maximum=arr[0];
for(int i=1;i {
if(arr[i]>maximum)
maximum=arr[i];
}
return maximum;
}
void arraySquared(int arr[],int size)
{
for(int i=1;i {
arr[i]=arr[i]*arr[i];
}
  
}
void arrayReverse(int arr[],int size)
{
int temp;
for(int i=1,j=size-1;i {
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
  
}


int main()
{
int arr[10];
//initalize array
srand(time(NULL));
for(int i=0;i<5;i++)
arr[i]=rand()%100 +1;
//print original array
cout<<"Original array : ";
for(int i=0;i<5;i++)
cout< //print maximum value of array
cout<<"\nMax value : "< //print minimum value of array
cout<<"\nMin value : "< //print squared array
cout<<"\nSquared Array : ";
arraySquared(arr,5);
for(int i=0;i<5;i++)
cout< //print reverse Array
cout<<"\nReveresed Array :";
arrayReverse(arr,5);
for(int i=0;i<5;i++)
cout<
return 0;
}

TIPUL Original array : 76 83 24 45 15 Max value : 83 Min value : 15 Squared Array : 76 6889 576 2025 225 Reveresed Array : 76

input Original array : 84 92 47 28 27 Max value : 92 Min value : 27 Squared Array : 84 8464 2209 784 729 Reveresed Array : 84

run 3

input Original array : 37 69 49 13 55 Max value : 69 Min value : 13 squared Array : 37 4761 2401 169 3025 Reveresed Array :37

main.cpp #include<ctime> 2 #include<cstdlib> 3 #include<iostream> 4 using namespace std; 5 int arrayMin(int arr[], int size)

33 void arrayReverse(int arr[], int size) 34 - { 35 int temp; for(int i=1,j-size-1;i<size/2;i++,j--) temp=arr[i]; arr[i]=arr[

Know the answer?
Add Answer to:
C++ ArrayMethods Program
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please do in Java as simply as possible :) Exercise #3: Design and implement a program...

    Please do in Java as simply as possible :) 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...

  • Python please! Exercise #3: Design and implement a program (name it ArrayMethods), that defines 4 methods...

    Python please! 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...

  • C++ Arrays & Methods

     #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns true (Boolean type) if the arrays store same values in the same order. Otherwise, it...

  • Design and implement a Java program (name it ArrayMethods ), that defines 4 methods as follows:...

    Design and implement a Java program (name it ArrayMethods ), that defines 4 methods as follows: int arrayMax (int [ ] arr) determines and returns the ma ximum value within an array int arrayMin (int [ ] arr) determines and returns the minimum value within an array void arraySquared (int [ ] arr) changes every value within the array to value

  • Exercise 5: Design and implement a Java program (name it ArrayMethods), that defines 4 methods as...

    Exercise 5: Design and implement a Java program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax(int[] arr) determines and returns the largest value within an array int arrayMin(int[] arr) determines and returns the smallest value within an array void arrayReverse(int[] arr) reverses the array (for example: 7 8 1 2 becomes 2 1 8 7) void arraySquared(int[] arr) changes every value within the array to value² Test your methods by creating an array of length 5 within...

  • Design and implement a Java program (name it ArrayMethods), that defines 4 methods as follows: int...

    Design and implement a Java program (name it ArrayMethods), that defines 4 methods as follows: int arrayMax (int [ ] arr) determines and returns the maximum value within an array int arrayMin (int [ ] arr) determines and returns the minimum value within an array void arraySquared (int [] arr) changes every value within the array to value2 void arrayReverse (int [ ] arr) reverses the array (for example: 7 8 12 becomes 2 18 7) Test your methods by...

  • C++ Single Dimensional Arrays

    Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array.  The program...

  • In Java Please Create A Program For The Following; Please Note: This program should be able...

    In Java Please Create A Program For The Following; Please Note: This program should be able accept changes to the values of constants ROWS and COLS when testing the codes. Switch2DRows Given a 2D array with ROWS rows and COLS columns of random numbers 0-9, re-order the rows such that the row with the highest row sum is switched with the first row. You can assume that 2D arrau represents a rectangular matrix (i.e. it is not ragged). Sample run:...

  • Q2. Consider the following C++ program that declares, allocates and fills in a1D array with random...

    Q2. Consider the following C++ program that declares, allocates and fills in a1D array with random numbers between 0 and 100. The array is sent to a function that finds the indices of all items > 50. A new array is created and the indices are stored inside it. The size of the new arrays MUST BE the same as the number of items > 50. The function returns the new array which is then printed out by main. Here...

  • ***Please complete the code in C*** Write a program testArray.c to initialize an array by getting...

    ***Please complete the code in C*** Write a program testArray.c to initialize an array by getting user's input. Then it prints out the minimum, maximum and average of this array. The framework of testArrav.c has been given like below Sample output: Enter 6 numbers: 11 12 4 90 1-1 Min:-1 Max:90 Average:19.50 #include<stdio.h> // Write the declaration of function processArray int main) I int arrI6]i int min-0,max-0 double avg=0; * Write the statements to get user's input and initialize the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT