Question

In: Computer Science

(C++ only please) Write a function called maximum that takes an array of double values as...

(C++ only please)

  1. Write a function called maximum that takes an array of double values as a parameter and returns the largest value in the array. The length of the array will also be passed as a parameter. (Note that the contents of the array should NOT be modified.)

  2. Write a function called printReverse that takes an array of characters and the length of the array as parameters. It should print the elements of the array in reverse order. The function should not return anything. (Note that the contents of the array should NOT be modified.)

  3. Write a function called triple that takes an array of integers as a parameter as well as the length of the array. It should triple each value in the array. The function should not return anything. (Note that the contents of the array WILL be modified.)

  4. Write a program (i.e. a main function) that simply calls each of the 3 functions above. For each function, initialize an array with arbitrary values, then call the corresponding function and display the result. For the maximum function, you will initialize an array of double values. Then you will call the maximum function, passing that array of doubles, and print the result. For the printReverse function, you will initialize an array of characters. Then you will call the printReverse function to print the array of characters in reverse order. Finally, you will initialize an array and call the triple function. For the triple function, you will need to print the entire array after the function has been called to show that each element was indeed tripled. (Hint: Your main function should consist of about 8 lines of code.)

Solutions

Expert Solution

I WROTE THE CODE ALONG WITH THE COMMENTS

CODE:


#include <iostream>
#include <cmath>
using namespace std;
int maximum(int arr[],int len)
{
int i;
int max=arr[0];
for(i=1;i<len;i++) //for loop used to traverse each element.
{
if(max<arr[i]) //condition for max element.
max=arr[i];
}
return max;
}
void printReverse(char arr[],int len)
{
int i;
cout<<"Reverse order of array: ";
for(i=len-1;i>=0;i--) //for loop used to traverse each character.
cout<<arr[i]<<" ";
}
void triple(int arr[],int len)
{
int i;
for(i=0;i<len;i++) //for loop used to traverse each element.
{
arr[i]=pow(arr[i],3); //pow function used triple the value.
}
}
int main()
{
int max,i;
int arr1[8]={23,45,67,2,99,69,9,78};
max=maximum(arr1,8); //calling maximum() function.
cout<<"Maximum number is : "<<max<<endl<<endl;
  
  
char arr2[5]={'h','e','l','l','o'};
printReverse(arr2,5); //calling printReverse() function.
cout<<endl<<endl;
  
  
int arr3[6]={3,4,6,8,9,12};
triple(arr3,6); //calling triple() function.
cout<<"Triple values of array: ";
for(i=0;i<6;i++) //print array.
cout<<arr3[i]<<" ";
return 0;
}

OUTPUT:

SCREENSHOT OF THE CODE:


Related Solutions

Write a function in C# that takes an array of double as the parameter, and return...
Write a function in C# that takes an array of double as the parameter, and return the average
C++ Write a function called linearSearch that takes an array as a parameter and search for...
C++ Write a function called linearSearch that takes an array as a parameter and search for a specific value inside this parameter. The function returns the frequency of a specific value in the array. In the main function: 1. Define an array called salaries of length 5. 2. Initialize the array by asking the user to input the values of its elements. 3. Define a variable called key and ask the user to enter a value for this variable. 4....
c++ please 1. Write and test the function maximum that is passed an array of n...
c++ please 1. Write and test the function maximum that is passed an array of n pointers to integers and returns the maximum value among the n integers. The function must use the travellingpointer(1stversion) notation to traverse the array. The function has the following prototype. int maximum ( int *p [ ], int n); 2. Implement the function psum( )that is passed an array of n floats and returns a pointer to the sum of such an array. Print the...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes one doyble argument called "num". The function will declare, ask, and get another double from the user. Compare the double entered by the user to "num" and return a 0 if they are the same, a -1 num is less than the double entered by the user and 1 if it is greater.
Write a function called swapElements to swap two elements in a character array. This function takes...
Write a function called swapElements to swap two elements in a character array. This function takes two parameters, a character array and input file. The function should read two numbers from a file and it swap the elements stored in the indices read. please code in c++
Write a function (in Javascript) called longestMorseCodeWords which takes in an array of strings. The output...
Write a function (in Javascript) called longestMorseCodeWords which takes in an array of strings. The output of longestMorseCodeWords should be an array of the strings that were passed in, but ordered by the length of their Morse Code equivalent in descending order. If the length of Morse Code is equal, order the words alphabetically.For convenience, the full table for the 26 letters of the English alphabet is given below: [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] let words = ["gin", "zen", "gig", "msg"] longestMorseCodeWords(words) The Morse...
C Language - Programming Write a function that takes an array of ints, and the size...
C Language - Programming Write a function that takes an array of ints, and the size of the array – another int. It also returns a double. Call this one ‘average.’ Return a double that is the average of the values in the array. Demonstrate that it works by finding the average of an array with these values {78, 90, 56, 99, 88, 68, 92} Write a function that takes one double parameter, and returns a char. The parameter represents...
Write a function in C that takes one argument, an array of 50 elements. Your function...
Write a function in C that takes one argument, an array of 50 elements. Your function should print out the index and value of the smallest element in the array.
Write a function called printChList that takes as its parameters a character array, its size, and...
Write a function called printChList that takes as its parameters a character array, its size, and output file stream. The function should print the contents of the array to the output file. code with c++ and detail explaination
In PYTHON Write an algorithm for a function called removeAll which takes 3 parameters: an array...
In PYTHON Write an algorithm for a function called removeAll which takes 3 parameters: an array of array type, a count of elements in the array, and a value. As with the remove method we discussed in class, elements passed the count of elements are stored as None. This function should remove all occurrences of value and then shift the remaining data down. The last populated element in the array should then be set to None. The function then returns...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT