#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
usingnamespace std;
constexprdouble pi = 3.14159;
double deg_to_rad(double deg){
return deg * ( pi / 180 );
}
int main () {
for (int i = 0; i < 90; ++i){
cout << i << " "; // to show which angle the row is
for (double j = 0; j <= 0.9; j+= 0.1)
{
cout << setprecision(4) << sin( deg_to_rad(i + j) ) << " ";
}
cout << "\n";
}
cout << "\n";
return 0;
}
The thing is, to print the tables of cos and tan, all I have to do is replace sin in line 26 with cos or tan. How do I change the above code (lines 20 to 30) to the function named clarketable that, if I call clarktable(cos) from the main function, it prints that table? That is, I want sin, cos or tan to be a parameter.
You can use an enumeration [1] and pass SIN, COS or TAN to your function. In your function you can have a 'switch' to print the correct table on the basis of what was passed as a parameter.
In your function you can have a 'switch' to print the correct table on the basis of what was passed as a parameter.
Will not the function become thrice as large if I use the switch? All I want is to change one thing in line 26. Is there a way to search and replace just that in the function? Something like a 'define'? I am new so forgive me for asking stupid questions.