Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define imprime show_decolagem()
- #define LIMPAR printf("\033[H")
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <unistd.h>
- struct pista_decolagem
- {
- int prateleiras[5],prateleirasf[5];
- unsigned int id,idf[5];
- union
- {
- struct pista_decolagem *prox;
- };
- };
- typedef struct Fila_d
- {
- struct pista_decolagem *dados;
- union
- {
- struct pista_decolagem *fim,*inicio;
- };
- }fila_d;
- struct tempo_t
- {
- int Hh,Mm;
- };
- struct pista_aterrissagem
- {
- int prateleiras[5],v[5];
- unsigned int id,idf;
- union
- {
- struct pista_aterrissagem *next;
- };
- };
- typedef struct fila_a
- {
- struct pista_aterrissagem *dates;
- union
- {
- struct pista_aterrissagem *begin,*end;
- };
- }queue;
- struct tempo_a
- {
- unsigned int Hh,Mm;
- };
- int fall=0,count=0,count1=0,fail=0;
- void show_decolagem()
- {
- for(int i=0; i <1; i++){
- sleep(2);
- printf("\033[H");
- printf("\n\t _ _ ");
- printf("\n\t ( ` )_ ");
- printf("\n\t ( ) `) ");
- printf("\n\t (_ (_ . _) _) ");
- printf("\n\t ______ ");
- printf("\n\t _L _~-L___ ");
- printf("\n\t = = ==(____AA____D ");
- printf("\n\t L_____L___________________,-~~~~~~~`-.._ ");
- printf("\n\t - - / o O o o o o O O o o o o o o O o |L_ ");
- printf("\n\t -- `~-.__ ___..----.. ) ");
- printf("\n\t -- `---~~L___________/------------````` ");
- printf("\n\t - = ===(_________D ");
- }
- for(int i=0; i <1;i++)
- {
- sleep(2);
- printf("\033[H");
- printf("\n\t _ _ ");
- printf("\n\t ( ` )_ ");
- printf("\n\t ( ) `) ");
- printf("\n\t (_ (_ . _) _) ");
- printf("\n\t ______ ");
- printf("\n\t _L _~-L___ ");
- printf("\n\t = = ==(____AA____D ");
- printf("\n\t L_____L___________________,-~~~~~~~`-.._ ");
- printf("\n\t --- / o O o o o o O O o o o o o o O o |L_ ");
- printf("\n\t -- `~-.__ ___..----.. ) ");
- printf("\n\t --- `---~~L___________/------------````` ");
- printf("\n\t -- = ===(_________D ");
- }
- for(int y=0; y <1; y++)
- {
- sleep(2);
- printf("\033[H");
- printf("\n\t _ _ ");
- printf("\n\t ( ` )_ ");
- printf("\n\t ( ) `) ");
- printf("\n\t (_ (_ . _) _) ");
- printf("\n\t ______ ");
- printf("\n\t _L _~-L___ ");
- printf("\n\t = = ==(____AA____D ");
- printf("\n\t L_____L___________________,-~~~~~~~`-.._ ");
- printf("\n\t - - / o O o o o o O O o o o o o o O o |L_ ");
- printf("\n\t -- `~-.__ ___..----.. ) ");
- printf("\n\t -- `---~~L___________/------------````` ");
- printf("\n\t - = ===(_________D ");
- }
- for(int j=0; j <1; j++)
- {
- sleep(2);
- printf("\033[H");
- printf("\n\t _ _ ");
- printf("\n\t ( ` )_ ");
- printf("\n\t ( ) `) ");
- printf("\n\t (_ (_ . _) _) ");
- printf("\n\t ______ ");
- printf("\n\t _L _~-L___ ");
- printf("\n\t = = ==(____AA____D ");
- printf("\n\t L_____L___________________,-~~~~~~~`-.._ ");
- printf("\n\t - - / o O o o o o O O o o o o o o O o |L_ ");
- printf("\n\t -- `~-.__ ___..----.. ) ");
- printf("\n\t -- `---~~L___________/------------````` ");
- printf("\n\t - = ===(_________D ");
- //printf("\n\t
- }
- for(int i=0; i <1; i++)
- {
- sleep(2);
- printf("\033[H");
- printf("\n\t ______ ");
- printf("\n\t _L _~-L___ ");
- printf("\n\t = = ==(____AA____D ");
- printf("\n\t L_____L___________________,-~~~~~~~`-.._ ");
- printf("\n\t - - / o O o o o o O O o o o o o o O o |L_ ");
- printf("\n\t -- `~-.__ ___..----.. ) ");
- printf("\n\t -- `---~~L___________/------------````` ");
- printf("\n\t - = ===(_________D ");
- //printf("\n\t
- LIMPAR;
- }
- }
- void ArteAir()
- {
- sleep(2);
- printf("\n\t _ _ ");
- printf("\n\t ( ` )_ ");
- printf("\n\t ( ) `) ");
- printf("\n\t (_ (_ . _) _) ");
- printf("\n\t | ");
- printf("\n\t | ");
- printf("\n\t ´´ .-'-. ´´ ´´ ");
- printf("\n\t ' ___ ' ");
- printf("\n\t ---------' .-. '--------- ");
- printf("\n\t _________________________' '-' '_________________________ ");
- printf("\n\t ''''''-|---|--L L==][^',_m_,'^][==L L--|---|-'''''' ");
- printf("\n\t L L ||L H L|| L L ");
- printf("\n\t '--' OO O|O OO '--' ");
- LIMPAR;
- for(int y=0; y <2; y++)
- {
- sleep(2);
- printf("\n\t _ _ ");
- printf("\n\t ( ` )_ ");
- printf("\n\t ( ) `) ");
- printf("\n\t (_ (_ . _) _) ");
- printf("\n\t | ");
- printf("\n\t | ");
- printf("\n\t ´´ .-'-. ´´ ´´ ");
- printf("\n\t ' ___ ' ");
- printf("\n\t ---------' .-. '--------- ");
- printf("\n\t _________________________' '-' '_________________________ ");
- printf("\n\t ''''''-|---|--L L==][^',_m_,'^][==L L--|---|-'''''' ");
- printf("\n\t L L ||L H L|| L L ");
- printf("\n\t '--' OO O|O OO '--' ");
- LIMPAR;
- }
- }
- int random_id_airplane()
- {
- srand(time(NULL));
- return rand() %10000;
- }
- fila_d *Create_Queue_Airplane(void)
- {
- fila_d *f = (fila_d *) malloc(sizeof(fila_d));
- if (f != NULL)
- f->inicio = NULL;
- f->fim = NULL;
- return f;
- }
- int enqueue_airplane(fila_d **f,int id_airplane)
- {
- struct pista_decolagem *p1 = (struct pista_decolagem *) malloc(sizeof(struct pista_decolagem));
- struct tempo_t t_d;
- int opc,i=0;
- srand(time(NULL));
- int r;
- p1->prateleiras[i] = id_airplane;
- t_d.Mm = rand() %5;
- if (t_d.Mm != 0)
- {
- printf("AVIAO %d esta pronto para decolar ",id_airplane);
- sleep(2);
- for(; t_d.Mm >0; t_d.Mm--)
- {
- printf("\n FALTAM {0: %d } Para Proxima Decolagem \n",t_d.Mm);
- sleep(1); /* se for no windows 1000 */
- if (t_d.Mm == 1)
- {
- r= rand() %5;
- if (r == 1 || r==2 || r==3 || r== 4 || r==5)
- {
- printf("Tempo Esta bom para decolagem \n");
- printf("\n AVIAO %d DECOLANDO \n",id_airplane);
- imprime;
- if (p1 != NULL)
- {
- p1->id = id_airplane;
- p1->prox = NULL;
- if ((*f)->inicio == NULL)
- {
- /*insira no inicio */
- (*f)->inicio = p1;
- }else
- {
- (*f)->fim->prox =p1;
- }
- }
- }else if (r == 0)
- {
- printf("\n DESEJA COLOAR O AVIAO PRA DECOLAR TEMPO NAO ESTA BOM PARA DECOLAGEM (1/SIM) (2/NAO)\n");
- printf("> "); scanf("%d",&opc);
- switch(opc)
- {
- default:
- break;
- case 1:
- r = rand() %10;
- if (r >1 || r <5)
- {
- printf("AVIAO %d Decolando ",id_airplane);
- imprime;
- if ((*f)->inicio == NULL)
- {
- (*f)->inicio =p1;
- }else
- {
- (*f)->fim->prox =p1;
- }
- }else
- {
- printf("aviao perdendo a força \n");
- r = rand() %10;
- if (r %2 ==0)
- {
- printf("aviao conseguiu voar");
- }else
- {
- printf("AVIAO SEM COMBUSTIVEL \n");
- fall++;
- p1->prateleirasf[fall] = id_airplane;
- count--;
- }
- }
- break;
- case 2:
- printf("AVIAO %d NA FILA DE ESPERA PARA DECOLAGEM \n",id_airplane);
- break;
- }
- }
- }
- }
- }
- count++;
- return 1;
- }
- void SHOW(fila_d **f)
- {
- struct pista_decolagem *p1;
- int i=0;
- printf("QUANTIDADE DE AVIAOS DECOLADOS %d \n",count);
- sleep(1);
- if ((*f)->inicio == NULL)
- {
- return;
- }else
- {
- for(p1 = (*f)->inicio; p1 != NULL; p1=p1->prox)
- {
- printf("ID AVIAO %d \n",p1->id);
- }
- printf("QUANTIDADE DE AVIAOES SEM COMBUSTIVEL %d \n",fall);
- if (fall == 0)
- {
- return;
- }else
- {
- for(int y=0; y <=fall; y++)
- {
- printf("ID AVIAO: %d \n",p1->prateleirasf[y]);
- }
- }
- }
- }
- queue *Create_Queue_Aterrissagem(void)
- {
- queue *q = (queue *) malloc(sizeof(queue));
- if (q != NULL)
- q->begin = NULL;
- q->end = NULL;
- return q;
- }
- int Enqueue(queue **q,int id_aviao)
- {
- struct pista_aterrissagem *pointer = (struct pista_aterrissagem *) malloc(sizeof(struct pista_aterrissagem));
- struct tempo_a t_a;
- int r;
- printf("AVIAO %d Aterrisando...\n",id_aviao);
- sleep(2);
- for(t_a.Mm = rand() % 5; t_a.Mm >0; t_a.Mm--)
- {
- printf("TEMPO PREVISTO PARA ATERRISAGEM {0 : %d } \n",t_a.Mm);
- sleep(1);
- if (t_a.Mm == 1)
- {
- r = rand() % 5;
- printf("AVIAO %d Aterrisando \n",id_aviao);
- ArteAir();
- sleep(2);
- if ( r > 1 || r <5)
- {
- if (pointer != NULL)
- {
- pointer->id = id_aviao;
- pointer->next = NULL;
- if ((*q)->begin == NULL)
- {
- (*q)->begin = pointer;
- }else
- {
- (*q)->end->next = pointer;
- }
- }else
- {
- printf("AVIAO COM PROBLEMAS NA ATERRISAGEM \n");
- sleep(2);
- r = rand() %10;
- if (r > 1 || r < 5)
- {
- printf("AVIAO MESMO COM PROBLEMAS CONSEGUIU ATERRISAR COM SUCESSO \n");
- ArteAir();
- if ((*q)->begin == NULL)
- {
- (*q)->begin =pointer;
- }else
- {
- (*q)->end->next = pointer;
- }
- }else
- {
- sleep(1);
- printf("AVIAO %d CAIU \n",id_aviao);
- fail++;
- pointer->v[fall] = id_aviao;
- count1--;
- }
- }
- }
- }
- }
- count1++;
- return 1;
- }
- void MostrarAterrissagem(queue **q)
- {
- struct pista_aterrissagem *pointer;
- int y=0;
- printf(" #-------------------------------------------------#");
- printf("# QUANTIDADE DE AVIAOS ATERRISSADOS COM SUCCESSO %d #\n",count1);
- if ((*q)->begin == NULL)
- {
- return;
- }else
- {
- printf("AVIAOS ATERRISADOS COM SUCESSO \n");
- for(pointer = (*q)->begin; pointer != NULL; pointer=pointer->next)
- {
- y++;
- printf("PRATELEIRA [%d]: id AVIAO: %d \n",y,pointer->id);
- }
- printf("QUANTIDADE DE AVIOES CAIDOS %d \n",fail);
- if (fail ==0)
- {
- return ;
- }else
- {
- for(int j=0; j <fail; j++)
- {
- printf("ID AVIAOS CAIDOS %d \n",pointer->v[j]);
- }
- }
- }
- }
- /*void winColorir(int Y, int B) {
- WORD wColor = ((B & 0x0F) << 4) + (Y & 0x0F);
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
- }*/
- int LiberarDecolagem(fila_d **f)
- {
- struct pista_decolagem *p1;
- struct pista_decolagem *p2;
- p2 = (*f)->inicio;
- for(p1 = (*f)->inicio; p1 != NULL; p1 = p1->prox)
- {
- free(p1);
- }
- return 1;
- }
- int LiberarAterrissagem(queue **q)
- {
- struct pista_decolagem *p1;
- return 1;
- }
- int main(void)
- {
- fila_d *f = Create_Queue_Airplane();
- queue *q = Create_Queue_Aterrissagem();
- int opc,r;
- do
- {
- r = random_id_airplane();
- printf("\n\t (0) --------- [SAIR]");
- printf("\n\t (1) --------- [DECOLAGEM] ");
- printf("\n\t (2) --------- [ATERRISAGEM] ");
- printf("\n\t (3) --------- [LISTAR/DECOLAGEM] ");
- printf("\n\t (4) --------- [LISTAR/ATERRISSAGEM] ");
- printf("\n\t (5) [LIBERAR/DECOLAGEM] ");
- printf("\n\t (6) [LIBERAR/ATERRISSAGEM] \n ");
- printf("> "); scanf("%d",&opc);
- switch(opc)
- {
- default:
- break;
- case 0:
- exit( 0 );
- case 1:
- enqueue_airplane(&f,r);
- break;
- case 2:
- Enqueue(&q,r);
- break;
- case 3:
- SHOW(&f);
- break;
- case 4:
- MostrarAterrissagem(&q);
- break;
- case 5:
- LiberarDecolagem(&f);
- break;
- case 6:
- LiberarAterrissagem(&q);
- }
- }while(opc !=0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement