Advertisement
rrcfs

Aula 409 atp2

Sep 4th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.50 KB | None | 0 0
  1. #include<conio2.h>
  2. #include<stdlib.h>
  3. #include<stdio.h>  //bibliotecas
  4. #include<string.h>
  5. #include<ctype.h>
  6. #define TF 10
  7. //declaração de funções ou prototipos
  8. char menu(void);
  9. void Executa(void);
  10. void Vendas(TpProd Produtos[TF], int tam);
  11. int Busca(TpProd Tabela[TF], int TL, char Prod[20]);
  12. //void cadastro(TpProd TabProd[TF], int &tam);
  13. //void Relatorio(TpProd Tabela[TF], int qtde);
  14.  
  15. struct TpProd //cosntantes
  16. {
  17.     int cod, qtde;
  18.     char Descr[10];  //structs
  19.     float valor;   
  20. };
  21. void Vendas(TpProd Produtos[TF], int tam)
  22. {
  23.     int p, qt;
  24.     char AuxDescr[20];
  25.     printf("\nDescricao do Produto:");
  26.     gets(AuxDescr);
  27.     while(strcmp(AuxDescr,"\0")!=0)
  28.     {
  29.         p=Busca(Produtos, tam, AuxDescr);
  30.         if(p==-1)
  31.         printf("\nNao encontrado\n");
  32.         else
  33.         {
  34.             printf("\nProduto Encontrado\n");
  35.             printf("Codigo:%d\n", Produtos[p].cod);
  36.             printf("Descrição:%s\n", Produtos[p].Descr);
  37.             printf("Estoque:%d\n", Produtos[p].Qtd);
  38.             printf("Valor Un R$:%.2f\n", Produtos[p].valor);
  39.        
  40.         printf("Quantidade:");
  41.         scanf("%d", &qt);
  42.         if(qt>Produtos[p].Qtde)
  43.             printf("\n Quantidade Insuficiente\n");
  44.         else
  45.         {
  46.             printf("\nValor total R$ %.2f\n", qt*Produto[p].valor);
  47.             Produtos[p].Qtde=Produtos[p].Qtde-qt;
  48.             printf("\nVenda Realizada!\n");
  49.         }
  50.         }
  51.         getch();
  52.         printf("\nDescricao do Produto:");
  53.         gets(AuxDescr);
  54.     }
  55.    
  56. };
  57.  
  58. char menu(void)
  59. {
  60.     clrscr();
  61.     printf("\n##Menu de Opcao##\n");
  62.     printf("\n[C]adastro");
  63.     printf("\n[E]xibe");
  64.     printf("\n[V]enda");
  65.     printf("\n[A]d. Estoque\n");
  66.     printf("\nopcao");
  67.     return toupper (getch());
  68. };
  69. void cadastro(TpProd TabProd[TF], int &tam)
  70. {
  71.     int auxProd;
  72.     printf("Codigo do Produto:\n");
  73.     scanf("%d", &auxProd);
  74.     while(tam<TF &&auxProd!=0)
  75.     {
  76.         TabProd[tam].cod=auxProd;
  77.         printf("Descricao:\n");fflush(stdin);
  78.         gets(TabProd[tam].Descr);
  79.        
  80.         printf("QTDE. Inicial:\n");
  81.         scanf("%d", &TabProd[tam].qtde);
  82.        
  83.         printf("Valor:\n");
  84.         scanf("%d", &TabProd[tam].valor);
  85.         tam++;
  86.        
  87.         printf("Codido do Pruduto\n");
  88.         scanf("%d", &auxProd);
  89.     }
  90. };
  91. void Executa (void)
  92. {
  93.     TpProd Tab[TF];
  94.     int TL=0;
  95.     char op;
  96.     do
  97.     {
  98.         op=menu();clrscr();
  99.         switch(op)
  100.         {
  101.             case 'C': printf("\nCadastra Produto\n");
  102.             cadastro(Tab, TL);break;
  103.             case 'E':printf("\nRelatorio de Produtos\n");
  104.             //relatorio (Tab, TL);break;
  105.             case 'V':printf("\nVendas de Produtos\n");
  106.             printf("\nVendas");
  107.             vendas(Tab, TL);
  108.             break;
  109.             case 'A':printf("\nAdiciona Estoque\n");
  110.             break;
  111.         }
  112.     }while(op!=27);
  113. };
  114. int main()
  115. {   Executa();
  116.     return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement