/*
* Copyright (c) 2011, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:樊露露
* 完成日期:2012 年 10 月 22 日
* 版 本 号:v1.0
*
* 输入描述:无
* 问题描述:求分段函数的值
* 程序输出:分段函数的值
* 问题分析:略
* 算法设计:略
*/
#include<iostream>
#include<Cmath>
using namespace std;
int main()
{
float x,y;
cout<<"请输入x的值:";
cin>>x;
if(x<0)
cout<<"Input error!"<<endl;
else
{
if(x<2)
{
y=x;
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
}
else if(x<6)
{
y=x*x+1;
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
}
else if(x<10)
{
y=sqrt(x+1);
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
}
else
{
y=1/(x+1);
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
}
}
return 0;
}
心得体会:要细心地做好每一步。