Advertisement
luciana1237

Untitled

Aug 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.39 KB | None | 0 0
  1. /*programa que simula uma biqueira */
  2.  
  3. #include <stdio.h> /*I/O*/
  4. #include <stdlib.h>/*malloc */
  5. #include <stdbool.h>/*bool*/
  6. #include <time.h>/*srand && rand */
  7. #include <unistd.h> /*sleep */
  8.  
  9.  
  10. typedef struct Queue
  11. {
  12.     int qtd_po,qtd_mac,qtd_crack,xlen,len,size;
  13.     struct Queue *begin,*end;
  14. }queue;
  15.  
  16.  
  17. queue *queue_create(void)
  18. {
  19.     queue *q = (queue *) malloc(sizeof(queue));
  20.    
  21.     if (q!= NULL)
  22.         q->begin =NULL;
  23.         q->end = NULL;
  24.    
  25.     return q;
  26. }
  27.  
  28. typedef struct
  29. {
  30.     int Hh,Mm,hours,Minutes,secunds,dd;
  31. }t;
  32.  
  33.  
  34.  
  35. #define MINUTES 3
  36.  
  37. int len=0,size=0,_size1=0,lucro=0,lucro1=0,lucro2=0;
  38.  
  39. int random_id(void)
  40. {
  41.     srand(time(NULL));
  42.    
  43.     return rand() %1000;
  44. }
  45.  
  46. queue *enfileirar(queue **q,int qtd,int qtd1,int qtd2)
  47. {
  48.     queue *novo = (queue *) malloc(sizeof(queue));
  49.     int y,r,x,k,horas,minutos;
  50.    
  51.     printf("\nINFORME A HORA ATUAL: \n");
  52.     printf("HH/MM \n > "); scanf("%d %d",&horas,&minutos);
  53.    
  54.     printf("")
  55.    
  56.     t *clock_t = (t *) malloc(sizeof(t));
  57.    
  58.     clock_t->Hh = horas;
  59.     clock_t->Mm = minutos;
  60.    
  61.     while(1){
  62.         for(clock_t->secunds=0; clock_t->secunds <=MINUTES; clock_t->secunds++){
  63.             sleep(0x1);
  64.            
  65.             printf("\nSAO EXATAMENTE: { %d : %d : %d } \n",clock_t->Hh,clock_t->Mm,clock_t->secunds);
  66.        
  67.             if (clock_t->secunds == MINUTES)
  68.             {
  69.                 clock_t->Mm = clock_t->Mm+1;
  70.                
  71.                 if (clock_t->Mm >= 59){
  72.                     clock_t->Hh = clock_t->Hh+1;
  73.                     clock_t->Mm = 0;
  74.                     }if (clock_t->Hh == 59)
  75.                         clock_t->Hh = clock_t->Hh+1;
  76.                         if (clock_t->Hh >= 23)
  77.                             clock_t->Hh = clock_t->Hh =0;
  78.             }
  79.         }
  80.     }
  81.  
  82.     return novo;
  83.        
  84. }
  85.  
  86. void show(queue **q)
  87. {
  88.    
  89.     printf("\n\t---------------------------");
  90.     printf("\n\t|MACONHA | COCAINA | CRACK |");
  91.     printf("\n\t|--------|---------|-------|");
  92.     printf("\n\t|QUANTIDADE| QUANTIDADE | QUANTIDADE |");
  93.     printf("\n\t|   %d   |    %d    |   %d   |",len,size,_size1);
  94.     printf("\n\t| LUCROS |  LUCROS  | LUCROS |");
  95.     printf("\n\t|----------------------------");
  96.     printf("\n\t|  M: %d$|  CO: %d$ | CK:%d$ |",lucro,lucro1,lucro2);
  97.     printf("\n\t|----------------------------|");
  98.    
  99. }
  100.  
  101.  
  102. int main()
  103. {
  104.     queue *q = queue_create();
  105.     int opc,po,mac,cra;
  106.    
  107.     if (q != NULL)
  108.         for(;;){
  109.             printf("\n\t_(0)--------- [ SAIR ]");
  110.             printf("\n\t_(1)--------- [ Enfileirar ] ");
  111.             printf("\n\t_(2)--------- [ TABELA DE LUCROS ] \n");
  112.             printf("> "); scanf("%d",&opc);
  113.            
  114.             switch(opc){
  115.                 case 0:
  116.                     exit( 0 );
  117.                 case 1:
  118.                     printf("\nDIGITE A quantidade dos produtos a ser inseridos \n");
  119.                     printf("PO: "); scanf("%d",&po);
  120.                     printf("\n\tMACONHA: "); scanf("%d",&mac);
  121.                     printf("\n\tCRACK: "); scanf("%d",&cra);
  122.                     q=enfileirar(&q,po,mac,cra);
  123.                     break;
  124.                 default:
  125.                     break;
  126.                 case 2:
  127.                     show(&q);
  128.                     break;
  129.                
  130.             }
  131.            
  132.         }
  133.         return 0;
  134.        
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement