#include <iostream>
using namespace std;
const double x1=0.3, x2=0.8; //定义为全局常变量,方便,易维护
double f(double); //此处加入对自定义函数f的声明
int main( )
{
double x;
cout<<"请输入x的值:";
cin>>x;
cout<<"解得:f("<<x<<")="<< f(x)<<"\n";
return 0;
}
//下面是自定义函数的定义部分
double f(double x)
{
double f;
if(x<x1)
f=0;
else if(x>=x1&&x<=x2)
f=(x-x1)/(x2-x1);
else
f=1;
return f;
}