1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include <iostream>
#include <fstream>
using namespace std;
double ratio(double, double);
double (*pt_ratio)(double, double)=ratio;
double product(double, double);
double (*pt_product)(double, double)=product;
double operate( double, double, double(*)(double, double) );
int main(int argc, const char * argv[] )
{
int menu;
double a = 1.2;
double b = 2.3;
double result;
double * pt_ratio;
double * pt_product;
cout << "Please enter 1 for the ratio and 2 for the product" << endl;
cout << "q to quit"<< endl;
while(cin >> menu)
{
if( menu == 1 )
{
result = operate( a , b , pt_ratio);
cout << a << "/" << b << "=" << result;
}
else if( menu == 2)
{
result = operate( a , b , pt_product );
cout << a << "x" << b << "=" << result;
}
}
return 0;
}
double ratio(double a, double b)
{
double c=a/b;
return c;
}
double product(double a, double b)
{
double c=a*b;
return c;
}

double operate(double a, double b, double (*funcall)(double, double))
{
double c=(*funcall)(a,b);
return c;
}
|