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

7. Consider the following recursive function: void recFun(int u) { if (u == 0) c

ID: 3857285 • Letter: 7

Question

7. Consider the following recursive function: void recFun(int u)

{ if (u == 0) cout << "Zero! ";

else

{ cout << "Negative "; recFun(u - 1);

}

}

What is the output of the function call as recFun(8). List all the steps as described with a ladder case for the example discussed in the Example -4 given before.

8. Consider the following function declarations - void getSeq(double x[], int sX); void showSeq(double x[], int sX); void showSumSquare(double x[], int sX); int getMax((double x[], sX);

The functions perform following task -

. getSeq – performs the task of reading a sequence of numerical values taken as user input and stores them in into a double array. The array to store the data is the first parameter to the function and the number of and the number of values to be taken as input is the second parameter input.

. showSeq – performs the printing a sequence of numerical values on the standard console which are stored in an array. The array storing the data is the first parameter to the function and the number of and the number of values in the array is the second parameter input.

. showSumSquare - performs the task of computing the summation of the square of the values stored in an array. The array having the stored data is the first parameter to the function and the number of and the number of values to be taken as input is the second parameter input.

. getMax - performs the task of finding the maximum value of from a sequence of numerical values which are stored in an array. The array storing the data is the first parameter to the function and the number of and the number of values in the array is the second parameter input.

Write a C++ program using the above functions so that the program performs following tasks in order.

1- Take the user input for the number of values to read from the user.

2- Invoke getSeq function to read the values from the user.

3- Invoke showSeq function to print values passed as the input.

4- Invoke showsumSquare to calculate and print the summation of square of the values taken as input.

5- Invoke getMax to calculate and print the maximum of the values taken as input.

Explanation / Answer

// Example program
#include <iostream>

void getSeq(double [], int);
void showSeq(double [], int);
void showSumSquare(double [], int);
void getMax(double [], int);

int main()
{
  
double a[50];
int n;
  
std::cout<<"Enter the number of values to be read";
std::cin>>n;
  
getSeq(a,n);//calling the functions
showSumSquare(a,n);
getMax(a,n);
  
}

void getSeq(double a[], int n)
{
std::cout<<"enter the Array values";
for(int i=0;i<n;i++)
{
std::cin>>a[i]; //reading the array values from the console
}
showSeq(a,n);//calling the function to print the values read on the console
}

void showSeq(double a[], int n)
{
std::cout<<" The entered values are";
for(int i=0;i<n;i++)
{
std::cout<<" "<<a[i]<<" "; //printing the values read from console
}
}

void showSumSquare(double a[], int n)
{
double sum=0;

for(int i=0;i<n;i++){
sum+=(a[i]*a[i]); //calculating the sum of squares of the array values
}
std::cout<<" The sum of the square of the values entered is "<<sum;//printing the result
}

void getMax(double a[], int n)
{
// Initialize maximum element
double max = a[0];

// Traverse array elements from second and
// compare every element with current max
for (int i = 1; i < n; i++)
if (a[i] > max)
max = a[i];
  
std::cout<<" The max element in the array is "<<max;//print the max value
}

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