c++作业2
2016-03-28 22:45
543 查看
(一)分段函数求值
(三)
#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; }
相关文章推荐