Advertisement
Jvsierra

filmes cpp

Feb 26th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5.  
  6. #define LIM_TITULO 101
  7. #define LIM_CLASSIFICACAO 11
  8. #define TF 300
  9.  
  10. struct TpFilme
  11. {
  12. int Ano, Duracao;
  13. float Gasto, Renda, TaxaEspec;
  14. char Titulo[LIM_TITULO], Classificacao[LIM_CLASSIFICACAO];
  15. };
  16.  
  17. void OrdenaAnos(int Anos[TF], int TL)
  18. {
  19. int a, b, Aux;
  20.  
  21. for(a = 0; a < TL - 1; a++)
  22. for(b = a + 1; b < TL; b++)
  23. if(Anos[a] > Anos[b])
  24. {
  25. Aux = Anos[a];
  26. Anos[a] = Anos[b];
  27. Anos[b] = Aux;
  28. }
  29. }
  30.  
  31. void OrdenaProducao(TpFilme V[TF], int TL)
  32. {
  33. int a, b;
  34. TpFilme Aux;
  35.  
  36. for(a = 0; a < TL - 1; a++)
  37. for(b = a + 1; b < TL; b++)
  38. if(V[a].TaxaEspec > V[a].TaxaEspec)
  39. {
  40. Aux = V[a];
  41. V[a] = V[b];
  42. V[b] = Aux;
  43. }
  44. }
  45.  
  46. int AnoMaior(int Vet[TF], int TL)
  47. {
  48. int i, j, Cont, Maior = 0, MaiorAno;
  49.  
  50. for(i = 0; i < TL - 1; i++)
  51. {
  52. Cont = 1;
  53.  
  54. for(j = i + 1; j < TL; j++)
  55. if(Vet[j] == Vet[i])
  56. Cont++;
  57.  
  58. if(Cont > Maior)
  59. {
  60. Maior = Cont;
  61. MaiorAno = Vet[i];
  62. }
  63. }
  64.  
  65. return MaiorAno;
  66. }
  67.  
  68. void OrganizaClassificacao(TpFilme V[TF], int TL)
  69. {
  70. int a, b;
  71. TpFilme Aux;
  72.  
  73. for(a = 0; a < TL - 1; a++)
  74. for(b = a + 1; b < TL; b++)
  75. if(stricmp(V[a].Classificacao, V[a].Classificacao) > 0)
  76. {
  77. Aux = V[a];
  78. V[a] = V[b];
  79. V[b] = Aux;
  80. }
  81. }
  82.  
  83. void OrdenaTaxaEspec(TpFilme V[TF], int TL)
  84. {
  85. int a, b;
  86. TpFilme Aux;
  87.  
  88. for(a = 0; a < TL - 1; a++)
  89. for(b = a + 1; b < TL; b++)
  90. if(V[a].Ano > V[a].Ano)
  91. {
  92. Aux = V[a];
  93. V[a] = V[b];
  94. V[b] = Aux;
  95. }
  96. }
  97.  
  98. void GeraRelatoriosFilmes(char NomeArq[100])
  99. {
  100. TpFilme Vet[TF], Aux;
  101. int TL, Anos[TF], i, ContDuracao;
  102. char NomeMaiorLucro[LIM_TITULO], NomeMaiorTaxa[LIM_TITULO];
  103. float MaiorLucro, MaiorTaxa, DuracaoMedia, Mediana;
  104. FILE *PtrTxt;
  105.  
  106. system("cls");
  107.  
  108. printf("Relatorio do arquivo de filmes\n\n");
  109.  
  110. PtrTxt = fopen(NomeArq, "r");
  111.  
  112. if(PtrTxt == NULL)
  113. printf("Arquivo %s inexistente\n\n", NomeArq);
  114. else
  115. {
  116. TL = 0;
  117. MaiorLucro = 0;
  118. MaiorTaxa = 0;
  119. ContDuracao = 0;
  120.  
  121. fscanf(PtrTxt, "%10[0-9a-zA-Z ] %d %[^;]%*c; %f %f %d %f", Aux.Titulo, &Aux.Ano, Aux.Classificacao,
  122. &Aux.Gasto, &Aux.Renda, &Aux.Duracao, &Aux.TaxaEspec);
  123.  
  124. while(!feof(PtrTxt))
  125. {
  126. if(Aux.Renda - Aux.Gasto > MaiorLucro)
  127. {
  128. MaiorLucro = Aux.Renda - Aux.Gasto;
  129. strcpy(NomeMaiorLucro, Aux.Titulo);
  130. }
  131.  
  132. if(Aux.TaxaEspec > MaiorTaxa)
  133. {
  134. MaiorTaxa = Aux.TaxaEspec;
  135. strcpy(NomeMaiorTaxa, Aux.Titulo);
  136. }
  137.  
  138. Anos[TL] = Aux.Ano;
  139. ContDuracao += Aux.Duracao;
  140. Vet[TL++] = Aux;
  141.  
  142. fscanf(PtrTxt, "%[^;]%*c %d %[^;]%*c; %f %f %d %f", Aux.Titulo, &Aux.Ano, Aux.Classificacao,
  143. &Aux.Gasto, &Aux.Renda, &Aux.Duracao, &Aux.TaxaEspec);
  144. }
  145.  
  146. fclose(PtrTxt);
  147.  
  148. if(TL == 0)
  149. printf("Nenhum filme cadastrado\n\n");
  150. else
  151. {
  152. printf("Filme com maior lucro: %s (%.3f milhoes)\n", NomeMaiorLucro, MaiorLucro);
  153.  
  154. printf("Filme com a maior taxa de espectadores: %s (%1.f)\n", NomeMaiorTaxa, MaiorTaxa);
  155.  
  156. DuracaoMedia = ContDuracao / (float)TL;
  157.  
  158. printf("Duracao media: %.2f minutos\n", DuracaoMedia);
  159.  
  160. printf("Ano com o maior numero de filmes: %d\n", AnoMaior(Anos, TL));
  161.  
  162. OrganizaClassificacao(Vet, TL);
  163.  
  164. FILE *PtrAux = fopen("OrdClassificao.txt", "a");
  165.  
  166. for(i = 0; i < TL; i++)
  167. fprintf(PtrAux, "%s; %d %s; %.3f %.3f %d %.1f\n", Vet[i].Titulo, Vet[i].Ano,
  168. Vet[i].Classificacao, Vet[i].Gasto, Vet[i].Renda, Vet[i].Duracao, Vet[i].TaxaEspec);
  169.  
  170. fclose(PtrAux);
  171.  
  172. OrdenaProducao(Vet, TL);
  173.  
  174. PtrAux= fopen("OrdAno.txt", "a");
  175.  
  176. for(i = 0; i < TL; i++)
  177. fprintf(PtrAux, "%s; %d %s; %.3f %.3f %d %.1f\n", Vet[i].Titulo, Vet[i].Ano,
  178. Vet[i].Classificacao, Vet[i].Gasto, Vet[i].Renda, Vet[i].Duracao, Vet[i].TaxaEspec);
  179.  
  180. fclose(PtrAux);
  181.  
  182. OrdenaTaxaEspec(Vet, TL);
  183.  
  184. PtrAux = fopen("OrdTaxaEspec.txt", "a");
  185.  
  186. for(i = 0; i < TL; i++)
  187. fprintf(PtrAux, "%s; %d %s; %.3f %.3f %d %.1f\n", Vet[i].Titulo, Vet[i].Ano,
  188. Vet[i].Classificacao, Vet[i].Gasto, Vet[i].Renda, Vet[i].Duracao, Vet[i].TaxaEspec);
  189.  
  190. fclose(PtrAux);
  191.  
  192. OrdenaAnos(Anos, TL);
  193.  
  194. if(TL % 2 != 0)
  195. Mediana = Anos[TL / 2];
  196. else
  197. Mediana = (Anos[TL / 2] + Anos[TL / 2 - 1]) / 2;
  198.  
  199. printf("Mediana: %d anos\n", Mediana);
  200. }
  201. }
  202.  
  203. getch();
  204. }
  205.  
  206. int main(void)
  207. {
  208. GeraRelatoriosFilmes("Filmes.txt");
  209.  
  210. return 0;
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement