Advertisement
luciana1237

aviao3.0

Jul 26th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include <time.h>
  7.  
  8.  
  9. #define MAX 10
  10. #define MAX_PRATELEIRAS 20
  11.  
  12. struct Info {
  13.     int vetor[MAX],x,v[MAX],pista[MAX];
  14.     char str[MAX];
  15.  
  16. };
  17.  
  18. typedef struct Info info;
  19.  
  20. typedef struct Celula {
  21.    
  22.     info *dados;
  23.     struct Celula *ant;
  24.     struct Celula *prox;
  25.    
  26. }cel;
  27.  
  28. struct Node {
  29.     unsigned int prateleiras1[MAX_PRATELEIRAS];
  30. };
  31.  
  32. typedef struct Node decolar;
  33.  
  34. typedef  struct Queue {
  35.    
  36.     decolar *date1;
  37.     struct Queue *begin;
  38.     struct Queue *_next;
  39. }queue;
  40.  
  41.  
  42.  
  43. int size =0x0,fall,_size =0,fuel;
  44.  
  45. int random_id()
  46. {
  47.     srand(time(NULL));
  48.    
  49.     return rand() %1000;
  50. }
  51.  
  52. cel *cria_cel(void)
  53. {
  54.     cel *c = (cel *) malloc(sizeof(cel));
  55.    
  56.     if (c!= NULL)
  57.         c->ant = NULL;
  58.         c->prox = NULL;
  59.     return c;
  60. }
  61.  
  62.  
  63. bool isEmpty(cel *c)
  64. {
  65.     return (c->prox == NULL);
  66. }
  67.  
  68. bool Empty(queue *q)
  69. {
  70.     return (q->_next == NULL);
  71. }
  72.  
  73.  
  74.  
  75. bool Push(cel **c,info * pointer,int idAviao)
  76. {
  77.     cel *novo = (cel *) malloc(sizeof(cel));
  78.     cel *aux;
  79.     int y,r,t_clock,Mm;
  80.    
  81.     srand(time(NULL));
  82.    
  83.     t_clock = rand() %6;
  84.    
  85.    
  86.     if (novo == NULL)
  87.     {
  88.         fprintf(stderr," erro "); exit( 0 );
  89.     }
  90.    
  91.     novo->dados = pointer;
  92.     novo->prox = NULL;
  93.     novo->ant = (*c);
  94.    
  95.     for(y=t_clock; y >=0; y--){
  96.         sleep( 1 );  /* Para Windows Sleep(1000); */
  97.        
  98.         #ifdef linux /* se o sitema operacional for o linux */
  99.             system("clear");
  100.         #else /* se nao */
  101.             system("cls");
  102.             #endif
  103.  
  104.        
  105.         printf("\n\t-=========================================-\n");
  106.         printf("\n\t|TEMPO PREVISTO PARA PROXIMA ATERRISAGEM  |\n\n");
  107.         printf("\n\t| TEMPO: \t{ 00 : %d }                   |\n",y);
  108.         printf("\n\t-=========================================- \n");
  109.        
  110.         if (y==0){
  111.             Mm=Mm+1;
  112.             if (Mm == 1)
  113.                 r = rand() %6;
  114.                
  115.                 if (r == 1 || r==2 || r== 3 || r==4 || r==5){
  116.                     sleep( 2 ); /* Para Windows Sleep(2000); */
  117.                    
  118.                     printf("\n\t********************************\n");
  119.                     printf("\n\t|[+] AVIAO => %d Aterrisando [+]|\n",idAviao);
  120.                     printf("\n\t********************************");
  121.                    
  122.                     //novo->dados->prateleiras1[ pos ] = idAviao;
  123.                    
  124.                     sleep( 2 );
  125.                    
  126.                     printf("\nAVIAO => %d ATERRISADO COM SUCESSO \n",idAviao);
  127.                     printf("\nOK\n");
  128.                     if(isEmpty(*c)){
  129.                    
  130.                         (*c)->prox =novo;
  131.                     }else{
  132.                         printf("tem");
  133.                        
  134.                         aux = (*c)->prox;
  135.        
  136.                         while(aux->prox != NULL){
  137.                             aux = aux->prox;
  138.                         }
  139.                         aux->prox = novo;
  140.                         aux->ant = aux;
  141.                
  142.                        }
  143.                 }else {
  144.                     sleep( 3 );
  145.                     printf("\n\n[-] AVIAO %d CAIU!! [-]",idAviao);
  146.                     fall++;
  147.                     size--;
  148.                 }
  149.             }
  150.         }
  151.    
  152.     size++;
  153.     return true;
  154. }
  155.  
  156. void ShowList_aterrisagem(cel **c)
  157. {
  158.     int count=0;
  159.  
  160.     cel *pointer;
  161.     pointer = (*c)->prox;
  162.  
  163.     if(isEmpty(*c))
  164.         printf("----LISTA VAZIA----");
  165.     if (!isEmpty(*c))
  166.         for(; count < size; count++)
  167.             printf("\nPISTA %d AVIAO ID: =>  [ %d ]\n",count,pointer->dados->pista[count]);
  168. }
  169.  
  170. int sizeList(cel **c)
  171. {
  172.     size_t count = 0;
  173.  
  174.     if (!isEmpty(*c)){
  175.         cel *pointer = (*c)->prox;
  176.         for(; pointer != NULL; pointer =pointer->prox)
  177.             count++;
  178.     }if (isEmpty(*c))
  179.         printf("----LISTA VAZIA----");
  180.  
  181.  
  182.     return count;
  183. }
  184.  
  185.  
  186. void libera_lista(cel **c)
  187. {
  188.     cel *no;
  189.     if (!isEmpty(*c)){
  190.         while((*c)->prox != NULL){
  191.             no = (*c);
  192.             (*c) = (*c)->prox;
  193.            
  194.             free(no);
  195.             size--;
  196.         }
  197.     }if(isEmpty(*c))
  198.         printf("\n ----LISTA VAZIA----\n");
  199. }
  200.  
  201. queue *queue_create(void)
  202. {
  203.     queue *q = (queue *) malloc(sizeof(queue));
  204.    
  205.     if (q != NULL)
  206.         q->begin = NULL;
  207.         q->_next = NULL;
  208.     return q;
  209. }
  210.  
  211. bool enfileirar_decolagem(queue **q,decolar *p,int IDaviao)
  212. {
  213.     queue *novo = (queue *) malloc(sizeof(queue));
  214.     queue *aux;
  215.    
  216.     int y,r,t_clock,Mm;
  217.    
  218.     if(novo == NULL)
  219.     {
  220.         fprintf(stderr," erro ");
  221.         exit( 0 );
  222.     }
  223.     srand(time(NULL));
  224.    
  225.     t_clock = rand() %6;
  226.    
  227.     novo->date1 = p;
  228.     novo->_next = NULL;
  229.     novo->begin = (*q);
  230.    
  231.     for(y=t_clock; y >=0; y--){
  232.         sleep( 1 );  /* Para Windows Sleep(1000); */
  233.        
  234.         #ifdef linux /* se o sitema operacional for o linux */
  235.             system("clear");
  236.         #else /* se nao */
  237.             system("cls");
  238.             #endif
  239.  
  240.        
  241.         printf("\n\t-=========================================-\n");
  242.         printf("\n\t|TEMPO PREVISTO PARA PROXIMA DECOLAGEM   |\n\n");
  243.         printf("\n\t| TEMPO: \t{ 00 : %d }                   |\n",y);
  244.         printf("\n\t-=========================================- \n");
  245.        
  246.         if (y==0){
  247.             Mm=Mm+1;
  248.             if (Mm == 1)
  249.                 r = rand() %6;
  250.                
  251.                 if (r == 1 || r==2 || r== 3 || r==4 || r==5){
  252.                     sleep( 2 ); /* Para Windows Sleep(2000); */
  253.                    
  254.                     printf("\n\t********************************\n");
  255.                     printf("\n\t|[+] AVIAO => %d DECOLANDO [+]|\n",IDaviao);
  256.                     printf("\n\t********************************");
  257.                    
  258.                     //novo->dados->prateleiras1[ pos ] = idAviao;
  259.                    
  260.                     sleep( 2 );
  261.                    
  262.                     printf("\nAVIAO => %d DECOLADO COM SUCESSO \n",IDaviao);
  263.                     printf("\nOK\n");
  264.                     if(Empty(*q)){
  265.                    
  266.                         (*q)->_next =novo;
  267.                     }else{
  268.                         printf("tem");
  269.                        
  270.                         aux = (*q)->_next;
  271.        
  272.                         while(aux->_next != NULL){
  273.                             aux = aux->_next;
  274.                         }
  275.                         aux->_next = novo;
  276.                         aux->begin = aux;
  277.                
  278.                        }
  279.                 }else {
  280.                     sleep( 3 );
  281.                     printf("\n\n[-] AVIAO %d SEM COMBUSTIVEL!! [-]",IDaviao);
  282.                     fuel++;
  283.                     _size--;
  284.                 }
  285.             }
  286.         }
  287.    
  288.     _size++;
  289.     return true;
  290.    
  291.    
  292. }
  293.  
  294. void ShowList_decolagem(queue **q)
  295. {
  296.    
  297.     int count=0;
  298.  
  299.     queue *pointer;
  300.     pointer = (*q)->_next;
  301.  
  302.     if(Empty(*q))
  303.         printf("----LISTA VAZIA----");
  304.     if (!Empty(*q))
  305.         for(; count < _size; count++)
  306.             printf("\nPISTA %d AVIAO ID: =>  [ %d ]\n",count,pointer->date1->prateleiras1[count]);
  307. }
  308.  
  309. void libera_lista_decolagem(queue **q)
  310. {
  311.     queue *no;
  312.     if (!Empty(*q)){
  313.         while((*q)->_next != NULL){
  314.             no = (*q);
  315.             (*q) = (*q)->_next;
  316.            
  317.             free(no);
  318.             _size--;
  319.         }
  320.     }if(Empty(*q))
  321.         printf("\n ----LISTA VAZIA----\n");
  322. }
  323.  
  324. int sizeList_decolagem(queue **q)
  325. {
  326.     int count = 0;
  327.  
  328.     if (!Empty(*q)){
  329.         queue *pointer = (*q)->_next;
  330.         for(; pointer != NULL; pointer =pointer->_next)
  331.             count++;
  332.     }if (Empty(*q))
  333.         printf("----LISTA VAZIA----");
  334.  
  335.  
  336.     return count;
  337. }
  338.  
  339. int main()
  340. {
  341.  
  342.     int _opc,elem,pos,tam_v,x,prat;
  343.     info p;
  344.     decolar dc;
  345.  
  346.     cel *c = cria_cel();
  347.    
  348.     queue *q = queue_create();
  349.  
  350.     for(;;){
  351.         x= random_id();
  352.        
  353.         printf("\n\t(0)----------- SAIR ");
  354.         printf("\n\t(1)----------- INSERIR AVIAO NA FILA DE POUSO ");
  355.         printf("\n\t(2)----------- INSERIR AVIAO NA FILA DE DECOLAGEM ");
  356.         printf("\n\t(3)----------- MOSTRAR FILA ( POUSO ) ");
  357.         printf("\n\t(4)----------- MOSTRAR FILA ( DECOLAGEM )\n");
  358.        
  359.         printf("> "); scanf("%d",&_opc);
  360.        
  361.         switch(_opc){
  362.             case 0:
  363.                 exit( 0 );
  364.             default:
  365.                 fprintf(stdout,"[-] COMANDO INVALIDO!!! [-]");
  366.                 break;
  367.             case 1:
  368.                 printf("\n INFORME O NUMERO DA PISTA (0 a 3):\n");
  369.                 printf("> "); scanf("%d",&pos);
  370.                
  371.                 p.pista[pos] = x;
  372.                 Push(&c,&p,x);
  373.                
  374.                 break;
  375.             case 2:
  376.                 printf("\n INFORME O NUMERO DA PRATELEIRA (0  a 4):  ");
  377.                 scanf("%d",&prat);
  378.                 dc.prateleiras1[prat] =x;
  379.                 enfileirar_decolagem(&q,&dc,x);
  380.                 break;
  381.             case 3:
  382.                 ShowList(&c);
  383.                 break;
  384.             case 4:
  385.                 ShowList_decolagem(&q);
  386.                 break;
  387.             case 6:
  388.                 libera_lista(&c);
  389.                 break;
  390.         }
  391.        
  392.     }
  393.     return 0;
  394.  
  395.  
  396.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement