0 Members and 1 Guest are viewing this topic.

int foo(double, double);

int foo((*)(double, double));

int (*(*foo)((*)(double*)))[];

//main.cpp#include <iomanip>#include <iostream>#include <cmath>using namespace std;//-------------------#include "interface.h"const double threshold = 10e-3;int main(){ while(true){ cout << "sin(x)/cos(x): "; double x = 0.0; cin >> x; double answerSin = mySin(x, threshold); double answerCos = myCos(x, threshold); cout << "sin(" << x << ") = " << setprecision(6) << fixed << answerSin << endl; cout << "cos(" << x << ") = " << setprecision(6) << fixed << answerCos << '\n' << endl; } return 0;}

//functions.cpp#include <cmath>#include <iostream>#include <iomanip>#include "interface.h"using namespace std;/*=======================sin(x) = [(-1)^n / (2n + 1)!] * [x^(2n + 1)]cos(x) = [(-1)^n / (2n)!] * [x^(2n)]threshold = 10^(-3)=======================*/__int64 myFact(int theFactArg){ int tmpVal = theFactArg; __int64 result = 1; while(tmpVal>1){ result *= tmpVal--; } return result;}double mySin(double theSinArg, double threshold){ double sumSin = 0.0; int nSin = 0; while(true){ double termSin1 = pow(-1.0, nSin) / myFact(2 * nSin + 1); double termSin2 = pow(theSinArg, 2 * nSin + 1); double termSin = termSin1 * termSin2; sumSin += termSin; if(sumSin < threshold) break; nSin++; } return sumSin;}double myCos(double theCosArg, double threshold){ double sumCos = 0.0; int nCos = 0; while(true){ double termCos1 = pow(-1.0, nCos) / myFact(2 * nCos); double termCos2 = pow(theCosArg, 2 * nCos); double termCos = termCos1 * termCos2; sumCos += termCos; if(sumCos < threshold) break; nCos++; } return sumCos;}

//interface.hdouble mySin(double theSinArg, double threshold);double myCos(double theCosArg, double threshold);

Programming is fun if you compare it to the majority of other subjects you need to study in school lul.

int *(*(*foo)((*[])(double, double))[])(int);

template<typename ObjT, typename ArgT>class Foo { ObjT o; ArgT a;public: Foo(const ObjT& _o, const ArgT& _a) : o(_o), a(_a) {} typename Obj::ReturnT operator()(typename Obj::ArgumentT2 b) { return o(a, b); }};template<typename ObjT, typename ArgT>Foo<ObjT, ArgT> Bar(const ObjT& o, const ArgT& a) { return Foo<ObjT, ArgT>(o, a);}