3. Consider the following function declarations - void getSeq (double xl, int sX
ID: 3590982 • Letter: 3
Question
3. Consider the following function declarations - void getSeq (double xl, int sX): void showseq (double xl. int sx) int getMax ( (double x), sx) The functions perform following task vold shoxsumequare (double xil, int 8%) 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 t parameter to the function and the number of and the number of values to be taken as input is the second parameter input. he data is the first . 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
#include<iostream>
using namespace std;
void getSeq(double x[], int sX);
void showSeq(double x[], int sX);
void showSumSquare(double x[], int sX);
int getMax(double x[], int sX);
int main()
{
int n; // variable to store, how many no. of values to be stored into an array
cout << "Enter, how many no. of values to be stored into an array? ";
cin >> n;
double *x=new double[n]; // dynamic array declartion, which reserves space for exactly n numbers
cout << "Enter sequence of numerical values : "<< endl;
getSeq(x,n);
cout << "The entered sequence of numerical values : " << endl;
showSeq(x,n);
cout << "Summation of the square of the values stored in an array : ";
showSumSquare(x,n);
cout << "The maximum value of from a sequence of numerical values which are stored in array : " << getMax(x,n) << endl;
return 0;
}
void getSeq(double x[], int sX) //
{
for(int i=0;i<sX;i++)
{
cin >> x[i];
}
}
void showSeq(double x[], int sX)
{
for(int i=0; i<sX;i++)
{
cout << x[i] << " ";
}
cout << endl;
}
void showSumSquare(double x[], int sX)
{
double sum=0;
for(int i=0;i<sX;i++)
{
sum = sum + (x[i] * x[i]);
}
cout << sum << endl;
}
int getMax(double x[], int sX)
{
double max=x[0];
for(int i=1;i<sX;i++)
{
if(max < x[i])
max=x[i];
}
return max;
}
/*
lenovo@lenovo-Vbox:~/chegg$ g++ impfunc.cpp -Wall
lenovo@lenovo-Vbox:~/chegg$ ./a.out
Enter, how many no. of values to be stored into an array? 5
Enter sequence of numerical values :
3
3
1
4
2
The entered sequence of numerical values :
3 3 1 4 2
Summation of the square of the values stored in an array : 39
The maximum value of from a sequence of numerical values which are stored in array : 4
lenovo@lenovo-Vbox:~/chegg$
lenovo@lenovo-Vbox:~/chegg$ ./a.out
Enter, how many no. of values to be stored into an array? 9
Enter sequence of numerical values :
4 3 2 1 4 5 2 7 6
The entered sequence of numerical values :
4 3 2 1 4 5 2 7 6
Summation of the square of the values stored in an array : 160
The maximum value of from a sequence of numerical values which are stored in array : 7
lenovo@lenovo-Vbox:~/chegg$
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.