c++作业2
来源:互联网 发布:nba季后赛各项数据统计 编辑:程序博客网 时间:2024/05/20 17:42
(一)分段函数求值
#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;}
0 0
- c语言作业2
- C语言作业(2)
- Linux-c 作业2
- C/C++作业2
- C语言程序设计课后作业2
- C语言作业(2)
- c语言课堂作业2
- c语言程序设计第三次作业 2
- C语言作业(2)
- c 作业
- c作业
- C作业
- c作业
- c作业
- c作业
- c作业
- c作业
- 【哈工大C语言作业实验题】:13-2作业
- STL stack
- 第五周项目2 游戏中角色类的设计(1)
- get()和load()的区别
- 基于循环双链表的一道编程题(java实现)
- centos7下yum安装mysql与卸载mysql
- c++作业2
- linux教程:配置Tomcat开机启动 centos7
- 单例模式
- 对一个才子的走访我学到了什么?
- Aizu 0525(Osenbei 穷竭搜索)
- python 元类的使用(orm框架搭建)
- 克服当众表达的恐惧心理-《卡耐基语言的突破与相处的艺术》(美)卡耐基
- 【转载】在Windows下Memcache缓存系统构建(Java)
- android异步加载网络图片(1)