Assignment 4, Question A1: Instructor's solution
- Question
-
Write the midterm summation program
using a wrap funciton mySin
instead of the standard sin of math.h.
I ask you to write three versions of the function mySin:
one in the ANCI C style, double mySin(double x).
Another one passing the result by reference in C++ style,
void mySin(double x, double & result). The last one passing
the result by address: void mySin(double x, double * result).
For all three versions, use the appropriate format of the function
call in main(). If you want to avoid having three different
files
for your three versions, use the
#define and #ifdef, #else
preprocessor directive to switch between versions.
Recall that the program had to compute the sum
sin x + sin 2x + ... +
sin Nx
for given x and N.
My program is based on the midterm program, of course
(see Lab8 ).
The required additional elements of programming
are: various formats of function calls
(see links in Lab6 accessible from the
main page)
and wraps (part 2 of
Lab 9)
Also, I put all three versions in one file using
the #define,#indef constructions.
To compile a specific versions, the programmer
must uncomment the corresponding #define
and leave the other two #define's commented.
Here is
the program