C++作业2
2016-03-28 20:50
239 查看
一.项目2分段函数求值
#include <iostream.h>
void main()
{
double x,y;
cout<<"enter x "<<endl;
cin>>x;
if(x>=1)
y=x-1;
else
y=1-x;
cout<<"y="<<y<<endl;
}
二.项目3两点距离
#include<iostream.h>#include<cmath>
void main()
{
double x1,x2,y1,y2,a,b,d;
cout<<"请输入两点坐标"<<endl;
cin>>x1>>y1>>x2>>y2;
a=x1-x2;
b=y1-y2;
d=sqrt(a*a+b*b);
cout<<"两点之间距离"<<d<<endl;
}
三.项目4模拟ATM
#include<iostream.h>void main()
{
int passord,x;
cout<<"工商银行欢迎你"<<endl;
cout<<"您好,请输入密码"<<endl;
cin>>passord;
if(passord==123456)
{
cout<<"请选择您所需要使用的功能。1查询,2取款,3存款,4转账,0退出"<<endl;
cin>>x;
if(x==1)
cout<<"谢谢,您选择了查询功能。";
if(x==2)
cout<<"谢谢,您选择了取款功能。";
if(x==3)
cout<<"谢谢,您选择了存款功能。";
if(x==4)
cout<<"谢谢,您选择了转账功能。";
if(x==0)
cout<<"谢谢,欢迎下次光临。";
}
else cout<<"密码错误";
}