Programming and Graphics

(Kiana) #1

144 Introduction to C++ Programming and Graphics


int menu;
double a = 4.0;
double b = 2.0;
double result;

cout << "Please enter 1 for the ratio and 2 for the product" << endl;
cout << "q to quit" << endl;
cout << "q to quit" << endl;

while(cin >> menu)
{
if(menu==1)
{
result=operate(a, b, prat);
cout << a << "/" << b <<"=" << result<< endl;
}
else if(menu==2)
{
result=operate(a, b, pprod);
cout << a << "x" << b <<"=" << result<< endl;
}
}
return 0;
}

/*--------------- ratio --------------------*/

double ratio(double a, double b)
{
double c=a/b;
return c;
}

/*--------------- product--------------------*/

double product(double a, double b)
{
double c=a*b;
return c;
}
/*--------------- operate--------------------*/

double operate(double a, double b,
double (*funcall)(double, double))
{
double c=(*funcall)(a, b);
return c;
}
Free download pdf