用C语言编写一个关于电梯的程序

用C语言编写一个关于电梯的程序,第1张

这是以前作的课程设计,是一个10层电梯的模拟,供楼主参考吧:

printf("上下选择:1-上楼,2-下楼\t")

scanf("%d",&input_direction)

fflush(stdin)

printf("输入该层的乘客想到达的楼层,以-1结束\n")

void check(liftor &myliftor) int flag1=0,flag2=0,flag3=0

for(i=0i<10i++)

{

if(myliftor.stored_flare[i]!=0)

flag1=1

if(myliftor.stored_flare[i]==1)

flag2=1

if(myliftor.stored_flare[i]==2)

flag3=1

}

if(!flag1) myliftor.set_direction(0)

else if(!flag2&&flag3) myliftor.set_direction(2)

else if(!flag3&&flag2) myliftor.set_direction(1)

int main(int argc, char *argv[])

liftor myliftor

char flag

int j

myliftor.direction=1

printf("**************************************\n")

printf("该程序用于模拟10(0-9)层的电梯控制\n")

printf("先输入按下电梯的层号及上下选\n择(类似电梯外的按钮)\n")

printf("每到一层时,输入乘客要到的楼\n层号(类似电梯内的按钮)\n")

为了简单,分配了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=1i<10i++)

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()

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7793759.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-09
下一篇 2023-04-09

发表评论

登录后才能评论

评论列表(0条)

保存