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

3. (40) Write a program that will use the following function prototypes: int rea

ID: 3595466 • Letter: 3

Question

3. (40) Write a program that will use the following function prototypes: int readData(double data]): ask user for number of points, read in points and return number of points double squareSum(double data[], int numpts)return the sum of the squares of the values in data double average(double datal]. int numpts); /return the average of the values in data In main, call readData to read in the number of points and those many data points. In squareSum, each value in the passed array is to be squared and added to a sum which is returned. Each function including main is worth 10 points. Don't try to enter all the code and then debug. Instead work on main and readData and get that to work before going on to other functions. Be sure to add your name as a comment where shown in the starter code!!

Explanation / Answer

#include <iostream>

using namespace std;

int readData(double data[]){

int n,i;

cout<<"Enter no. of data points:";

cin>>n;

cout<<"Enter data points ";

for(i=0;i<n;i++)cin>>data[i];

return n;

}

double squareSum(double data[], int numpts){

double sum=0;

int i;

for(i=0;i<numpts;i++){

sum+=data[i]*data[i];

}

return sum;

}

double average(double data[], int numpts){

double sum=0;

int i;

for(i=0;i<numpts;i++){

sum+=data[i];

}

return sum/(double)(numpts);

}

int main(){

int numpts;

double data[10004];

numpts=readData(data);

cout<<"Sum of squares: "<<squareSum(data,numpts)<<endl;

cout<<"Average: "<<average(data,numpts)<<endl;

return 0;

}

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