Advertisement
Jvsierra

Prob 2 com funções

Aug 4th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4.  
  5. #define LIM 51
  6. #define TFC 2
  7. #define TFV 500
  8. #define TFP 5
  9. #define TFCOL 3
  10.  
  11. int buscaCliente(char nomesClientes[TFC][LIM], char clienteProcurado[]);
  12. int buscaProduto(char nomesProdutos[TFP][LIM], char produtoProcurado[]);
  13.  
  14. int main()
  15. {
  16. char nomesCli[TFC][LIM], nomesProd[TFP][LIM], cliAux[LIM], prodAux[LIM];
  17. int matVendas[TFV][TFCOL], posProd, posCli, l, c, cont, tlVendas = 0, estoque[TFP], qntd;
  18. float preco[TFP], totParc, totVenda;
  19.  
  20. printf("Cadastro de clientes\n");
  21.  
  22. for(l = 0; l < TFC; l++)
  23. {
  24. printf("Digite o nome do %do cliente:\n", l+1);
  25. fflush(stdin);
  26. gets(nomesCli[l]);
  27. }
  28.  
  29. printf("Cadastro de produtos\n");
  30.  
  31. for(l = 0; l < TFP; l++)
  32. {
  33. printf("Digite o nome do %do produto:\n", l+1);
  34. fflush(stdin);
  35. gets(nomesProd[l]);
  36.  
  37. printf("Digite o preco:\n");
  38. scanf("%f", &preco[l]);
  39.  
  40. printf("Digite a quantidade em estoque:\n");
  41. scanf("%d", &estoque[l]);
  42. }
  43.  
  44. printf("Digite o nome do cliente:\n");
  45. fflush(stdin);
  46. gets(cliAux);
  47.  
  48. while(tlVendas < TFV && strcmp(cliAux, "") != 0)
  49. {
  50. posCli = buscaCliente(nomesCli, cliAux);
  51.  
  52. if(posCli == -1)
  53. printf("Cliente inexistente\n");
  54. else
  55. {
  56. printf("Digite o nome do produto:\n");
  57. fflush(stdin);
  58. gets(prodAux);
  59.  
  60. while(tlVendas < TFV && strcmp(prodAux, "") != 0)
  61. {
  62. posProd = buscaProduto(nomesProd, prodAux);
  63.  
  64. if(posProd == -1)
  65. printf("Produto inexistente\n");
  66. else
  67. {
  68. printf("Digite a quantidade:\n");
  69. scanf("%d", &qntd);
  70.  
  71. if(estoque[posProd] < qntd)
  72. printf("Estoque insuficiente\n");
  73. else
  74. {
  75. matVendas[tlVendas][0] = posCli;
  76. matVendas[tlVendas][1] = posProd;
  77. matVendas[tlVendas][2] = qntd;
  78.  
  79. estoque[posProd] -= qntd;
  80.  
  81. tlVendas++;
  82.  
  83. printf("Venda efetuada\n");
  84. }
  85. }
  86.  
  87. if(tlVendas < TFV)
  88. {
  89. printf("Digite o nome do produto:\n");
  90. fflush(stdin);
  91. gets(prodAux);
  92. }
  93. }
  94. }
  95.  
  96. if(tlVendas < TFV)
  97. {
  98. printf("Digite o nome do cliente:\n");
  99. fflush(stdin);
  100. gets(cliAux);
  101. }
  102. }
  103.  
  104. for(l = 0; l < tlVendas; l+= cont)
  105. {
  106. cont = 0;
  107. totVenda = 0;
  108.  
  109. printf("Cliente: %d - %s\n", matVendas[l][0], nomesCli[matVendas[l][0]]);
  110.  
  111. for(c = l; c < tlVendas && matVendas[c][0] == matVendas[l][0]; c++)
  112. {
  113. printf("Produto %d - %s ", matVendas[c][1], nomesProd[matVendas[c][1]]);
  114. printf("Preco: %.2f ", preco[matVendas[c][1]]);
  115.  
  116. printf("Quantidade: %d ", matVendas[c][2]);
  117.  
  118. totParc = preco[matVendas[c][1]] * matVendas[c][2];
  119.  
  120. printf("Total: %.2f\n", totParc);
  121.  
  122. totVenda += totParc;
  123.  
  124. cont++;
  125. }
  126.  
  127. printf("Total da Venda: %.2f\n\n", totVenda);
  128.  
  129. }
  130.  
  131. printf("\nExibicao dos produtos em estoque\n\n");
  132.  
  133. for(l = 0; l < TFP; l++)
  134. {
  135. printf("Produto: %d - %s ", l, nomesProd[l]);
  136. printf("Preco: %.2f ", preco[l]);
  137. printf("Quantidade em estoque: %d\n", estoque[l]);
  138.  
  139. printf("\n");
  140. }
  141.  
  142. getch();
  143. }
  144.  
  145. int buscaCliente(char nomesClientes[TFC][LIM], char clienteProcurado[])
  146. {
  147. int pos;
  148.  
  149. pos = 0;
  150.  
  151. while(pos < TFC && strcmp(nomesClientes[pos], clienteProcurado) != 0)
  152. pos++;
  153.  
  154. if(pos == TFC)
  155. pos = -1;
  156.  
  157. return pos;
  158. }
  159.  
  160. int buscaProduto(char nomesProdutos[TFP][LIM], char produtoProcurado[])
  161. {
  162. int pos = 0;
  163.  
  164. while(pos < TFP && strcmp(produtoProcurado, nomesProdutos[pos]) != 0)
  165. pos++;
  166.  
  167. if(pos == TFP)
  168. pos = -1;
  169.  
  170. return pos;
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement