Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio2.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #define TFI 100
- #define TFP 10
- struct TpInscrito
- {
- int Ins_Numero, Cod_Palestra1, Cod_Palestra2;
- char Ins_Nome[30], Ins_Sexo, Ins_Cidade[30];
- };
- struct TpPalestra
- {
- int Pal_Codigo, Pal_TotVagas;
- char Pal_Nome[40], Pal_Horario[6];
- };
- struct TpEstatistica
- {
- int Eve_Palestra, Eve_TotalInscritos, Eve_TotInscrFem, Eve_TotInscrMasc;
- float Eve_InscrVagas;
- };
- int BuscaPalestra(TpPalestra Plst[TFP], int TL, int Chave)
- {
- int i = 0;
- while(i < TL && Plst[i].Pal_Codigo != Chave)
- i++;
- if(i < TL)
- return i;
- else
- return -1;
- }
- int BuscaInscritos(TpInscrito Insc[TFI], int TL, int Chave)
- {
- int i = 0;
- while(i < TL && Insc[i].Ins_Numero != Chave)
- i++;
- if(i < TL)
- return i;
- else
- return -1;
- }
- int BuscaEstatistica(TpEstatistica Est[TFP], int TL, int Chave)
- {
- int i = 0;
- while(i < TL && Est[i].Eve_Palestra != Chave)
- i++;
- if(i < TL)
- return i;
- else
- return -1;
- }
- int ValidaExclusao(TpInscrito Insc[TFI], int TLI, int CodPalestra)
- {
- int i = 0;
- while(i < TLI && Insc[i].Cod_Palestra1 != CodPalestra && Insc[i].Cod_Palestra2 != CodPalestra)
- i++;
- if(i == TLI)
- return 1;
- else
- return -1;
- }
- void meustrncpy(char str[40], char dest[40], int inicio, int fim)
- {
- int i, pos = 0;
- strcpy(dest, "\0");
- for(i = inicio; i < fim; i++)
- dest[pos++] = str[i];
- dest[pos] = '\0';
- }
- int ProcuraInicio(char str[40], char chave[40], int n)
- {
- int i = 0;
- while(i < n && toupper(str[i]) == toupper(chave[i]))
- i++;
- if(i == n)
- return 1;
- else
- return -1;
- }
- int ProcuraMeio(char str[40], char chave[40])
- {
- int i, inicio = 0, fim = strlen(chave);
- char dest[40] = "\0";
- for(i = 0; fim < strlen(str) && stricmp(dest, chave) != 0; i++)
- meustrncpy(str, dest, inicio++, fim++);
- if(i < strlen(str) && stricmp(dest, chave) == 0)
- return 1;
- else
- return -1;
- }
- void CalculaEstatistica(TpEstatistica Est[TFP], TpPalestra Plst[TFP], int TLP, int Inicio, int Fim)
- {
- int i;
- for(i = 0; i < Fim; i++)
- Est[i].Eve_InscrVagas = (float)Est[i].Eve_TotalInscritos / Plst[BuscaPalestra(Plst, TLP, Est[i].Eve_Palestra)].Pal_TotVagas;
- }
- void AtualizaEstatistica(TpEstatistica &Est1, TpEstatistica &Est2, char Sexo, int Tipo)
- {
- /*
- Tipo == 1 -> Inserir estatística
- Tipo == 2 -> Remover estatística
- Tipo == 3 -> Alterar sexo da estatística
- Tipo == 4 -> "Swap" entre as estatísticas
- */
- if(Tipo == 1)
- {
- Est1.Eve_TotalInscritos++;
- Est2.Eve_TotalInscritos++;
- if(Sexo == 'M')
- {
- Est1.Eve_TotInscrMasc++;
- Est2.Eve_TotInscrMasc++;
- }
- else
- {
- Est1.Eve_TotInscrFem++;
- Est2.Eve_TotInscrFem++;
- }
- }
- else if(Tipo == 2)
- {
- Est1.Eve_TotalInscritos--;
- Est2.Eve_TotalInscritos--;
- if(Sexo == 'M')
- {
- Est1.Eve_TotInscrMasc--;
- Est2.Eve_TotInscrMasc--;
- }
- else
- {
- Est1.Eve_TotInscrFem--;
- Est2.Eve_TotInscrFem--;
- }
- }
- else if(Tipo == 3)
- {
- if(Sexo == 'M')
- {
- Est1.Eve_TotInscrFem--;
- Est1.Eve_TotInscrMasc++;
- Est2.Eve_TotInscrFem--;
- Est2.Eve_TotInscrMasc++;
- }
- else
- {
- Est1.Eve_TotInscrFem++;
- Est1.Eve_TotInscrMasc--;
- Est2.Eve_TotInscrFem++;
- Est2.Eve_TotInscrMasc--;
- }
- }
- else
- {
- Est1.Eve_InscrVagas--;
- Est2.Eve_InscrVagas++;
- if(Sexo == 'M')
- {
- Est1.Eve_TotInscrMasc--;
- Est2.Eve_TotInscrMasc++;
- }
- else
- {
- Est1.Eve_TotInscrFem--;
- Est2.Eve_TotInscrMasc++;
- }
- }
- }
- void OrdenaInscrito(TpInscrito Insc[TFI], int TLI)
- {
- int i, j;
- TpInscrito Aux;
- for(i = 0; i < TLI - 1; i++)
- for(j = i + 1; j < TLI; j++)
- if(strcmp(Insc[i].Ins_Nome, Insc[j].Ins_Nome) > 0)
- {
- Aux = Insc[i];
- Insc[i] = Insc[j];
- Insc[j] = Aux;
- }
- }
- void OrdenaEstatistica(TpEstatistica Est[TFP], int TL)
- {
- int i, j;
- TpEstatistica Aux;
- for(i = 0; i < TL - 1; i++)
- for(j = i + 1; j < TL; j++)
- if(Est[i].Eve_InscrVagas < Est[j].Eve_InscrVagas)
- {
- Aux = Est[i];
- Est[i] = Est[j];
- Est[j] = Aux;
- }
- }
- void IncluiInscrito(TpInscrito Insc[TFI], int &TLI, TpPalestra Plst[TFP],
- int TLP, TpEstatistica Est[TFP])
- {
- int NumAux, Cont;
- system("cls");
- if(TLP >= 2)
- {
- Cont = 0;
- printf("**Cadastro de Inscritos**\n\n");
- printf("Digite o numero do inscrito:\n");
- scanf("%d", &NumAux);
- while(TLI < TFI && NumAux > 0)
- {
- if(BuscaInscritos(Insc, TLI, NumAux) >= 0)
- printf("Numero do inscrito ja cadastrado\n");
- else
- {
- Insc[TLI].Ins_Numero = NumAux;
- printf("Nome do inscrito:\n");
- fflush(stdin);
- gets(Insc[TLI].Ins_Nome);
- while(strcmp(Insc[TLI].Ins_Nome, "\0") == 0)
- {
- printf("Digite um nome valido:\n");
- fflush(stdin);
- gets(Insc[TLI].Ins_Nome);
- }
- printf("Sexo:\n");
- fflush(stdin);
- scanf("%c", &Insc[TLI].Ins_Sexo);
- Insc[TLI].Ins_Sexo = toupper(Insc[TLI].Ins_Sexo);
- while(Insc[TLI].Ins_Sexo != 'M' && Insc[TLI].Ins_Sexo != 'F')
- {
- textcolor(4);
- printf("Voce digitou uma opcao invalida.\nSexo do inscrito (M/F):\n");
- fflush(stdin);
- scanf("%c", &Insc[TLI].Ins_Sexo);
- Insc[TLI].Ins_Sexo = toupper(Insc[TLI].Ins_Sexo);
- }
- textcolor(7);
- printf("Cidade:\n");
- fflush(stdin);
- gets(Insc[TLI].Ins_Cidade);
- while(strcmp(Insc[TLI].Ins_Cidade, "\0") == 0)
- {
- printf("Digite uma cidade valida:\n");
- fflush(stdin);
- gets(Insc[TLI].Ins_Cidade);
- }
- printf("Codigo da primeira palestra: \n");
- scanf("%d", &Insc[TLI].Cod_Palestra1);
- while(BuscaPalestra(Plst, TLP, Insc[TLI].Cod_Palestra1) == -1)
- {
- textcolor(4);
- printf("Codigo de palestra inexistente\n");
- printf("Codigo da primeira palestra: \n");
- scanf("%d", &Insc[TLI].Cod_Palestra1);
- }
- printf("Codigo da segunda palestra:\n");
- scanf("%d", &Insc[TLI].Cod_Palestra2);
- while(BuscaPalestra(Plst, TLP, Insc[TLI].Cod_Palestra2) == -1
- || Insc[TLI].Cod_Palestra1 == Insc[TLI].Cod_Palestra2)
- {
- textcolor(4);
- printf("Codigo da palestra invalido.\n");
- printf("Codigo da segunda palestra:\n");
- scanf("%d", &Insc[TLI].Cod_Palestra2);
- }
- AtualizaEstatistica(Est[BuscaEstatistica(Est, TLP, Insc[TLI].Cod_Palestra1)],
- Est[BuscaEstatistica(Est, TLP, Insc[TLI].Cod_Palestra2)],
- Insc[TLI].Ins_Sexo, 1);
- TLI++;
- Cont++;
- textcolor(3);
- printf("\nInscrito cadastrado\n\n");
- }
- system("cls");
- textcolor(7);
- printf("Digite o numero do inscrito:\n");
- scanf("%d", &NumAux);
- }
- CalculaEstatistica(Est, Plst, TLP, TLI - Cont, TLI);
- OrdenaEstatistica(Est, TLP);
- OrdenaInscrito(Insc, TLI);
- }
- else
- {
- textcolor(4);
- printf("Nao ha palestras suficientes\n");
- }
- getch();
- }
- void RemoveInscrito(TpInscrito Insc[TFI], int &TLI, TpPalestra Plst[TFP],
- int TLP, TpEstatistica Est[TFP])
- {
- int NumeroAux, Pos, i, PosEst, Cont;
- system("cls");
- printf("Exclusao de inscritos\n\n");
- if(TLI == 0)
- {
- textcolor(4);
- printf("Nenhum inscrito cadastrado\n\n");
- }
- else
- {
- printf("Digite o numero do inscrito (0 para sair):\n");
- scanf("%d", &NumeroAux);
- while(NumeroAux > 0)
- {
- Cont = 0;
- Pos = BuscaInscritos(Insc, TLI, NumeroAux);
- if(Pos == -1)
- {
- textcolor(4);
- printf("Nenhum inscrito com esse numero\n");
- }
- else
- {
- AtualizaEstatistica(Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra1)],
- Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra2)],
- Insc[Pos].Ins_Sexo, 2);
- CalculaEstatistica(Est, Plst, TLP, 0, TLP);
- for(; Pos < TLI - 1; Pos++)
- Insc[Pos] = Insc[Pos + 1];
- TLI--;
- textcolor(3);
- printf("Inscrito excluido\n");
- }
- printf("Digite o numero do inscrito (0 para sair):\n");
- scanf("%d", &NumeroAux);
- }
- }
- getch();
- }
- char MenuAlteraInscrito(void)
- {
- printf("Escolha:\n");
- printf("[A] - Alterar nome\n");
- printf("[B] - Alterar sexo\n");
- printf("[C] - Alterar cidade\n");
- printf("[D] - Alterar codigo da primeira palestra\n");
- printf("[E] - Alterar codigo da segunda palestra\n");
- printf("[ESC] - Sair\n");
- return toupper(getche());
- }
- void AlteraInscrito(TpInscrito Insc[TFI], int TLI, TpPalestra Plst[TFP], int TLP,
- TpEstatistica Est[TFP])
- {
- int Pos, NumAux, PalAux;
- char Op, AuxS, StrAux[30];
- system("cls");
- printf("**Alteração inscritos**\n\n");
- if(TLI == 0)
- printf("Nenhum inscrito cadastrado\n\n");
- else
- {
- printf("Digite o numero do inscrito (0 para sair):\n");
- scanf("%d", &NumAux);
- while(NumAux > 0)
- {
- Pos = BuscaInscritos(Insc, TLI, NumAux);
- if(Pos == -1)
- {
- textcolor(4);
- printf("Nenhum inscrito com esse numero\n");
- }
- else
- {
- Op = MenuAlteraInscrito();
- while(Op != 27)
- {
- switch(Op)
- {
- case 'A':
- printf("Nome atual: %s\n", Insc[Pos].Ins_Nome);
- printf("Digite o novo nome:\n");
- fflush(stdin);
- gets(Insc[Pos].Ins_Nome);
- while(strcmp(Insc[Pos].Ins_Nome, "\0") == 0)
- {
- printf("Nome invalido.\n");
- printf("Digite o novo nome:\n");
- fflush(stdin);
- gets(Insc[Pos].Ins_Nome);
- }
- printf("Nome alterado\n");
- break;
- case 'B':
- printf("Sexo atual: %c\n", Insc[Pos].Ins_Sexo);
- printf("Digite o novo sexo:\n");
- fflush(stdin);
- scanf("%c", &AuxS);
- AuxS = toupper(AuxS);
- while(AuxS != 'M' && AuxS != 'F')
- {
- printf("Sexo invalido\n");
- printf("Digite o novo sexo:\n");
- fflush(stdin);
- scanf("%c", &AuxS);
- AuxS = toupper(AuxS);
- }
- //Atualizando as estatísticas por sexo das palestras do inscrito
- AtualizaEstatistica(Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra1)],
- Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra2)],
- AuxS, 3);
- Insc[Pos].Ins_Sexo = AuxS;
- printf("Sexo alterado\n");
- break;
- case 'C':
- printf("Cidade atual: %c\n", Insc[Pos].Ins_Cidade);
- printf("Digite a nova cidade:\n");
- fflush(stdin);
- gets(Insc[Pos].Ins_Cidade);
- while(strcmp(Insc[Pos].Ins_Cidade, "\0") == 0)
- {
- printf("Dado invalido\n");
- printf("Digite a nova cidade:\n");
- fflush(stdin);
- gets(Insc[Pos].Ins_Cidade);
- }
- printf("Cidade alterada\n");
- break;
- case 'D':
- printf("Codigo atual: %d\n", Insc[Pos].Cod_Palestra1);
- printf("Digite o novo codigo da primeira palestra:\n");
- scanf("%d", &PalAux);
- while(BuscaPalestra(Plst, TLP, PalAux) == - 1 ||
- PalAux == Insc[Pos].Cod_Palestra2)
- {
- printf("Codigo de palestra invalido\n");
- printf("Digite o novo codigo da primeira palestra:\n");
- scanf("%d", &PalAux);
- }
- AtualizaEstatistica(Est[BuscaEstatistica(Est, TLP, PalAux)],
- Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra1)],
- Insc[Pos].Ins_Sexo, 4);
- Insc[Pos].Cod_Palestra1 = PalAux;
- printf("Codigo da primeira palestra alterado\n");
- break;
- case 'E':
- printf("Codigo atual: %d\n", Insc[Pos].Cod_Palestra2);
- printf("Digite o novo codigo da segunda palestra:\n");
- scanf("%d", &PalAux);
- while(BuscaPalestra(Plst, TLP, PalAux) == - 1 ||
- PalAux == Insc[Pos].Cod_Palestra1)
- {
- printf("Codigo de palestra invalido\n");
- printf("Digite o novo codigo da segunda palestra:\n");
- scanf("%d", &PalAux);
- }
- AtualizaEstatistica(Est[BuscaEstatistica(Est, TLP, PalAux)],
- Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra2)],
- Insc[Pos].Ins_Sexo, 4);
- Insc[Pos].Cod_Palestra2 = PalAux;
- printf("Codigo da segunda palestra alterado\n");
- break;
- default:
- printf("Opcao invalida\n");
- }
- getch();
- system("cls");
- Op = MenuAlteraInscrito();
- }
- }
- getch();
- printf("Digite o numero do inscrito (0 para sair):\n");
- scanf("%d", &NumAux);
- }
- OrdenaInscrito(Insc, TLI);
- }
- getch();
- }
- void CabecalhoInscritos(void)
- {
- gotoxy(1, 1);
- printf("Nome");
- gotoxy(20, 1);
- printf("Sexo");
- gotoxy(25, 1);
- printf("Cidade");
- gotoxy(55, 1);
- printf("Palestra 1");
- gotoxy(67, 1);
- printf("Palestra 2");
- }
- void ImprimeInscrito(TpInscrito Insc, int linha)
- {
- gotoxy(1,linha);
- printf("%s", Insc.Ins_Nome);
- gotoxy(20,linha);
- printf("%c", Insc.Ins_Sexo);
- gotoxy(25,linha);
- printf("%s", Insc.Ins_Cidade);
- gotoxy(55,linha);
- printf("%d", Insc.Cod_Palestra1);
- gotoxy(67,linha);
- printf("%d", Insc.Cod_Palestra2);
- }
- void ConsultaInscrito(TpInscrito Insc[TFI], int TLI, TpPalestra Plst[TFP], int TLP)
- {
- int NumAux, Pos, linha = 2;
- textbackground(0);
- system("cls");
- printf("**Consulta de Inscritos**\n");
- if(TLI == 0)
- {
- textcolor(4);
- printf("Nenhum inscrito cadastrado\n");
- }
- else
- {
- printf("Digite o numero do inscrito (0 para sair):\n");
- scanf("%d", &NumAux);
- while(NumAux > 0)
- {
- Pos = BuscaInscritos(Insc, TLI, NumAux);
- system("cls");
- if(Pos == -1)
- {
- textcolor(4);
- printf("Nenhum inscrito com esse numero");
- textcolor(7);
- }
- else
- {
- textbackground(4);
- textcolor(14);
- CabecalhoInscritos();
- ImprimeInscrito(Insc[Pos], linha);
- textcolor(7);
- }
- textbackground(0);
- printf("\nDigite o numero do inscrito (0 para sair):\n");
- scanf("%d", &NumAux);
- }
- }
- getch();
- }
- void ListaInscritos(TpInscrito Insc[TFI], int TLI, TpPalestra Plst[TFP], int TLP)
- {
- int i, linha = 2;
- system("cls");
- if(TLI == 0)
- printf("Nenhum inscrito cadastrado\n\n");
- else
- {
- textbackground(4);
- textcolor(14);
- CabecalhoInscritos();
- for(i = 0; i < TLI; i++)
- {
- ImprimeInscrito(Insc[i], linha++);
- }
- textbackground(0);
- }
- getch();
- }
- void OrdenaPalestra(TpPalestra Plst[TFP], int TLP)
- {
- int i, j;
- TpPalestra Aux;
- for(i = 0; i < TLP - 1; i++)
- for(j = i + 1; j < TLP; j++)
- if(strcmp(Plst[i].Pal_Nome, Plst[j].Pal_Nome) > 0)
- {
- Aux = Plst[i];
- Plst[i] = Plst[j];
- Plst[j] = Aux;
- }
- }
- void IncluiPalestra(TpPalestra Plst[TFP], int &TL, TpEstatistica Est[TFP])
- {
- int CodigoAux, TotVagasAux;
- char NomeAux[40], HorarioAux[6];
- system("cls");
- printf("\n\nCadastro de palestras\n\n");
- printf("Codigo da palestra:\n");
- scanf("%d", &CodigoAux);
- while(TL < TFP && CodigoAux > 0)
- {
- if(BuscaPalestra(Plst, TL, CodigoAux) >= 0)
- printf("Codigo de palestra ja cadastrado\n\n");
- else
- {
- Plst[TL].Pal_Codigo = CodigoAux;
- printf("Nome da palestra:\n");
- fflush(stdin);
- gets(NomeAux);
- while(strcmp(NomeAux, "\0") == 0)
- {
- printf("Digite um nome valido\n");
- fflush(stdin);
- gets(NomeAux);
- }
- strcpy(Plst[TL].Pal_Nome, NomeAux);
- printf("Horario da palestra (hh:mm)\n");
- fflush(stdin);
- gets(Plst[TL].Pal_Horario);
- printf("Total de vagas:\n");
- scanf("%d", &Plst[TL].Pal_TotVagas);
- Est[TL].Eve_Palestra = Plst[TL].Pal_Codigo;
- Est[TL].Eve_TotalInscritos = 0;
- TL++;
- printf("Palestra cadastrada\n\n");
- }
- printf("Codigo da palestra:\n");
- scanf("%d", &CodigoAux);
- }
- OrdenaPalestra(Plst, TL);
- getch();
- }
- void CabecalhoPalestras(void)
- {
- textcolor(15);
- textbackground(1);
- gotoxy(1, 1);
- printf("Codigo");
- gotoxy(15, 1);
- printf("Nome");
- gotoxy(65, 1);
- printf("Horario");
- gotoxy(75, 1);
- printf("Vagas");
- }
- void ImprimePalestra(TpPalestra Plst, int linha)
- {
- gotoxy(1, linha);
- printf("%d", Plst.Pal_Codigo);
- gotoxy(15, linha);
- printf("%s", Plst.Pal_Nome);
- gotoxy(65, linha);
- printf("%s", Plst.Pal_Horario);
- gotoxy(75, linha);
- printf("%d", Plst.Pal_TotVagas);
- }
- void ListaPalestras(TpPalestra Plst[TFP], int TLP)
- {
- int i, linha = 2;
- system("cls");
- if(TLP == 0)
- {
- textbackground(15);
- textcolor(4);
- printf("Nenhuma palestra cadastrada\n");
- }
- else
- {
- textbackground(4);
- textcolor(14);
- CabecalhoPalestras();
- for(i = 0; i < TLP; i++)
- ImprimePalestra(Plst[i], linha++);
- textbackground(0);
- }
- getch();
- }
- void ConsultaPalestras(TpPalestra Plst[TFP], int TLP)
- {
- int CodAux, Pos;
- system("cls");
- printf("Consulta de palestras\n\n");
- if(TLP == 0)
- printf("Nenhuma palestra cadastrada\n");
- else
- {
- printf("\nDigite o codigo da palestra (0 para sair):\n");
- scanf("%d", &CodAux);
- while(CodAux > 0)
- {
- Pos = BuscaPalestra(Plst, TLP, CodAux);
- if(Pos == -1)
- printf("Nenhuma palestra com esse codigo\n");
- else
- {
- }
- printf("\nDigite o codigo da palestra (0 para sair):\n");
- scanf("%d", &CodAux);
- }
- }
- textbackground(0);
- getch();
- }
- void ExcluiPalestra(TpPalestra Plst[TFP], TpInscrito Insc[TFI],
- int TLI, TpEstatistica Est[TFP], int &TLP)
- {
- int CodAux, Pos;
- system("cls");
- printf("Exclusao de palestras\n\n");
- if(TLP == 0)
- printf("Nenhuma palestra cadastrada\n\n");
- else
- {
- printf("Digite o codigo da palestra (0 para sair):\n");
- scanf("%d", &CodAux);
- while(CodAux > 0)
- {
- Pos = BuscaPalestra(Plst, TLP, CodAux);
- if(Pos == -1)
- printf("Nenhuma palestra com esse codigo\n");
- else
- {
- if(ValidaExclusao(Insc, TLI, Plst[Pos].Pal_Codigo) == -1)
- {
- textbackground(7);
- textcolor(4);
- printf("Palestra tem inscritos cadastrados\n");
- textbackground(0);
- textcolor(7);
- }
- else
- {
- for(;Pos < TLP - 1; Pos++)
- {
- Plst[Pos] = Plst[Pos + 1];
- Est[Pos] = Est[Pos + 1];
- }
- TLP--;
- textcolor(3);
- printf("Palestra excluida\n");
- textcolor(7);
- }
- }
- printf("Digite o codigo da palestra (0 para sair):\n");
- scanf("%d", &CodAux);
- }
- }
- getch();
- }
- char MenuAlteraPalestra(void)
- {
- printf("Escolha:\n");
- printf("[A] - Alterar nome\n");
- printf("[B] - Alterar horario\n");
- printf("[C] - Alterar numero de vagas\n");
- printf("[ESC] - Sair\n");
- return toupper(getche());
- }
- void AlteraPalestra(TpPalestra Plst[TFP], int TLP)
- {
- int Pos, TotVagasAux, CodAux;
- char NomeAux[40], HorarioAux[6], Op;
- system("cls");
- printf("Alteração de palestras\n\n");
- if(TLP == 0)
- printf("Nenhuma palestra cadastrada\n");
- else
- {
- printf("Digite o codigo da palestra (0 para sair):\n");
- scanf("%d", &CodAux);
- while(CodAux > 0)
- {
- Pos = BuscaPalestra(Plst, TLP, CodAux);
- if(Pos == -1)
- printf("Nenhuma palestra com esse codigo\n");
- else
- {
- Op = MenuAlteraPalestra();
- while(Op != 27)
- {
- switch(Op)
- {
- case 'A':
- printf("Nome atual: %s\n", Plst[Pos].Pal_Nome);
- printf("Digite o novo nome:\n");
- fflush(stdin);
- gets(NomeAux);
- while(strcmp(NomeAux, "\0") == 0)
- {
- printf("Nome invalido\n");
- printf("Digite o novo nome:\n");
- fflush(stdin);
- gets(NomeAux);
- }
- strcpy(Plst[Pos].Pal_Nome, NomeAux);
- printf("Nome alterado\n");
- break;
- case 'B':
- printf("Horario atual: %s\n", Plst[Pos].Pal_Horario);
- printf("Digite o novo horario:\n");
- fflush(stdin);
- gets(HorarioAux);
- while(strcmp(HorarioAux, "\0") == 0)
- {
- printf("Horario invalido\n");
- printf("Digite o novo horario:\n");
- fflush(stdin);
- gets(HorarioAux);
- }
- strcpy(Plst[Pos].Pal_Horario, HorarioAux);
- printf("Horario alterado\n");
- break;
- case 'C':
- printf("\nVagas atuais: %d\n", Plst[Pos].Pal_TotVagas);
- printf("Digite o novo numero de vagas:\n");
- scanf("%d", &TotVagasAux);
- while(TotVagasAux < 1)
- {
- printf("Numero de vagas invalido\n");
- printf("Digite o novo numero de vagas:\n");
- scanf("%d", &TotVagasAux);
- }
- Plst[Pos].Pal_TotVagas = TotVagasAux;
- printf("Numero de vagas alterado\n");
- break;
- default:
- printf("Opcao invalida\n");
- }
- getch();
- Op = MenuAlteraPalestra();
- }
- }
- printf("Digite o codigo da palestra (0 para sair):\n");
- scanf("%d", &CodAux);
- }
- }
- getch();
- }
- char MenuRelatorioPalestras(void)
- {
- printf("[A] - Busca a partir do inicio\n");
- printf("[B] - Busca em qualquer parte do titulo\n");
- printf("[ESC] - Sair\n");
- return toupper(getche());
- }
- void RelatorioPalestras(TpPalestra Plst[TFP], int TLP)
- {
- int i, linha = 2;
- char Op, NomeAux[40];
- system("cls");
- printf("**Busca de palestras por titulo**\n\n");
- if(TLP == 0)
- printf("Nenhuma palestra cadastrada\n");
- else
- {
- Op = MenuRelatorioPalestras();
- while(Op != 27)
- {
- switch(Op)
- {
- case 'A':
- printf("\nDigite o nome:\n");
- fflush(stdin);
- gets(NomeAux);
- system("cls");
- CabecalhoPalestras();
- for(i = 0; i < TLP; i++)
- if(ProcuraInicio(Plst[i].Pal_Nome, NomeAux, strlen(NomeAux)) == 1)
- ImprimePalestra(Plst[i], linha++);
- linha = 1;
- printf("\nBusca Concluida\n");
- break;
- case 'B':
- printf("\nDigite o nome:\n");
- fflush(stdin);
- gets(NomeAux);
- system("cls");
- CabecalhoPalestras();
- for(i = 0; i < TLP; i++)
- if(ProcuraMeio(Plst[i].Pal_Nome, NomeAux) == 1)
- ImprimePalestra(Plst[i], linha++);
- linha = 1;
- printf("\nBusca concluida\n");
- break;
- default:
- printf("Opcao invalida\n");
- }
- Op = MenuRelatorioPalestras();
- }
- }
- textbackground(0);
- getch();
- }
- void InsercaoDireta(TpPalestra Plst[TFP], int &TLP, TpInscrito Insc[TFI], int &TLI,
- TpEstatistica Est[TFP])
- {
- int i;
- TpPalestra InsercPalestra[5] = {{1, 2, "Big Data em Universidades", "21:00"},
- {2, 3, "Skills para ser cientista de dados", "18:30"},
- {3, 4, "Marcos tecnicos do Hadoop 3", "09:00"},
- {4, 5, "Impactos da IA nos empregos", "19:00"},
- {5, 10, "Usando Big Data em corporacoes", "20:30"}};
- TpInscrito InsercInscrito[5] = {{1, 1, 2, "Joao Victor Sierra", 'M', "Regente Feijo"},
- {2, 1, 2, "Lucas Gomes", 'M', "Pirapo"},
- {3, 3, 5, "Luana Campos", 'F', "Presidente Venceslau"},
- {4, 5, 4, "Sofia Vieira", 'F', "Sao Paulo"},
- {5, 1, 5, "Manoel Silva", 'M', "Uberaba"}};
- system("cls");
- if(TLP > 0 || TLI > 0)
- {
- textcolor(4);
- textbackground(8);
- printf("Ja existem dados cadastrados\n");
- }
- else
- {
- for(i = 0; i < 5; i++)
- {
- Plst[TLP].Pal_Codigo = InsercPalestra[i].Pal_Codigo;
- Plst[TLP].Pal_TotVagas = InsercPalestra[i].Pal_TotVagas;
- strcpy(Plst[TLP].Pal_Nome, InsercPalestra[i].Pal_Nome);
- strcpy(Plst[TLP].Pal_Horario, InsercPalestra[i].Pal_Horario);
- Est[TLP].Eve_Palestra = InsercPalestra[i].Pal_Codigo;
- Est[TLP].Eve_TotalInscritos = 0;
- Est[TLP].Eve_TotInscrFem = 0;
- Est[TLP].Eve_TotInscrMasc = 0;
- TLP++;
- }
- for(i = 0; i < 5; i++)
- {
- Insc[TLI].Ins_Numero = InsercInscrito[i].Ins_Numero;
- Insc[TLI].Cod_Palestra1 = InsercInscrito[i].Cod_Palestra1;
- Insc[TLI].Cod_Palestra2 = InsercInscrito[i].Cod_Palestra2;
- strcpy(Insc[TLI].Ins_Nome, InsercInscrito[i].Ins_Nome);
- strcpy(Insc[TLI].Ins_Cidade, InsercInscrito[i].Ins_Cidade);
- Insc[TLI].Ins_Sexo = InsercInscrito[i].Ins_Sexo;
- AtualizaEstatistica(Est[BuscaPalestra(Plst, TLP, InsercInscrito[i].Cod_Palestra1)],
- Est[BuscaPalestra(Plst, TLP, InsercInscrito[i].Cod_Palestra2)],
- InsercInscrito[i].Ins_Sexo, 1);
- TLI++;
- }
- CalculaEstatistica(Est, Plst, TLP, 0, 5);
- OrdenaEstatistica(Est, TLP);
- OrdenaInscrito(Insc, TLI);
- OrdenaPalestra(Plst, TLP);
- textbackground(4);
- textcolor(14);
- printf("Dados cadastrados\n");
- }
- textbackground(0);
- getch();
- }
- void CabecalhoEstatistica(void)
- {
- gotoxy(1, 1);
- printf("Palestra");
- gotoxy(42, 1);
- printf("Vagas");
- gotoxy(52, 1);
- printf("Insc/vaga");
- gotoxy(65, 1);
- printf("Homens");
- gotoxy(72, 1);
- printf("Mulheres");
- }
- void ImprimeEstatistica(TpEstatistica Est, TpPalestra Plst[TFP], int TLP, int linha)
- {
- int Pos = BuscaPalestra(Plst, TLP, Est.Eve_Palestra);
- gotoxy(1, linha);
- printf("%s", Plst[Pos].Pal_Nome);
- gotoxy(42, linha);
- printf("%d", Plst[Pos].Pal_TotVagas);
- gotoxy(52, linha);
- printf("%.2f", Est.Eve_InscrVagas);
- gotoxy(65, linha);
- printf("%d", Est.Eve_TotalInscritos);
- gotoxy(65, linha);
- printf("%d", Est.Eve_TotInscrMasc);
- gotoxy(72, linha);
- printf("%d", Est.Eve_TotInscrFem);
- }
- void ListaEstatistica(TpEstatistica Est[TFP], TpPalestra Plst[TFP], int TLP)
- {
- int i, Pos, linha = 2;
- system("cls");
- if(TLP == 0)
- printf("Nenhuma palestra cadastrada\n");
- else
- {
- textbackground(4);
- textcolor(14);
- CabecalhoEstatistica();
- for(i = 0; i < TLP; i++)
- ImprimeEstatistica(Est[i], Plst, TLP, linha++);
- gotoxy(1, linha);
- textbackground(0);
- textcolor(7);
- }
- getch();
- }
- void Quadro(int LI, int CI, int LF, int CF, int CorT, int corF)
- {
- int i;
- textcolor(CorT);
- textbackground(corF);
- gotoxy(CI, LI);
- printf("%c", 201);
- gotoxy(CI, LF);
- printf("%c", 200);
- gotoxy(CF, LI);
- printf("%c", 187);
- gotoxy(CF, LF);
- printf("%c", 188);
- for(i = CI+1; i < CF; i++)
- {
- gotoxy(i, LI);
- printf("%c", 205);
- }
- for(i = LI + 1; i < LF; i++)
- {
- gotoxy(CI, i);
- printf("%c", 186);
- gotoxy(CF, i);
- printf("%c", 186);
- }
- for(i = CI + 1; i < CF; i++)
- {
- gotoxy(i, LF);
- printf("%c", 205);
- }
- textcolor(7);
- textbackground(0);
- }
- char MenuPrincipal(void)
- {
- int Linha = 5;
- system("cls");
- Quadro(2, 20, 22, 54, 14, 0);
- Quadro(4, 22, 20, 52, 14, 0);
- textbackground(4);
- textcolor(14);
- gotoxy(28, 3);
- printf("MENU - Big Data Week");
- gotoxy(24,Linha++);
- printf("[A] - Incluir inscritos");
- gotoxy(24,Linha++);
- printf("[B] - Consultar inscritos");
- gotoxy(24,Linha++);
- printf("[C] - Alterar inscritos");
- gotoxy(24,Linha++);
- printf("[D] - Excluir inscritos");
- gotoxy(24,Linha++);
- printf("[E] - Exibir inscritos");
- gotoxy(24,Linha++);
- printf("[F] - Incluir palestras");
- gotoxy(24,Linha++);
- printf("[G] - Consultar palestras");
- gotoxy(24,Linha++);
- printf("[H] - Alterar palestras");
- gotoxy(24,Linha++);
- printf("[I] - Excluir palestras");
- gotoxy(24,Linha++);
- printf("[J] - Exibir palestras\n");
- gotoxy(24,Linha++);
- printf("[K] - Consultar por tema");
- gotoxy(24,Linha++);
- printf("[L] - Relatorio por nome");
- gotoxy(24,Linha++);
- printf("[M] - Exibir estatistica");
- gotoxy(24,Linha++);
- printf("[N] - Insercao direta");
- gotoxy(24,Linha);
- printf("[ESC] - Sair\n");
- textbackground(0);
- textcolor(7);
- gotoxy(37, Linha);
- return toupper(getch());
- }
- void Executa(void)
- {
- TpInscrito Insc[TFI];
- TpPalestra Plst[TFP];
- TpEstatistica Est[TFP];
- int TLI = 0, TLP = 0;
- char Op;
- Op = MenuPrincipal();
- while(Op != 27)
- {
- switch(Op)
- {
- case 'A':
- IncluiInscrito(Insc, TLI, Plst, TLP, Est);
- break;
- case 'B':
- ConsultaInscrito(Insc, TLI, Plst, TLP);
- break;
- case 'C':
- AlteraInscrito(Insc, TLI, Plst, TLP, Est);
- break;
- case 'D':
- RemoveInscrito(Insc, TLI, Plst, TLP, Est);
- break;
- case 'E':
- ListaInscritos(Insc, TLI, Plst, TLP);
- break;
- case 'F':
- IncluiPalestra(Plst, TLP, Est);
- break;
- case 'G':
- ConsultaPalestras(Plst, TLP);
- break;
- case 'H':
- AlteraPalestra(Plst, TLP);
- break;
- case 'I':
- ExcluiPalestra(Plst, Insc, TLI, Est, TLP);
- break;
- case 'J':
- ListaPalestras(Plst, TLP);
- break;
- case 'K':
- //
- break;
- case 'L':
- RelatorioPalestras(Plst, TLP);
- break;
- case 'M':
- ListaEstatistica(Est, Plst, TLP);
- break;
- case 'N':
- InsercaoDireta(Plst, TLP, Insc, TLI, Est);
- break;
- default:
- printf("\nOpcao invalida\n");
- }
- Op = MenuPrincipal();
- }
- }
- int main(void)
- {
- Executa();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement