1、两点间的距离
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
double x1,x2,y1,y2,d;
cout<<"请依次输入(x1,y1),(x2,y2)坐标值:"<<endl;
cout<<"(x1,y1)="<<"(x2,y2)="<<endl;
cin>>x1>>y1>>x2>>y2;
d=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
cout<<"两点间的距离为:"<<"d="<<d<<endl;
return 0;
}
2、分段函数求值
#include <iostream>
using namespace std;
int main()
{
int x;
cout<<"请输入x的值(整数):"<<"x=";
cin>>x;
if(x>=1)
cout<<"y=x-1="<<x-1<<endl;
else
cout<<"y=-x+1="<<-x+1<<endl;
return 0;
}
3、模拟ATM
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,e,f,g;
cout<<"欢迎来到徐氏银行"<<endl;
cout<<"请输入你的密码:"<<endl;
cin>>a>>b>>c>>d>>e>>f;
if(a==1&&b==2&&c==3&&d==4&&e==5&&f==6)
{
cout<<"1、查询 2、取款 3、存款 4、转账 0、退出"<<endl;
cout<<"请输入你要办理的业务序号:"<<endl;
cin>>g;
cout<<"谢谢,你选择了业务"<<g<<endl;
}
else
cout<<"密码错误"<<endl;
return 0;
}