Advertisement
luciana1237

aviao12

Jul 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.63 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.  
  9. typedef struct No {
  10.  
  11.     int fall;
  12.     struct No *prox;
  13.  
  14. }elem;
  15.  
  16. struct Fila{
  17.  
  18.     elem *inicio;
  19.     elem *fim;
  20.  
  21. };
  22.  
  23. typedef struct Node {
  24.     int _size;
  25.     struct Node *_next;
  26. }decolar;
  27.  
  28. struct Queue {
  29.     decolar *begin;
  30.     decolar *end;
  31. };
  32.  
  33. typedef struct Fila fila;
  34. typedef struct Queue queue;
  35.  
  36.  
  37. int size=0;
  38. int pista[MAX_PISTAS],prateleiras[MAX_PISTAS];
  39.  
  40. int random_id()
  41. {
  42.     srand(time(NULL) *5);
  43.  
  44.     return rand() %1000;
  45. }
  46.  
  47.  
  48. fila *fila_cria(void)
  49. {
  50.     fila *f= (fila *) malloc(sizeof(fila));
  51.  
  52.     if (f != NULL)
  53.         f->inicio = NULL;
  54.         f->fim = NULL;
  55.     return f;
  56.  
  57. }
  58. queue *queue_create(void)
  59. {
  60.     queue *q = (queue *) malloc(sizeof(queue));
  61.  
  62.     if (q != NULL)
  63.         q->begin = NULL;
  64.         q->end = NULL;
  65.     return q;
  66. }
  67.  
  68. bool isEmpty(fila *f)
  69. {
  70.     return (f->inicio == NULL);
  71. }
  72. bool Empty(queue *q)
  73. {
  74.     return (q->begin == NULL);
  75. }
  76.  
  77. bool aterrisar(fila *f,int p,int idAviao)
  78. {
  79.     elem *no = (elem *) malloc(sizeof(elem));
  80.     int y,r,Mm=0,clock;
  81.     no->fall =0;
  82.     no->prox = NULL;
  83.  
  84.     if (no == NULL)
  85.     {
  86.         fprintf(stderr," erro \n"); exit( 0 );
  87.    
  88.     }
  89.  
  90.     srand(time(NULL));
  91.  
  92.     clock = rand() % 30;
  93.  
  94.     printf("\n\nOK\n\n");
  95.  
  96.     for(y=clock; y >=0; y--){
  97.        
  98.         sleep( 1 );
  99.  
  100.         printf("Tempo previsto Para Aterrisagem [ %d ] \n",y);
  101.  
  102.         if (y == 0){
  103.             Mm =Mm+1;
  104.             if (Mm == 1)
  105.                 r = rand() % 4;
  106.  
  107.                 if (r == 2 || r== 3 || r==4){
  108.                    
  109.                     printf("\naviao aterrisando...\n");
  110.                     sleep( 2 );
  111.                     //no->prox = NULL;
  112.                     prateleiras[ p ] =  idAviao;
  113.                     printf("\n\nAviao Aterrisado com Sucesso \n\n");
  114.  
  115.                     if (isEmpty(f))
  116.                         f->inicio = no;
  117.                     else
  118.                         f->fim->prox = no;
  119.                 }else {
  120.                     printf("\n\nAviao Caiu \n\n");
  121.                     no->fall++;
  122.                 }
  123.         }
  124.     }
  125.     size++;
  126.     f->fim = no;
  127.     return true;
  128. }
  129.  
  130. bool decolar_aviao(queue *q,int p, int IdAviao)
  131. {
  132.     decolar *node = (decolar *) malloc(sizeof(decolar));
  133.     int y,r,clock,Mm;
  134.  
  135.     srand(time(NULL));
  136.  
  137.     if (node == NULL)
  138.     {
  139.         fprintf(stderr, " erro "); exit( 0 );
  140.     }
  141.     node->_next = NULL;
  142.     node->_size =0;
  143.  
  144.     for(y=clock; y >=0; y--){
  145.         sleep ( 1 );
  146.         printf("Tempo espeerado para a decolagem %d \n",y);
  147.        
  148.         if (y== 0){
  149.             Mm = Mm+1;
  150.             if (Mm == 1)
  151.                 r = rand() % 4;
  152.  
  153.                 if (r == 1 || r==2 || r== 3){
  154.                     sleep( 2 );
  155.                     printf("Aviao %d Decolando \n",IdAviao);
  156.                     prateleiras[ p ] = IdAviao;
  157.                     printf("Aviao Decolado Com Sucesso \n");
  158.  
  159.                     if (Empty(q))
  160.                         q->begin =node;
  161.                     else
  162.                         q->end->_next = node;
  163.                 }else {
  164.                     printf("\n\nAviao sem combustivel \n\n");
  165.                 }
  166.         }
  167.     }
  168.     q->end = node;
  169.     node->_size++;
  170.     return true;
  171.  
  172. }
  173.  
  174. void imprime()
  175. {
  176.     int i;
  177.     for(i=0; i < size; i++)
  178.         printf("Elemento da Prateleiras => ID Aviao: %d \n",prateleiras[ i ]);
  179. }
  180.  
  181.  
  182. int main()
  183. {
  184.     fila *f = fila_cria();
  185.     int x = random_id();
  186.     //srand(time(NULL));
  187.     //aterrisar(f,0,x);
  188.     //imprime(f);
  189.  
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement