C 언어 주차장 시 뮬 레이 션 관리 프로그램의 설계 와 실현

62516 단어 데이터 구조
****         n        ,      ,            。     ,           ,     ,          。          ,     ,          ,        。            。

1)           :    ,   ,    
2)          ,  (   ,  )。

//   
#include
#include			/*system(cls)        */
#include			/*getch()        */
#include
#include
#include

#include 


//   
#define MAX_LEN  15	
#define MAX_STOP  5			//      5    
#define MAX_PAVE  3         //            ,     
#define MAX 105  

#define price 2//     2 
  
//   
//  
typedef struct  {
	char license_plate[10]; //      ,           
    char state[3];          //       ,  s         ,  p        ,           i  
 
	int inhour;
    int inminute;
    int outhour;
    int outminute;

}CAR;
//   
typedef struct{ 
	CAR STOP[MAX_STOP];     //          
	int top;                //        
}STOPPING;
//    
typedef struct{ 
	CAR BUFF[MAX_STOP];     //          
	int top;                //             
}BUFFER;
//  
typedef struct{
	CAR PAVE[MAX_PAVE-1];   //          
	int front, rear;        //           
	int count;              //       
}PAVEMENT;



STOPPING *s;   //   
BUFFER *b;     //    
PAVEMENT *p;   //  
char carname[17];

int Timeh[MAX_STOP];//           
int Timem[MAX_STOP];//           
int timeh;		  //          
int timem;		  //          
int totaltime;

//--------------------------------------------------------
//    
STOPPING *init_stopping();  //   “    ”
BUFFER *init_buff();	    //   “   ”
PAVEMENT *init_pavement();  //   “    ”
void car_come();			//      “    ”,       
void stop_to_buff();		//     “    ”   “   ”
void buff_to_stop();		//     “   ”   “    ”
void pave_to_stop();		//     “    ”   “    ”	
void Car_to_pave(PAVEMENT *p,char name[MAX_LEN]);//      
void display();				//         
void welcome();				//    
void come();				//           
void leave();				//           
void Car_mid();				//            
void out_Time();            //         
//--------------------------------------------------------

//    
void welcome()                       
{
	system("cls");
	printf("




"
); printf("\t\t|-------------------------------** **-------------------------------|
"
); printf("
"
); printf("\t\t|\t\t , 【1】 。 |
"
); printf("\t\t|\t\t , 【2】 。 |
"
); printf("\t\t|\t\t , 【3】|
"
); printf("\t\t|\t\t , 【0】 。 |
"
); printf("\t\t|\t\t : 【Enter】 【 】 |
"
); printf("\t\t|\t\t : |
"
); printf("
"
); printf("\t\t|--------------------------------------------------------------------------------|

"
); printf("\t\t\tplease choose (0-3): "); } // “ ” STOPPING *init_stopping() { STOPPING *s=(STOPPING*)malloc(sizeof(STOPPING));// s->top=-1; return s; } // “ ” BUFFER *init_buff() { BUFFER *b=(BUFFER*)malloc(sizeof(BUFFER)); // b->top=-1; return b; } // “ ” PAVEMENT *init_pavement() { PAVEMENT *p=(PAVEMENT*)malloc(sizeof(PAVEMENT));// p->front=p->rear=MAX_PAVE-1; // p->count=0; return p; } // void Car_to_pave(PAVEMENT *p,char name[MAX_LEN]) { if(p->count>0&&p->front==(p->rear+1)%MAX_PAVE)// , { printf("Sorry! , 。
"
); return ; } else { p->rear=(p->rear+1)%MAX_PAVE; p->count++; strcpy(p->PAVE[p->rear].license_plate,carname); strcpy(p->PAVE[p->rear].state,"p");// printf("%s , !
"
,carname); printf("%s %d
"
,carname,p->rear+1);// :1--5 } } // “ ”, void car_come() { printf(" , (h,m):
"
); s->top++; scanf(" %d:%d",&s->STOP[s->top].inhour,&s->STOP[s->top].inminute);// Timeh[s->top]=s->STOP[s->top].inhour; Timem[s->top]=s->STOP[s->top].inminute;// strcpy(s->STOP[s->top].license_plate,carname);// strcpy(s->STOP[s->top].state,"s"); // printf("%s , !
"
,carname); printf("%s %d
"
,carname,s->top+1); } // void come() { printf(" :"); scanf("%s",carname); if(s->top==MAX_STOP-1)// { Car_to_pave(p,carname);// } else { printf("
"
); // “ ”, car_come(); } } // “ ” “ ” void stop_to_buff() { strcpy(b->BUFF[++b->top].license_plate,s->STOP[s->top+1].license_plate);// strcpy(s->STOP[s->top+1].state,"i"); // printf(" %s
"
,s->STOP[s->top+1].license_plate); } // “ ” “ ” void buff_to_stop() { while(b->top>=0)// { strcpy(s->STOP[++s->top].license_plate,b->BUFF[b->top--].license_plate); } } // “ ” “ ” void pave_to_stop() { int i; strcpy(s->STOP[++s->top].license_plate,p->PAVE[p->front].license_plate);// printf(" %s %d
"
,p->PAVE[p->front].license_plate,s->top+1); if(p->count>1) { for(i=p->front+1; i<p->count; i++) { strcpy(p->PAVE[i-1].license_plate,p->PAVE[i].license_plate);// , } p->rear--; p->front--; p->count--; } else// 1 { p->rear=MAX_PAVE-1; p->front=MAX_PAVE-1; p->count=0; } } // void Car_mid() { int find = 0; while(s->top>=0) { if(strcmp(s->STOP[s->top--].license_plate,carname)==0)// , { find = 1; break; } else { // “ ” “ ” stop_to_buff(); } } if(!find)// { printf(" !
"
); while(b->top>=0)// { strcpy(s->STOP[++s->top].license_plate,b->BUFF[b->top--].license_plate); } return ; } else { out_Time(); // “ ” “ ” buff_to_stop (); if(s->top<=MAX_STOP-1&&p->count>0)// { p->front=(p->front+1)%MAX_PAVE; // “ ” “ ” pave_to_stop(); } } } // void out_Time() { int i; printf(" :
"
); scanf("%d:%d",&s->STOP[s->top+1].outhour,&s->STOP[s->top+1].outminute); timeh=s->STOP[s->top+1].outhour;// timem=s->STOP[s->top+1].outminute;// if(Timeh[s->top+1]==timeh)// , { totaltime=1; } else { totaltime=timeh-Timeh[s->top+1]+(timem>Timem[s->top+1]?1:0);// , } printf(" %s
"
,s->STOP[s->top+1].license_plate); printf(" %d , %d
"
,totaltime,price*totaltime); if(s->top+1>=0) { for(i=s->top+1; i<MAX_STOP-1; i++) { Timeh[i]=Timeh[i+1];// Timem[i]=Timem[i+1];// } Timeh[MAX_STOP]=timeh; Timem[MAX_STOP]=timem;// ; , } } // void leave() { printf(" :"); scanf("%s",carname); if(s->top<0) // printf(" !
"
); else Car_mid(); } void display() { int i; if(s->top==-1) { printf(" !
"
); } else { printf(" %d , %d , %d , %d
"
,MAX_STOP,s->top+1,MAX_PAVE-1,p->count); if(p->count>0) { printf(" :
"
); for(i=0; i<=s->top; i++) { printf("%d :%s
"
,i+1,s->STOP[i].license_plate); } printf(" :
"
); for(i=0; i<p->count; i++) { printf("%d :%s
"
,i+1,p->PAVE[i].license_plate); } } else { printf(" :
"
); for(i=0; i<=s->top; i++) { printf("%s
"
,s->STOP[i].license_plate); } printf(" !
"
); } } } int main() { s=init_stopping(); // “ ” b=init_buff(); // “ ” p=init_pavement(); // “ ” int option; welcome(); scanf("%d",&option); while(option) { switch(option) { case 1: come();break; case 2: leave();break; case 3: display();break; default: break; } getch(); welcome(); scanf("%d",&option); } printf(" , !
"
); return 0; } [](http://ddrv.cn/a/83269)

좋은 웹페이지 즐겨찾기