您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 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;}
本文标题:c++面向对象程序设计实现简单电梯
链接地址:https://www.777doc.com/doc-4217063 .html