c++面向对象程序设计实现简单电梯

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

head.h#includeiostream#includecstdio#includectime#includecstdlib#includeWindows.husingnamespacestd;classdate{private:intd,m,y;public:date();voidadd();};classCelevator{private:intfl;public:Celevator();voidchoose();voidup(intx);voiddown(intx);};elevator.cpp#includehead.h#includecstdiodate::date(){time_tnow;time(&now);structtm*t_now;t_now=localtime(&now);y=t_now-tm_year+1900;m=t_now-tm_mon+1;d=t_now-tm_mday;}voiddate::add(){coutTodayisy.m.dendl;coutYouarewelcometousethiselevator.endl;coutThiselevatorfrom-3to20floorsendl;};Celevator::Celevator(){datetime;time.add();fl=1;coutendl;coutYouareontheflfloorendl;cout---Pleaseinputanumber---endl;cout|1.up|endl;cout|2.down|endl;cout|0.quit|endl;cout-------------endl;}voidCelevator::choose(){intn;cinn;if(n==1){coutPleaseenterthefloors:endl;intx;cinx;Celevator::up(x);}if(n==2){coutPleaseenterthefloors:endl;intx;cinx;Celevator::down(x);}if(n==0){exit(0);}}voidCelevator::up(intx){if((x=-3)&&(x=20)){inti=fl;if(x=i){coutInputerrorendl;}else{for(i=fl;ix;i++){coutYouareontheifloorendl;Sleep(750);}coutThexfloorhasbarrivedendl;coutendl;}fl=i;}else{coutOutofrange.Pleasere-enter.endl;coutendl;x=x+0;}coutThiselevatorfrom-3to20floorsendl;cout---Pleaseinputanumber---endl;cout|1.up|endl;cout|2.down|endl;cout|0.quit|endl;cout-------------endl;Celevator::choose();}voidCelevator::down(intx){if((x=-3)&&(x=20)){inti=fl;if(x=i){coutInputerrorendl;}else{for(i=fl;ix;i--){coutYouareontheifloorendl;Sleep(800);}coutThexfloorhasbarrivedendl;coutendl;}fl=i;}else{coutOutofrange.Pleasere-enter.endl;coutendl;x=x+0;}coutThiselevatorfrom-3to20floorsendl;cout---Pleaseinputanumber---endl;cout|1.up|endl;cout|2.down|endl;cout|0.quit|endl;cout-------------endl;Celevator::choose();}intmain(){Celevatorasd;asd.choose();return0;}

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功