c++作业2

一、项目二-输入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<<"密码错误";
}


 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值