Advertisement
luciana1237

Untitled

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