c++作业2

(一)分段函数求值

#include<iostream>
using namespace std;;
int main()
{
    int x=0,y=0;
cin>>x;
if(x>=1)  y=x-1;
else     y=-x+1;
cout<<y;
return 0;
} 
(二)两点距离

#include<iostream>
#include<cmath>
using namespace std;
class point
{
public:
point(int x= 0,int y=0) :x(x),y(y){}
    friend float dist(point &p1,point &p2);
private:
    	int x,y;
};

float dist(point &p1,point &p2)
{
double x = p1.x-p2.x;
double y = p1.y-p2.y;
return static_cast<float>(sqrt(x*x+y*y));  
}
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
point myp1(a,b),myp2(c,d);
    cout<<dist(myp1,myp2)<<endl;

return 0;

(三)
#include<iostream>
using namespace std;
void  menu1()  //菜单1 
{
    int key;
    cout<<"                   welcome to Jinlei's bank                        "<<endl<<endl;
    do{
    cout<<"please input your password"<<endl;
    cin>>key;
    }while(key!=111111);
}

void menu2()  //菜单2 
{
	int i;
    cout<<"please choose the number before the choice(0 ~ 4)"<<endl<<endl;
    cout<<"     *   1.Inquire(查询)"<<endl;
    cout<<"     *   2.Withdrawals(取款)"<<endl;
    cout<<"     *   3.deposit(存款)"<<endl;
    cout<<"     *   4.Transfers(转账)"<<endl;
    cout<<"     *   0.exit"<<endl;
 
  	
    cin>>i;
    
    switch(i)
    {
  	    case 1:cout<<"Thank you for using the search function";break;//查询 
		case 2:cout<<"Thank you for using teller function;break";//取款 
		case 3:cout<<"Thank you for using the deposit function";break;//存款 
		case 4:cout<<"Thank you for using transfer function";break;//转账 
		case 0:break;
        default:printf("\n输入错误!!!\n\n请重新选择\n\n");
    }

}

int main()
{
	menu1();
	menu2();
	cout<<"Think you for your using"<<endl;
}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值