Consider the following function declarations - void getSeq(double x[], int sX);
ID: 3857812 • Letter: C
Question
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.
Take the user input for the number of values to read from the user.
Invoke getSeq function to read the values from the user.
Invoke showSeq function to print values passed as the input.
Invoke showsumSquare to calculate and print the summation of square of the values taken as input.
Invoke getMax to calculate and print the maximum of the values taken as input.
Explanation / Answer
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);
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];
}
showSeq(a,n);
}
void showSeq(double a[], int n)
{
std::cout<<" The entered values are";
for(int i=0;i<n;i++)
{
std::cout<<" "<<a[i]<<" ";
}
}
void showSumSquare(double a[], int n)
{
double sum=0;
for(int i=0;i<n;i++){
sum+=(a[i]*a[i]);
}
std::cout<<" The sum of the square of the values entered is "<<sum;
}
void getMax(double a[], int n)
{
double max = a[0];
for (int i = 1; i < n; i++)
if (a[i] > max)
max = a[i];
std::cout<<" The max element in the array is "<<max;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.