一、项目二-输入x求y
#include <iostream>
using namespace std;
int main()
{
int x,y;
cout<<"输入x=";
cin>>x;
if(x>=1)
{
y=x-1;
cout<<"y="<<y<<endl;
}
else
{
y=1-x;
cout<<"y="<<y<<endl;
}
}
二、项目三-计算两点间的距离
#include <iostream>
#include <cmath>
using namespace std;
void main()
{
double x1,y1,x2,y2,L;
char ch;
cout<<"输入一点坐标(x1,y1)"<<endl;
cin>>x1>>ch>>y1;
cout<<"输入另一点坐标(x2,y2)"<<endl;
cin>>x2>>ch>>y2;
L=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
cout<<"两点间的距离L=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))="<<L<<endl;
}
三、项目四 -模拟ATM
#include <iostream>
using namespace std;
const int m=960922;//用户密码//
int main()
{
cout<<"钟氏银行欢迎您!"<<endl;
cout<<"请输入密码:";
int n;
cin>>n;
if(n==m)
{
cout<<"显示功能选项\n1.查询\n2.取款\n3.存款\n4.转帐\n0.退出\n用户输入功能选择"<<endl;
int o;
cin>>o;
if(0<=o&&o<5)
{
if(o==0) cout<<"谢谢光临!"<<endl;
if(o==1) cout<<"谢谢,您选择了查询功能。"<<endl;
if(o==2) cout<<"谢谢,您选择了取款功能。"<<endl;
if(o==3) cout<<"谢谢,您选择了存款功能。"<<endl;
if(o==4) cout<<"谢谢,您选择了转帐功能。"<<endl;
}
else
cout<<"谢谢!"<<endl;
}
else
cout<<"密码错误";
}