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

I am back again. Still working on a program. The help with the incrementing was

ID: 3553961 • Letter: I

Question

I am back again. Still working on a program. The help with the incrementing was great. I am trying now to incorporate functions into the program. I have written the following code, but it fails to run. The only error code that I get is undefined reference to 'capFun(double, double, double)'. Where have I messed this up?

#include <cstdlib>

#include <iostream> //pre-processor directs - iostream talks to screen

#include <iomanip> //pre-processor directs - string

#include <cmath> //allows math functions


using namespace std; //introduces namespace

//*****************Function prototypes***************************

void capFun (double, double, double);

//***************************************************************

const int size=10;

//*****************Main function*********************************

int main()

{

double x[size], y[size]; //Declares arrays

double W=100,f;

cout<<" Enter your frequency: ";

cin>>f;

for (int i=0;i<size;i++) //initiates, defines and sets counter

{

x[i]=f; //initiates the first value of the array

f=f*2;

}

//and increments by 10

capFun (W,x[size],y[size]); //Calls capFun function

cout<<"Frequency: "<<"Result: "<<endl; //prints column headers to screen

for (int i=0;i<size;i++) //initiates, defines and sets counter

cout<<setprecision(6)<<setw(10)<<x[i]<<setw(10)<<y[i]<<endl;//prints values in arrays to screen

cout<<endl;

return 0;

}

//*****************capFun Function***************************************

void capFun (double W, double x[size], double y[size])

{

for (int i=0;i<size;i++) //initiates, defines and sets counter

y[i]=W+x[i]; //converts values in Farn array to celsius

}

Explanation / Answer

Working program:


#include <cstdlib>


#include <iostream> //pre-processor directs - iostream talks to screen


#include <iomanip> //pre-processor directs - string


#include <cmath> //allows math functions



using namespace std; //introduces namespace


//*****************Function prototypes***************************


void capFun (double, double[], double[],int);



//***************************************************************


const int size=10;


//*****************Main function*********************************


int main()


{


double x[size], y[size]; //Declares arrays


double W=100,f;

cout<<" Enter your frequency: ";

cin>>f;

for (int i=0;i<size;i++) //initiates, defines and sets counter

{

x[i]=f; //initiates the first value of the array

f=f*2;

}

//and increments by 10

capFun (W,x,y,size); //Calls capFun function

cout<<"Frequency: "<<"Result: "<<endl; //prints column headers to screen

for (int i=0;i<size;i++) //initiates, defines and sets counter

cout<<setprecision(6)<<setw(10)<<x[i]<<setw(10)<<y[i]<<endl;//prints values in arrays to screen

cout<<endl;

return 0;

}

//*****************capFun Function***************************************

void capFun (double W, double x[], double y[],int size)

{

for (int i=0;i<size;i++) //initiates, defines and sets counter

y[i]=W+x[i]; //converts values in Farn array to celsius

}