Advertisement
luciana1237

aviao13:25

Jul 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <time.h>
  5. #include <unistd.h>
  6.  
  7. #define MAX_PISTAS 3
  8. #define MAX_PRATELEIRAS 4
  9.  
  10. typedef struct No {
  11.  
  12.     unsigned int fall,prateleiras[MAX_PRATELEIRAS];
  13.     struct No *prox;
  14.  
  15. }elem;
  16.  
  17. struct Fila{
  18.  
  19.     elem *inicio;
  20.     elem *fim;
  21.  
  22. };
  23.  
  24. typedef struct Node {
  25.     unsigned int prateleiras1[MAX_PRATELEIRAS];
  26.     struct Node *_next;
  27. }decolar;
  28.  
  29. struct Queue {
  30.     decolar *begin;
  31.     decolar *end;
  32. };
  33.  
  34. typedef struct Fila fila;
  35. typedef struct Queue queue;
  36.  
  37.  
  38. int size=0,_size=0;
  39. int pista[MAX_PISTAS];
  40.  
  41. int random_id()
  42. {
  43.     srand(time(NULL));
  44.  
  45.     return rand() %1000;
  46. }
  47.  
  48.  
  49. fila *fila_cria(void)
  50. {
  51.     fila *f= (fila *) malloc(sizeof(fila));
  52.  
  53.     if (f != NULL)
  54.         f->inicio = NULL;
  55.         f->fim = NULL;
  56.     return f;
  57.  
  58. }
  59. queue *queue_create(void)
  60. {
  61.     queue *q = (queue *) malloc(sizeof(queue));
  62.  
  63.     if (q != NULL)
  64.         q->begin = NULL;
  65.         q->end = NULL;
  66.     return q;
  67. }
  68.  
  69. bool isEmpty(fila *f)
  70. {
  71.     return (f->inicio == NULL);
  72. }
  73. bool Empty(queue *q)
  74. {
  75.     return (q->begin == NULL);
  76. }
  77.  
  78. bool aterrisar(fila *f,int p,int idAviao)
  79. {
  80.     elem *no = (elem *) malloc(sizeof(elem));
  81.     int y,r,Mm=0,clock;
  82.     no->fall =0;
  83.     no->prox = NULL;
  84.  
  85.     if (no == NULL)
  86.     {
  87.         fprintf(stderr," erro \n"); exit( 0 );
  88.    
  89.     }
  90.  
  91.     srand(time(NULL));
  92.  
  93.     clock = rand() % 10;
  94.  
  95.     for(y=clock; y >=0; y--){
  96.        
  97.         sleep( 1 );
  98.        
  99.         #ifdef linux
  100.             system("clear");
  101.         #else
  102.             system("cls");
  103.             #endif
  104.  
  105.         printf("\n\t-=========================================-\n");
  106.         printf("\n\t|TEMPO PREVISTO PARA PROXIMA ATERRISAGEM  |\n\n");
  107.         printf("\n\t| TEMPO: \t%d                             |\n",y);
  108.         printf("\n\t-=========================================- \n");
  109.  
  110.         if (y == 0){
  111.             Mm =Mm+1;
  112.             if (Mm == 1)
  113.                 r = rand() % 4;
  114.  
  115.                 if (r == 2 || r== 3 || r==4){
  116.                    
  117.                     printf("\n\t********************************\n");
  118.                     printf("\n\t|[+] AVIAO => %d Aterrisando [+]|\n",idAviao);
  119.                     printf("\n\t********************************");
  120.                     sleep( 2 );
  121.                     //no->prox = NULL;
  122.                     no->prateleiras[ p ] =  idAviao;
  123.                    
  124.                     printf("\n[+] AVIAO: %d ATERRISADO COM SUCESSO!!! [+]\n",idAviao);
  125.  
  126.                     if (isEmpty(f))
  127.                         f->inicio = no;
  128.                     else
  129.                         f->fim->prox = no;
  130.                 }else {
  131.                     sleep( 3 );
  132.                     printf("\n\t[-] AVIAO %d CAIU!! [-]\n",idAviao);
  133.                     no->fall++;
  134.                     size--;
  135.                 }
  136.         }
  137.     }
  138.     size++;
  139.     f->fim = no;
  140.     return true;
  141. }
  142.  
  143. bool decolar_aviao(queue *q,int p, int IdAviao)
  144. {
  145.     decolar *node = (decolar *) malloc(sizeof(decolar));
  146.     int y,r,clock,Mm;
  147.     clock = rand() %10;
  148.  
  149.     srand(time(NULL));
  150.  
  151.     if (node == NULL)
  152.     {
  153.         fprintf(stderr, " error "); exit( 0 );
  154.     }
  155.     node->_next = NULL;
  156.  
  157.     for(y=clock; y >=0; y--){
  158.         sleep ( 1 );
  159.  
  160.         printf("\n\t ==========================================\n");
  161.         printf("\n\t| TEMPO PREVISTO PARA PROXIMA DECOLAGEM:   |\n\n");
  162.         printf("\n\t| TEMPO: \t%d                              |\n",y);
  163.         printf("\n\t ========================================== \n");
  164.        
  165.         if (y== 0){
  166.             Mm = Mm+1;
  167.             if (Mm == 1)
  168.                 r = rand() % 4;
  169.  
  170.                 if (r == 1 || r==2 || r== 3){
  171.                     sleep( 2 );
  172.                     printf("\n\t****************************\n");
  173.                     printf("\n\t| AVIAO => %d Decolando...  |\n",IdAviao);
  174.                     printf("\n\t****************************");
  175.  
  176.                     node->prateleiras1[ p ] = IdAviao;
  177.                     printf("\nAVIAO => %d DECOLADO COM SUCESSO \n",IdAviao);
  178.  
  179.                     if (Empty(q))
  180.                         q->begin =node;
  181.                     else
  182.                         q->end->_next = node;
  183.                 }else {
  184.                     sleep( 1 );
  185.                     printf("\n\n[-] AVIAO SEM COMBUSTIVEL [-]\n\n");
  186.                     _size--;
  187.                 }
  188.         }
  189.     }
  190.     q->end = node;
  191.     _size++;
  192.     return true;
  193.  
  194. }
  195.  
  196. void mostra_pouso(fila *f)
  197. {
  198.     int i;
  199.    
  200. }
  201.  
  202. void mostra_decolar(queue *q)
  203. {
  204.     int y;
  205. }
  206.  
  207.  
  208. int main()
  209. {
  210.     fila *f = fila_cria();
  211.     queue *q = queue_create();
  212.  
  213.     int opc,pis,prat;
  214.  
  215.     for(;;){
  216.        
  217.         int x = random_id();
  218.         printf("\n\t( 0 )-----SAIR \n");
  219.         printf("\n\t( 1 )----- INSERIR AVIAO NA FILA DE POUSO \n");
  220.         printf("\n\t( 2 )----- INSERIR AVIAO NA FILA DE DECOLAGEM \n");
  221.         printf("\n\t( 3 )----- MOSTRAR FILA ( POUSO ) \n");
  222.         printf("\n\t( 4 )----- MOSTRAR FILA ( DECOLAGEM )\n");
  223.  
  224.         printf("> "); scanf("%d",&opc);
  225.  
  226.         switch(opc){
  227.             default:
  228.                 break;
  229.             case 0:
  230.                 printf("Saindo...");
  231.                 sleep( 1 );
  232.                 exit( 0 );
  233.             case 1:
  234.                 printf("\n (Informe o numero da pista): ");
  235.                 scanf("%d",&pis);
  236.                 aterrisar(f,pis,x);
  237.                 break;
  238.             case 2:
  239.                 printf("\n (Informe o numero da prateleira): ");
  240.                 scanf("%d",&prat);
  241.                 decolar_aviao(q,prat,x);
  242.                 break;
  243.             case 3:
  244.                 mostra_pouso(f);
  245.                 break;
  246.             case 4:
  247.                 mostra_decolar(q);
  248.                 break;
  249.         }
  250.     }
  251.     return 0;
  252.  
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement