#include<iostream>
#include<string>
using namespace std;
double add(double x,double y){
return x+y;
}
double sub(double x,double y){
return x-y;
}
double mul(double x,double y){
return x*y;
}
double div(double x,double y){
if(y==0){
cout<<"bad"<<endl;
return 0;
}
else
return x/y;
}
double calculate(double x,double y,double (*pf)(double,double)){
return (*pf)(x,y);
}
int main(){
double x,y;
double (*pf[4])(double,double)={add,sub,mul,div};
// pf[0]=add;
// pf[1]=sub;
// pf[2]=mul;
// pf[3]=div;
while(cin>>x>>y){
for(int i=0;i<=3;i++){
cout<<(*pf[i])(x,y)<<endl;
}
}
return 0;
}
函数指针数组 C++Prime Plus第七章最后一题
最新推荐文章于 2024-11-16 16:57:08 发布