當前位置:編程學習大全網 - 編程語言 - 壹個C++程序作業,模擬電梯運行

壹個C++程序作業,模擬電梯運行

為了簡單,分配了1到9層.另外也沒加入有幾人同時按,不過那樣也不難,再分配10個每層的變量,隨機按.再處理,是先向上還是直接向下.不過那倒真的可以用到真的上了.

#include <stdio.h>

#include <dos.h>

#include <ctype.h>

#define ON 1

#define OFF 0

main(){

int power,i;

char oldkey,key ;

struct date today;

struct time now;

getdate(&today); /*把系統當前日期存入today所指向的date結構中*/

gettime(&now);

gotoxy(25,3);

printf("Today's date is %d-%d-%d\n",today.da_year,today.da_mon,today.da_day);

gotoxy(25,6);

printf("Current time is %02d:%02d:%02d\n",now.ti_hour,now.ti_min,now.ti_sec);

if( now.ti_hour>=8||(now.ti_hour<=23&&now.ti_min<59)){

power=ON;

printf("\n\n\nLift power is on.Lift stop in 1 floor.");

}

else {

power=OFF;

printf("Lift power is off.");

}

oldkey=0;

while(power==ON) {

printf("\n\n\nFloor");

for(i=1;i<10;i++)

printf("\n %d",i);

printf("\nPress floor number or q to shut down power :");

if( now.ti_hour>=8||(now.ti_hour<=23&&now.ti_min<59))

power=ON;

else

power=OFF;

key=bioskey(0);

key=key&0x00ff;

system("cls");

if(key=='0'){

power=OFF;

printf("\n\n Lift Power off");

sleep(1);

break;

}

if(key>oldkey)

printf(" %c Go up!...",24);

if(key<oldkey)

printf(" %c Go down!...",25);

if(key==oldkey)

printf(" %c ok you are here",22);

sleep(2);

system("cls");

printf("\n\n ");

switch(key){

case '1':

if(key==oldkey)

printf(" %c ok you are here",22);

else if(key>oldkey)

printf("%c Go up!...stop in %c floor.",24,key);

else

printf("%c Go down!...stop in %c floor.",25,key);

oldkey=key;

break;

case '2':

if(key==oldkey)

printf(" %c ok you are here",22);

else if(key>oldkey)

printf("%c Go up!...stop in %c floor.",24,key);

else

printf("%c Go down!...stop in %c floor.",25,key);

oldkey=key;

break;

case '3':

if(key==oldkey)

printf(" %c ok you are here",22);

else if(key>oldkey)

printf("%c Go up!...stop in %c floor.",24,key);

else

printf("%c Go down!...stop in %c floor.",25,key);

oldkey=key;

break;

case '4':

if(key==oldkey)

printf(" %c ok you are here",22);

else if(key>oldkey)

printf("%c Go up!...stop in %c floor.",24,key);

else

printf("%c Go down!...stop in %c floor.",25,key);

oldkey=key;

break;

case '5':

if(key==oldkey)

printf(" %c ok you are here",22);

else if(key>oldkey)

printf("%c Go up!...stop in %c floor.",24,key);

else

printf("%c Go down!...stop in %c floor.",25,key);

oldkey=key;

break;

case '6':

if(key==oldkey)

printf(" %c ok you are here",22);

else if(key>oldkey)

printf("%c Go up!...stop in %c floor.",24,key);

else

printf("%c Go down!...stop in %c floor.",25,key);

oldkey=key;

break;

case '7':

if(key==oldkey)

printf(" %c ok you are here",22);

else if(key>oldkey)

printf("%c Go up!...stop in %c floor.",24,key);

else

printf("%c Go down!...stop in %c floor.",25,key);

oldkey=key;

break;

case '8':

if(key==oldkey)

printf(" %c ok you are here",22);

else if(key>oldkey)

printf("%c Go up!...stop in %c floor.",24,key);

else

printf("%c Go down!...stop in %c floor.",25,key);

oldkey=key;

break;

case '9':

if(key==oldkey)

printf(" %c ok you are here",22);

else if(key>oldkey)

printf("%c Go up!...stop in %c floor.",24,key);

else

printf("%c Go down!...stop in %c floor.",25,key);

oldkey=key;

break;

}

}

getch();

}

  • 上一篇:有哪些適合小白的莆田鞋?
  • 下一篇:怎樣用數控編程對刀
  • copyright 2024編程學習大全網