Advertisement
luciana1237

Untitled

Aug 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.33 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,lucro_geral=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.     t *clock_t = (t *) malloc(sizeof(t));
  50.    
  51.     int y,r,x,k,horas,minutos;
  52.     x= random_id();
  53.    
  54.     printf("\nINFORME A HORA ATUAL: \n");
  55.     printf("HH/MM \n > "); scanf("%d %d",&horas,&minutos);
  56.    
  57.     printf("\nDigite a hora da entrega: ");
  58.     printf("HH/MM \n > ");
  59.     scanf("%d %d",&clock_t->hours,&clock_t->Minutes);
  60.    
  61.     srand(time(NULL));
  62.    
  63.     (*q)->qtd_mac =qtd;
  64.     (*q)->qtd_crack =qtd1;
  65.     (*q)->qtd_po=qtd2;
  66.  
  67.    
  68.     clock_t->Hh = horas;
  69.     clock_t->Mm = minutos;
  70.    
  71.     while(1){
  72.        
  73.         for(clock_t->secunds=0; clock_t->secunds <=MINUTES; clock_t->secunds++){
  74.             sleep(0x1);
  75.            
  76.             printf("\nSAO EXATAMENTE: { %d : %d : %d } \n",clock_t->Hh,clock_t->Mm,clock_t->secunds);
  77.        
  78.             if (clock_t->secunds == MINUTES)
  79.             {
  80.                 clock_t->Mm = clock_t->Mm+1;
  81.                
  82.                 if (clock_t->Mm >= 59){
  83.                     clock_t->Hh = clock_t->Hh+1;
  84.                     clock_t->Mm = 0;
  85.                     }if (clock_t->Hh == 59)
  86.                         clock_t->Hh = clock_t->Hh+1;
  87.                         if (clock_t->Hh >= 23){
  88.                             clock_t->Hh = clock_t->Hh =0;
  89.                             }if ((clock_t->Hh && clock_t->Mm == clock_t->hours && clock_t->Minutes))
  90.                             {
  91.                                 printf("ok");
  92.                                
  93.                                 r= rand() %4;
  94.                                
  95.                                 if (r == 1)
  96.                                 {
  97.                                     k = rand() %10;
  98.                                     if (k !=0)
  99.                                     {
  100.                                         printf("CLIENTE: %d quer %d de Maconha \n",x,k);
  101.                                         printf("\nCONFERINDO....\n");
  102.                                         sleep(2);
  103.                                        
  104.                                         if (k > (*q)->qtd_mac)
  105.                                         {
  106.                                             printf("CONFERINDO...\n");
  107.                                             sleep(2);
  108.                                             printf("\n[!] nao tem essa quantidade no momento...\n");
  109.                                         }else
  110.                                         {
  111.                                             sleep(1);
  112.                                             printf("CLIENTE: %d Comprou %d quantidade de maconha \n",x,k);
  113.                                             (*q)->qtd_mac = (*q)->qtd_mac -k;
  114.                                             lucro = lucro+10*k;
  115.                                             len++;
  116.                                         }
  117.                                     }else
  118.                                     {
  119.                                         sleep(2);
  120.                                         printf("\nVc foi pego pela policia \n");
  121.                                         lucro_geral =0;
  122.                                        
  123.                                     }
  124.                                 }else if (r == 2)
  125.                                 {
  126.                                     k=rand() %10;
  127.                                     if (k!=0)
  128.                                     {
  129.                                         printf("CLIENTE: %d quer %d de po \n",x,k);
  130.                                         printf("\nCONFERINDO....\n");
  131.                                         sleep(2);
  132.                                        
  133.                                         if (k > (*q)->qtd_po)
  134.                                         {
  135.                                             printf("CONFERINDO...\n");
  136.                                             sleep(1);
  137.                                             printf("\nNAO TEM ESSA quantidade no momneto\n");
  138.                                         }else
  139.                                         {
  140.                                             sleep(1);
  141.                                             printf("\nCLIENTE: %d comprou d quantidade",x,k);
  142.                                             (*q)->qtd_po = (*q)->qtd_po-k;
  143.                                             lucro1=lucro1+20*k;
  144.                                             size++;
  145.                                         }
  146.                                     }else
  147.                                     {
  148.                                         sleep(2);
  149.                                         printf("\nVc foi pego pela policia \n");
  150.                                         lucro_geral =0;
  151.                                     }
  152.                                 }else if (r ==3)
  153.                                 {
  154.                                     k=rand() %10;
  155.                                     if (k != 0)
  156.                                     {
  157.                                         printf("\nCLIENTE %d quer %d de pedra \n",x,k);
  158.                                         if (k > (*q)->qtd_crack)
  159.                                         {
  160.                                             printf("\nCONFERINDO...");
  161.                                             sleep(2);
  162.                                             printf("\nindisponivel no momento \n");
  163.                                         }else
  164.                                         {
  165.                                             printf("\nCLIENTE %d: comprou %d de P \n",x,k);
  166.                                             (*q)->qtd_crack = (*q)->qtd_crack-k;
  167.                                             lucro2 = lucro2+5*k;
  168.                                             _size1++;
  169.                                         }
  170.                                     }
  171.                                 }
  172.                         }
  173.                     }
  174.                 }
  175.             }
  176.     lucro_geral = (*q)->qtd_mac+(*q)->qtd_po+(*q)->qtd_crack;
  177.  
  178.     return novo;
  179.        
  180. }
  181.  
  182. void show(queue **q)
  183. {
  184.    
  185.     printf("\n\t---------------------------");
  186.     printf("\n\t|MACONHA | COCAINA | CRACK |");
  187.     printf("\n\t|--------|---------|-------|");
  188.     printf("\n\t|QUANTIDADE| QUANTIDADE | QUANTIDADE |");
  189.     printf("\n\t|   %d   |    %d    |   %d   |",len,size,_size1);
  190.     printf("\n\t| LUCROS |  LUCROS  | LUCROS |");
  191.     printf("\n\t|----------------------------");
  192.     printf("\n\t|  M: %d$|  CO: %d$ | CK:%d$ |",lucro,lucro1,lucro2);
  193.     printf("\n\t|----------------------------|");
  194.    
  195. }
  196.  
  197.  
  198. int main()
  199. {
  200.     queue *q = queue_create();
  201.     int opc,po,mac,cra;
  202.    
  203.     if (q != NULL)
  204.         for(;;){
  205.             printf("\n\t_(0)--------- [ SAIR ]");
  206.             printf("\n\t_(1)--------- [ Enfileirar ] ");
  207.             printf("\n\t_(2)--------- [ TABELA DE LUCROS ] \n");
  208.             printf("> "); scanf("%d",&opc);
  209.            
  210.             switch(opc){
  211.                 case 0:
  212.                     exit( 0 );
  213.                 case 1:
  214.                     printf("\nDIGITE A quantidade dos produtos a ser inseridos \n");
  215.                     printf("PO: "); scanf("%d",&po);
  216.                     printf("\n\tMACONHA: "); scanf("%d",&mac);
  217.                     printf("\n\tCRACK: "); scanf("%d",&cra);
  218.                     q=enfileirar(&q,po,mac,cra);
  219.                     break;
  220.                 default:
  221.                     break;
  222.                 case 2:
  223.                     show(&q);
  224.                     break;
  225.                
  226.             }
  227.            
  228.         }
  229.         return 0;
  230.        
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement