Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <conio.h>
- #define LIM_TITULO 101
- #define LIM_CLASSIFICACAO 11
- #define TF 300
- struct TpFilme
- {
- int Ano, Duracao;
- float Gasto, Renda, TaxaEspec;
- char Titulo[LIM_TITULO], Classificacao[LIM_CLASSIFICACAO];
- };
- void OrdenaAnos(int Anos[TF], int TL)
- {
- int a, b, Aux;
- for(a = 0; a < TL - 1; a++)
- for(b = a + 1; b < TL; b++)
- if(Anos[a] > Anos[b])
- {
- Aux = Anos[a];
- Anos[a] = Anos[b];
- Anos[b] = Aux;
- }
- }
- void OrdenaProducao(TpFilme V[TF], int TL)
- {
- int a, b;
- TpFilme Aux;
- for(a = 0; a < TL - 1; a++)
- for(b = a + 1; b < TL; b++)
- if(V[a].TaxaEspec > V[a].TaxaEspec)
- {
- Aux = V[a];
- V[a] = V[b];
- V[b] = Aux;
- }
- }
- int AnoMaior(int Vet[TF], int TL)
- {
- int i, j, Cont, Maior = 0, MaiorAno;
- for(i = 0; i < TL - 1; i++)
- {
- Cont = 1;
- for(j = i + 1; j < TL; j++)
- if(Vet[j] == Vet[i])
- Cont++;
- if(Cont > Maior)
- {
- Maior = Cont;
- MaiorAno = Vet[i];
- }
- }
- return MaiorAno;
- }
- void OrganizaClassificacao(TpFilme V[TF], int TL)
- {
- int a, b;
- TpFilme Aux;
- for(a = 0; a < TL - 1; a++)
- for(b = a + 1; b < TL; b++)
- if(stricmp(V[a].Classificacao, V[a].Classificacao) > 0)
- {
- Aux = V[a];
- V[a] = V[b];
- V[b] = Aux;
- }
- }
- void OrdenaTaxaEspec(TpFilme V[TF], int TL)
- {
- int a, b;
- TpFilme Aux;
- for(a = 0; a < TL - 1; a++)
- for(b = a + 1; b < TL; b++)
- if(V[a].Ano > V[a].Ano)
- {
- Aux = V[a];
- V[a] = V[b];
- V[b] = Aux;
- }
- }
- void GeraRelatoriosFilmes(char NomeArq[100])
- {
- TpFilme Vet[TF], Aux;
- int TL, Anos[TF], i, ContDuracao;
- char NomeMaiorLucro[LIM_TITULO], NomeMaiorTaxa[LIM_TITULO];
- float MaiorLucro, MaiorTaxa, DuracaoMedia, Mediana;
- FILE *PtrTxt;
- system("cls");
- printf("Relatorio do arquivo de filmes\n\n");
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- TL = 0;
- MaiorLucro = 0;
- MaiorTaxa = 0;
- ContDuracao = 0;
- fscanf(PtrTxt, "%10[0-9a-zA-Z ] %d %[^;]%*c; %f %f %d %f", Aux.Titulo, &Aux.Ano, Aux.Classificacao,
- &Aux.Gasto, &Aux.Renda, &Aux.Duracao, &Aux.TaxaEspec);
- while(!feof(PtrTxt))
- {
- if(Aux.Renda - Aux.Gasto > MaiorLucro)
- {
- MaiorLucro = Aux.Renda - Aux.Gasto;
- strcpy(NomeMaiorLucro, Aux.Titulo);
- }
- if(Aux.TaxaEspec > MaiorTaxa)
- {
- MaiorTaxa = Aux.TaxaEspec;
- strcpy(NomeMaiorTaxa, Aux.Titulo);
- }
- Anos[TL] = Aux.Ano;
- ContDuracao += Aux.Duracao;
- Vet[TL++] = Aux;
- fscanf(PtrTxt, "%[^;]%*c %d %[^;]%*c; %f %f %d %f", Aux.Titulo, &Aux.Ano, Aux.Classificacao,
- &Aux.Gasto, &Aux.Renda, &Aux.Duracao, &Aux.TaxaEspec);
- }
- fclose(PtrTxt);
- if(TL == 0)
- printf("Nenhum filme cadastrado\n\n");
- else
- {
- printf("Filme com maior lucro: %s (%.3f milhoes)\n", NomeMaiorLucro, MaiorLucro);
- printf("Filme com a maior taxa de espectadores: %s (%1.f)\n", NomeMaiorTaxa, MaiorTaxa);
- DuracaoMedia = ContDuracao / (float)TL;
- printf("Duracao media: %.2f minutos\n", DuracaoMedia);
- printf("Ano com o maior numero de filmes: %d\n", AnoMaior(Anos, TL));
- OrganizaClassificacao(Vet, TL);
- FILE *PtrAux = fopen("OrdClassificao.txt", "a");
- for(i = 0; i < TL; i++)
- fprintf(PtrAux, "%s; %d %s; %.3f %.3f %d %.1f\n", Vet[i].Titulo, Vet[i].Ano,
- Vet[i].Classificacao, Vet[i].Gasto, Vet[i].Renda, Vet[i].Duracao, Vet[i].TaxaEspec);
- fclose(PtrAux);
- OrdenaProducao(Vet, TL);
- PtrAux= fopen("OrdAno.txt", "a");
- for(i = 0; i < TL; i++)
- fprintf(PtrAux, "%s; %d %s; %.3f %.3f %d %.1f\n", Vet[i].Titulo, Vet[i].Ano,
- Vet[i].Classificacao, Vet[i].Gasto, Vet[i].Renda, Vet[i].Duracao, Vet[i].TaxaEspec);
- fclose(PtrAux);
- OrdenaTaxaEspec(Vet, TL);
- PtrAux = fopen("OrdTaxaEspec.txt", "a");
- for(i = 0; i < TL; i++)
- fprintf(PtrAux, "%s; %d %s; %.3f %.3f %d %.1f\n", Vet[i].Titulo, Vet[i].Ano,
- Vet[i].Classificacao, Vet[i].Gasto, Vet[i].Renda, Vet[i].Duracao, Vet[i].TaxaEspec);
- fclose(PtrAux);
- OrdenaAnos(Anos, TL);
- if(TL % 2 != 0)
- Mediana = Anos[TL / 2];
- else
- Mediana = (Anos[TL / 2] + Anos[TL / 2 - 1]) / 2;
- printf("Mediana: %d anos\n", Mediana);
- }
- }
- getch();
- }
- int main(void)
- {
- GeraRelatoriosFilmes("Filmes.txt");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement