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 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);
- }
- void QuadroSimples(int LI, int CI, int LF, int CF, int CorT, int corF)
- {
- int i;
- textcolor(CorT);
- textbackground(corF);
- gotoxy(CI, LI);
- printf("%c", 218);
- gotoxy(CI, LF);
- printf("%c", 192);
- gotoxy(CF, LI);
- printf("%c", 191);
- gotoxy(CF, LF);
- printf("%c", 217);
- for(i = CI+1; i < CF; i++)
- {
- gotoxy(i, LI);
- printf("%c", 196);
- }
- for(i = LI + 1; i < LF; i++)
- {
- gotoxy(CI, i);
- printf("%c", 179);
- gotoxy(CF, i);
- printf("%c", 179);
- }
- for(i = CI + 1; i < CF; i++)
- {
- gotoxy(i, LF);
- printf("%c", 196);
- }
- textcolor(7);
- textbackground(0);
- }
- 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(stricmp(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");
- Quadro(1, 1, 25, 80, 2, 0);
- gotoxy(28, 2);
- textcolor(15);
- printf("Cadastro de Inscritos");
- if(TLP >= 2)
- {
- Cont = 0;
- gotoxy(3, 4);
- printf("Digite o numero do inscrito (0 para sair):");
- scanf("%d", &NumAux);
- while(TLI < TFI && NumAux > 0)
- {
- if(BuscaInscritos(Insc, TLI, NumAux) >= 0)
- {
- textbackground(7);
- textcolor(4);
- gotoxy(3, 5);
- printf("Numero do inscrito ja cadastrado\n");
- textcolor(7);
- textbackground(0);
- }
- else
- {
- Insc[TLI].Ins_Numero = NumAux;
- gotoxy(3, 5);
- printf("Nome do inscrito: ");
- fflush(stdin);
- gets(Insc[TLI].Ins_Nome);
- while(strcmp(Insc[TLI].Ins_Nome, "\0") == 0)
- {
- gotoxy(3, 6);
- textcolor(4);
- printf("Digite um nome valido: ");
- fflush(stdin);
- textcolor(15);
- gets(Insc[TLI].Ins_Nome);
- }
- gotoxy(3, 7);
- printf("Sexo: ");
- 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')
- {
- gotoxy(3, 8);
- textcolor(4);
- printf("Digite um dado valido:");
- fflush(stdin);
- textcolor(15);
- scanf("%c", &Insc[TLI].Ins_Sexo);
- Insc[TLI].Ins_Sexo = toupper(Insc[TLI].Ins_Sexo);
- }
- gotoxy(3, 9);
- printf("Cidade: ");
- fflush(stdin);
- gets(Insc[TLI].Ins_Cidade);
- while(strcmp(Insc[TLI].Ins_Cidade, "\0") == 0)
- {
- textcolor(4);
- gotoxy(3, 10);
- printf("Digite uma cidade valida:");
- fflush(stdin);
- textcolor(15);
- gets(Insc[TLI].Ins_Cidade);
- }
- gotoxy(3, 11);
- printf("Codigo da primeira palestra: ");
- scanf("%d", &Insc[TLI].Cod_Palestra1);
- while(BuscaPalestra(Plst, TLP, Insc[TLI].Cod_Palestra1) == -1)
- {
- gotoxy(3, 12);
- textcolor(4);
- printf("Codigo de palestra inexistente. Digite um codigo valido: ");
- textcolor(15);
- scanf("%d", &Insc[TLI].Cod_Palestra1);
- }
- gotoxy(3, 13);
- printf("Codigo da segunda palestra: ");
- scanf("%d", &Insc[TLI].Cod_Palestra2);
- while(BuscaPalestra(Plst, TLP, Insc[TLI].Cod_Palestra2) == -1
- || Insc[TLI].Cod_Palestra1 == Insc[TLI].Cod_Palestra2)
- {
- gotoxy(3, 14);
- textcolor(4);
- printf("Codigo da palestra invalido. Digite um codigo valido: ");
- textcolor(15);
- 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(2);
- gotoxy(30, 15);
- printf("Inscrito cadastrado");
- }
- getch();
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- gotoxy(28, 2);
- textcolor(WHITE);
- printf("Cadastro de Inscritos");
- gotoxy(3, 4);
- printf("Digite o numero do inscrito (0 para sair):");
- scanf("%d", &NumAux);
- }
- CalculaEstatistica(Est, Plst, TLP, TLI - Cont, TLI);
- OrdenaEstatistica(Est, TLP);
- OrdenaInscrito(Insc, TLI);
- }
- else
- {
- gotoxy(22, 3);
- textbackground(WHITE);
- textcolor(4);
- printf(" Nao ha palestras suficientes! ");
- textcolor(15);
- textbackground(0);
- }
- getch();
- }
- void RemoveInscrito(TpInscrito Insc[TFI], int &TLI, TpPalestra Plst[TFP],
- int TLP, TpEstatistica Est[TFP])
- {
- int NumeroAux, Pos, i, PosEst, Cont;
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- textcolor(15);
- gotoxy(30, 2);
- printf("Exclusao de inscritos");
- if(TLI == 0)
- {
- gotoxy(27,3);
- textcolor(4);
- printf("Nenhum inscrito cadastrado");
- textcolor(15);
- }
- else
- {
- gotoxy(3, 4);
- printf("Digite o numero do inscrito (0 para sair): ");
- scanf("%d", &NumeroAux);
- while(NumeroAux > 0)
- {
- Cont = 0;
- Pos = BuscaInscritos(Insc, TLI, NumeroAux);
- if(Pos == -1)
- {
- gotoxy(3, 5);
- textcolor(4);
- printf("Nenhum inscrito com esse numero");
- textcolor(15);
- }
- else
- {
- gotoxy(3, 6);
- textcolor(10);
- printf("Confirma exclusao? (S/N): ");
- if(toupper(getch()) == 'S')
- {
- 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--;
- gotoxy(3, 7);
- textcolor(10);
- printf("Inscrito excluido");
- }
- else
- {
- gotoxy(20, 7);
- textcolor(11);
- printf("Exclusao cancelada");
- textcolor(15);
- }
- }
- getch();
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- gotoxy(30, 2);
- textcolor(15);
- printf("Exclusao de inscritos");
- gotoxy(3, 4);
- printf("Digite o numero do inscrito (0 para sair): ");
- scanf("%d", &NumeroAux);
- }
- }
- getch();
- }
- char MenuAlteraInscrito(void)
- {
- gotoxy(3, 4);
- printf("Escolha:");
- gotoxy(3, 5);
- printf("[A] - Alterar nome");
- gotoxy(3, 6);
- printf("[B] - Alterar sexo\n");
- gotoxy(3, 7);
- printf("[C] - Alterar cidade");
- gotoxy(3, 8);
- printf("[D] - Alterar codigo da primeira palestra");
- gotoxy(3, 9);
- printf("[E] - Alterar codigo da segunda palestra");
- gotoxy(3, 10);
- printf("[ESC] - Sair ");
- 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;
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- textcolor(15);
- gotoxy(30, 2);
- printf("Alteracao de inscritos");
- if(TLI == 0)
- {
- gotoxy(27, 3);
- textcolor(4);
- printf("Nenhum inscrito cadastrado");
- textcolor(15);
- }
- else
- {
- gotoxy(3, 3);
- printf("Digite o numero do inscrito (0 para sair): ");
- scanf("%d", &NumAux);
- while(NumAux > 0)
- {
- Pos = BuscaInscritos(Insc, TLI, NumAux);
- if(Pos == -1)
- {
- gotoxy(3, 4);
- textcolor(4);
- printf("Nenhum inscrito com esse numero\n");
- }
- else
- {
- Op = MenuAlteraInscrito();
- while(Op != 27)
- {
- gotoxy(3, 11);
- switch(Op)
- {
- case 'A':
- printf("Nome atual: %s ", Insc[Pos].Ins_Nome);
- gotoxy(3, 12);
- printf("Digite o novo nome: ");
- fflush(stdin);
- gets(Insc[Pos].Ins_Nome);
- while(strcmp(Insc[Pos].Ins_Nome, "\0") == 0)
- {
- textcolor(4);
- gotoxy(3, 13);
- printf("Nome invalido.");
- textcolor(15);
- gotoxy(3, 14);
- printf("Digite o novo nome: ");
- fflush(stdin);
- gets(Insc[Pos].Ins_Nome);
- }
- gotoxy(3, 15);
- printf("Nome alterado");
- break;
- case 'B':
- printf("Sexo atual: %c ", Insc[Pos].Ins_Sexo);
- gotoxy(3, 12);
- printf("Digite o novo sexo(F/M):");
- fflush(stdin);
- scanf("%c", &AuxS);
- AuxS = toupper(AuxS);
- while(AuxS != 'M' && AuxS != 'F')
- {
- textcolor(4);
- gotoxy(3, 13);
- printf("Sexo invalido. Digite um caractere valido:");
- textcolor(15);
- 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;
- gotoxy(3, 15);
- printf("Sexo alterado");
- break;
- case 'C':
- printf("Cidade atual: %s", Insc[Pos].Ins_Cidade);
- gotoxy(3, 12);
- printf("Digite a nova cidade:");
- fflush(stdin);
- gets(Insc[Pos].Ins_Cidade);
- while(strcmp(Insc[Pos].Ins_Cidade, "\0") == 0)
- {
- gotoxy(3, 13);
- textcolor(4);
- printf("Dado invalido. Digite a nova cidade: ");
- textcolor(15);
- fflush(stdin);
- gets(Insc[Pos].Ins_Cidade);
- }
- gotoxy(3, 15);
- printf("Cidade alterada");
- break;
- case 'D':
- printf("Codigo atual: %d", Insc[Pos].Cod_Palestra1);
- gotoxy(3, 12);
- printf("Digite o novo codigo da primeira palestra: ");
- scanf("%d", &PalAux);
- while(BuscaPalestra(Plst, TLP, PalAux) == - 1 ||
- PalAux == Insc[Pos].Cod_Palestra2)
- {
- gotoxy(3, 13);
- textcolor(4);
- printf("Codigo de palestra invalido. Digite um codigo valido:");
- textcolor(15);
- 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;
- gotoxy(3, 15);
- printf("Codigo da primeira palestra alterado");
- break;
- case 'E':
- printf("Codigo atual: %d", Insc[Pos].Cod_Palestra2);
- gotoxy(3, 12);
- printf("Digite o novo codigo da segunda palestra:");
- scanf("%d", &PalAux);
- while(BuscaPalestra(Plst, TLP, PalAux) == - 1 ||
- PalAux == Insc[Pos].Cod_Palestra1)
- {
- gotoxy(3, 13);
- textcolor(4);
- printf("Codigo de palestra invalido. Digite o novo codigo da segunda palestra: ");
- textcolor(15);
- 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;
- gotoxy(3, 15);
- printf("Codigo da segunda palestra alterado");
- break;
- default:
- gotoxy(20, 16);
- textcolor(4);
- printf("Opcao invalida");
- textcolor(15);
- break;
- }
- getch();
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- textcolor(15);
- gotoxy(30, 2);
- printf("Alteracao de inscritos");
- Op = MenuAlteraInscrito();
- }
- }
- getch();
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- textcolor(15);
- gotoxy(30, 2);
- printf("Alteracao de inscritos");
- gotoxy(3, 3);
- printf("Digite o numero do inscrito (0 para sair): ");
- scanf("%d", &NumAux);
- }
- OrdenaInscrito(Insc, TLI);
- }
- getch();
- }
- void ImprimeInscrito(TpInscrito Insc, TpPalestra Plst[TFP], int TLP, int linha)
- {
- Quadro(linha - 1, 2, linha + 3, 79, 15, 0);
- textcolor(15);
- gotoxy(3,linha);
- printf("%s", Insc.Ins_Nome);
- gotoxy(44,linha);
- printf("Sexo:%c", Insc.Ins_Sexo);
- gotoxy(51,linha++);
- printf("%s", Insc.Ins_Cidade);
- gotoxy(3,linha++);
- printf("Primeira palestra: %s", Plst[BuscaPalestra(Plst, TLP, Insc.Cod_Palestra1)].Pal_Nome);
- gotoxy(3,linha);
- printf("Segunda palestra: %s", Plst[BuscaPalestra(Plst, TLP, Insc.Cod_Palestra2)].Pal_Nome);
- }
- void ConsultaInscrito(TpInscrito Insc[TFI], int TLI, TpPalestra Plst[TFP], int TLP)
- {
- int NumAux, Pos;
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- textcolor(15);
- gotoxy(30, 2);
- printf("Consulta de de inscritos");
- if(TLI == 0)
- {
- textcolor(4);
- gotoxy(29,3);
- printf("Nenhum inscrito cadastrado");
- textcolor(15);
- }
- else
- {
- gotoxy(3, 3);
- printf("Digite o numero do inscrito (0 para sair): ");
- scanf("%d", &NumAux);
- while(NumAux > 0)
- {
- Pos = BuscaInscritos(Insc, TLI, NumAux);
- if(Pos == -1)
- {
- gotoxy(3, 4);
- textcolor(4);
- printf("Nenhum inscrito com esse numero!");
- textcolor(15);
- }
- else
- ImprimeInscrito(Insc[Pos], Plst, TLP, 5);
- getch();
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- textcolor(15);
- gotoxy(30, 2);
- printf("Consulta de de inscritos");
- gotoxy(3, 3);
- printf("Digite o numero do inscrito (0 para sair): ");
- 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)
- {
- gotoxy(27, 2);
- textcolor(4);
- printf("Nenhum inscrito cadastrado\n\n");
- textcolor(15);
- }
- else
- {
- textcolor(15);
- for(i = 0; i < TLI; i++)
- {
- ImprimeInscrito(Insc[i], Plst, TLP, linha);
- linha+=5;
- }
- gotoxy(1, 1);
- 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;
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- textcolor(15);
- gotoxy(30, 2);
- printf("Cadastro de Palestras");
- gotoxy(3, 3);
- printf("Codigo da palestra (0 para sair):");
- scanf("%d", &CodigoAux);
- while(TL < TFP && CodigoAux > 0)
- {
- if(BuscaPalestra(Plst, TL, CodigoAux) >= 0)
- {
- textcolor(4);
- gotoxy(3,4);
- printf("Codigo de palestra ja cadastrado!");
- textcolor(15);
- }
- else
- {
- Plst[TL].Pal_Codigo = CodigoAux;
- gotoxy(3, 4);
- printf("Nome da palestra:");
- fflush(stdin);
- gets(Plst[TL].Pal_Nome);
- while(strcmp(Plst[TL].Pal_Nome, "\0") == 0)
- {
- gotoxy(3, 5);
- textcolor(4);
- printf("Digite um nome valido:");
- textcolor(15);
- fflush(stdin);
- gets(Plst[TL].Pal_Nome);
- }
- gotoxy(3, 6);
- printf("Horario da palestra (hh:mm):");
- fflush(stdin);
- gets(Plst[TL].Pal_Horario);
- while(strcmp(Plst[TL].Pal_Horario, "") == 0)
- {
- gotoxy(3, 7);
- textcolor(4);
- printf("Digite um horario valido:");
- textcolor(15);
- gets(Plst[TL].Pal_Horario);
- }
- gotoxy(3, 8);
- printf("Total de vagas:");
- scanf("%d", &Plst[TL].Pal_TotVagas);
- while(Plst[TL].Pal_TotVagas < 1)
- {
- gotoxy(3, 9);
- textcolor(4);
- printf("Digite um total de vagas valido:");
- textcolor(15);
- scanf("%d", &Plst[TL].Pal_TotVagas);
- }
- Est[TL].Eve_Palestra = Plst[TL].Pal_Codigo;
- Est[TL].Eve_TotalInscritos = 0;
- TL++;
- gotoxy(3, 10);
- textcolor(10);
- printf("Palestra cadastrada!");
- }
- getch();
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- textcolor(15);
- gotoxy(30, 2);
- printf("Cadastro de Palestras");
- gotoxy(3, 3);
- printf("Codigo da palestra (0 para sair):");
- scanf("%d", &CodigoAux);
- }
- OrdenaPalestra(Plst, TL);
- getch();
- }
- void CabecalhoPalestras(void)
- {
- QuadroSimples(1, 1, 3, 10, 15, 0);
- QuadroSimples(1, 11, 3, 58, 15, 0);
- QuadroSimples(1, 59, 3, 69, 15, 0);
- QuadroSimples(1, 70, 3, 77, 15, 0);
- textcolor(15);
- gotoxy(2, 2);
- printf("Codigo");
- gotoxy(12, 2);
- printf("Nome da Palestra");
- gotoxy(60, 2);
- printf("Horario");
- gotoxy(71, 2);
- printf("Vagas");
- }
- void ImprimePalestra(TpPalestra Plst, int linha)
- {
- QuadroSimples(linha, 1, linha+2, 10, 15, 0);
- QuadroSimples(linha, 11, linha+2, 58, 15, 0);
- QuadroSimples(linha, 59, linha+2, 69, 15, 0);
- QuadroSimples(linha, 70, linha+2, 77, 15, 0);
- textcolor(15);
- gotoxy(2, linha+1);
- printf("%d", Plst.Pal_Codigo);
- gotoxy(12, linha+1);
- printf("%s", Plst.Pal_Nome);
- gotoxy(60, linha+1);
- printf("%s", Plst.Pal_Horario);
- gotoxy(71, linha+1);
- printf("%d", Plst.Pal_TotVagas);
- }
- void ListaPalestras(TpPalestra Plst[TFP], int TLP)
- {
- int i, linha = 4;
- system("cls");
- textcolor(15);
- if(TLP == 0)
- {
- textcolor(4);
- gotoxy(27, 2);
- printf("Nenhuma palestra cadastrada!");
- textcolor(15);
- }
- else
- {
- textbackground(4);
- textcolor(14);
- CabecalhoPalestras();
- for(i = 0; i < TLP; i++)
- {
- ImprimePalestra(Plst[i], linha);
- linha+=3;
- }
- linha = 4;
- gotoxy(1, 1);
- textbackground(0);
- }
- getch();
- }
- void ConsultaPalestras(TpPalestra Plst[TFP], int TLP)
- {
- int CodAux, Pos;
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- gotoxy(20,2);
- textcolor(15);
- printf("Consulta de palestras");
- if(TLP == 0)
- {
- gotoxy(20,4);
- textcolor(4);
- printf("Nenhuma palestra cadastrada");
- textcolor(15);
- }
- else
- {
- gotoxy(3, 3);
- printf("Codigo da palestra (0 para sair):");
- scanf("%d", &CodAux);
- while(CodAux > 0)
- {
- Pos = BuscaPalestra(Plst, TLP, CodAux);
- if(Pos == -1)
- {
- gotoxy(3,5);
- textcolor(4);
- printf("Nenhuma palestra com esse codigo");
- textcolor(15);
- }
- else
- {
- system("cls");
- CabecalhoPalestras();
- ImprimePalestra(Plst[Pos], 4);
- }
- getch();
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- gotoxy(20,2);
- textcolor(15);
- printf("Consulta de palestras");
- gotoxy(3, 3);
- printf("Codigo da palestra (0 para sair):");
- 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");
- Quadro(1, 1, 25, 80, 2, 0);
- gotoxy(27,2);
- textcolor(15);
- printf("Exclusao de palestras");
- if(TLP == 0)
- {
- gotoxy(25,3);
- textcolor(4);
- printf("Nenhum palestra cadastrada");
- textcolor(15);
- }
- else
- {
- gotoxy(3, 3);
- printf("Digite o codigo da palestra (0 para sair):");
- scanf("%d", &CodAux);
- while(CodAux > 0)
- {
- Pos = BuscaPalestra(Plst, TLP, CodAux);
- if(Pos == -1)
- {
- gotoxy(3, 4);
- textcolor(4);
- printf("Nenhuma palestra com esse codigo");
- textcolor(15);
- }
- else
- {
- if(ValidaExclusao(Insc, TLI, Plst[Pos].Pal_Codigo) == -1)
- {
- textcolor(4);
- gotoxy(3, 4);
- printf("Palestra tem inscritos cadastrados");
- textcolor(15);
- }
- else
- {
- gotoxy(3, 5);
- textcolor(10);
- printf("Confirma exclusao? (S/N):");
- if(toupper(getch()) == 'S')
- {
- for(;Pos < TLP - 1; Pos++)
- {
- Plst[Pos] = Plst[Pos + 1];
- Est[Pos] = Est[Pos + 1];
- }
- TLP--;
- gotoxy(3, 6);
- printf("Palestra excluida");
- }
- else
- {
- gotoxy(3, 6);
- printf("Exclusao cancelada");
- }
- textcolor(15);
- }
- }
- getch();
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- gotoxy(27,2);
- textcolor(15);
- printf("Exclusao de palestras");
- gotoxy(3, 3);
- printf("Digite o codigo da palestra (0 para sair):");
- scanf("%d", &CodAux);
- }
- }
- getch();
- }
- char MenuAlteraPalestra(void)
- {
- gotoxy(3, 4);
- printf("Escolha:");
- gotoxy(3, 5);
- printf("[A] - Alterar nome");
- gotoxy(3, 6);
- printf("[B] - Alterar horario");
- gotoxy(3, 7);
- printf("[C] - Alterar numero de vagas");
- gotoxy(3, 8);
- printf("[ESC] - Sair");
- return toupper(getch());
- }
- void AlteraPalestra(TpPalestra Plst[TFP], int TLP)
- {
- int CodAux, Pos;
- char Op;
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- gotoxy(27,2);
- textcolor(15);
- printf("Alteracao de palestras");
- if(TLP == 0)
- {
- gotoxy(25,3);
- textcolor(4);
- printf("Nenhum palestra cadastrada");
- textcolor(15);
- }
- else
- {
- gotoxy(3,3);
- printf("Digite o codigo da palestra (0 para sair):");
- 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)
- {
- gotoxy(3, 10);
- switch(Op)
- {
- case 'A':
- printf("Nome atual: %s", Plst[Pos].Pal_Nome);
- gotoxy(3, 11);
- printf("Digite o novo nome:");
- fflush(stdin);
- gets(Plst[Pos].Pal_Nome);
- while(strcmp(Plst[Pos].Pal_Nome, "\0") == 0)
- {
- gotoxy(3, 12);
- textcolor(4);
- printf("Nome invalido. Digite um nome valido:");
- fflush(stdin);
- textcolor(15);
- gets(Plst[Pos].Pal_Nome);
- }
- gotoxy(3, 13);
- printf("Nome alterado");
- break;
- case 'B':
- printf("Horario atual: %s", Plst[Pos].Pal_Horario);
- gotoxy(3, 11);
- printf("Digite o novo horario:");
- fflush(stdin);
- gets(Plst[Pos].Pal_Horario);
- while(strcmp(Plst[Pos].Pal_Horario, "\0") == 0)
- {
- gotoxy(3, 12);
- textcolor(4);
- printf("Horario invalido. Digite um horario valido:");
- fflush(stdin);
- textcolor(15);
- gets(Plst[Pos].Pal_Horario);
- }
- gotoxy(3, 13);
- printf("Horario alterado");
- break;
- case 'C':
- printf("Vagas atuais: %d", Plst[Pos].Pal_TotVagas);
- gotoxy(3, 11);
- printf("Digite o novo numero de vagas:");
- scanf("%d", &Plst[Pos].Pal_TotVagas);
- while(Plst[Pos].Pal_TotVagas < 1)
- {
- gotoxy(3, 12);
- textcolor(4);
- printf("Numero de vagas invalido. Digite um numero de vagas valido:");
- textcolor(15);
- scanf("%d", &Plst[Pos].Pal_TotVagas);
- }
- gotoxy(3, 13);
- printf("Numero de vagas alterado");
- break;
- default:
- textcolor(4);
- printf("Opcao invalida");
- break;
- }
- getch();
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- gotoxy(27,2);
- textcolor(15);
- printf("Alteracao de palestras");
- Op = MenuAlteraPalestra();
- }
- }
- getch();
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- gotoxy(27,2);
- textcolor(15);
- printf("Alteracao de palestras");
- gotoxy(3,3);
- printf("Digite o codigo da palestra (0 para sair):");
- scanf("%d", &CodAux);
- }
- }
- getch();
- }
- char MenuRelatorioPalestras(void)
- {
- gotoxy(3, 4);
- printf("[A] - Busca a partir do inicio");
- gotoxy(3, 5);
- printf("[B] - Busca em qualquer parte do titulo");
- gotoxy(3, 6);
- printf("[ESC] - Sair");
- gotoxy(15, 6);
- return toupper(getch());
- }
- void RelatorioPalestras(TpPalestra Plst[TFP], int TLP)
- {
- int i, linha = 4;
- char Op, NomeAux[40];
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- textcolor(10);
- gotoxy(30, 2);
- printf("Busca de Palestras por titulos");
- gotoxy(3, 3);
- textcolor(15);
- if(TLP == 0)
- {
- gotoxy(20,4);
- textcolor(4);
- printf("Nenhuma palestra cadastrada");
- }
- else
- {
- Op = MenuRelatorioPalestras();
- while(Op != 27)
- {
- gotoxy(3, 8);
- switch(Op)
- {
- case 'A':
- printf("Digite o nome:");
- 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 = 4;
- break;
- case 'B':
- printf("Digite o nome:");
- 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 += 3;
- }
- gotoxy(30, linha);
- textcolor(10);
- printf("Busca concluida");
- textcolor(15);
- linha = 4;
- break;
- default:
- gotoxy(3, 8);
- textcolor(4);
- printf("Opcao invalida");
- break;
- }
- getch();
- system("cls");
- Quadro(1, 1, 25, 80, 2, 0);
- textcolor(10);
- gotoxy(30, 2);
- printf("Busca de Palestras por titulos");
- gotoxy(3, 3);
- textcolor(15);
- 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)
- {
- QuadroSimples(1, 1, 4, 41, 15, 0);
- QuadroSimples(1, 42, 4, 50, 15, 0);
- QuadroSimples(1, 51, 4, 58, 15, 0);
- QuadroSimples(1, 59, 4, 65, 15, 0);
- QuadroSimples(1, 66, 4, 72, 15, 0);
- QuadroSimples(1, 73, 4, 80, 15, 0);
- textcolor(15);
- gotoxy(2,2);
- printf("Palestra");
- gotoxy(43,2);
- printf("Vagas");
- gotoxy(52,2);
- printf("Inscr");
- gotoxy(60,2);
- printf("Insc");
- gotoxy(60,3);
- printf("/vaga");
- gotoxy(67,2);
- printf("Homem");
- gotoxy(74,2);
- printf("Mulher");
- }
- void ImprimeEstatistica(TpEstatistica Est, TpPalestra Plst[TFP], int TLP, int linha)
- {
- int Pos = BuscaPalestra(Plst, TLP, Est.Eve_Palestra);
- QuadroSimples(linha, 1, linha+3, 41, 15, 0);
- QuadroSimples(linha, 42, linha+3, 50, 15, 0);
- QuadroSimples(linha, 51, linha+3, 58, 15, 0);
- QuadroSimples(linha, 59, linha+3, 65, 15, 0);
- QuadroSimples(linha, 66, linha+3, 72, 15, 0);
- QuadroSimples(linha, 73, linha+3, 80, 15, 0);
- textcolor(WHITE);
- gotoxy(2, linha+1);
- printf("%s", Plst[Pos].Pal_Nome);
- gotoxy(43, linha+1);
- printf("%d", Plst[Pos].Pal_TotVagas);
- gotoxy(52, linha+1);
- printf("%d", Est.Eve_TotalInscritos);
- gotoxy(60, linha+1);
- printf("%.2f", Est.Eve_InscrVagas);
- gotoxy(67, linha+1);
- printf("%d", Est.Eve_TotInscrMasc);
- gotoxy(74, linha+1);
- printf("%d", Est.Eve_TotInscrFem);
- }
- void ListaEstatistica(TpEstatistica Est[TFP], TpPalestra Plst[TFP], int TLP)
- {
- int i, Pos, linha = 5;
- system("cls");
- if(TLP == 0)
- {
- gotoxy(30, 2);
- textcolor(4);
- printf("Nenhum palestra cadastrada");
- }
- else
- {
- CabecalhoEstatistica();
- for(i = 0; i < TLP; i++)
- {
- ImprimeEstatistica(Est[i], Plst, TLP, linha);
- linha += 4;
- }
- gotoxy(1, 1);
- }
- getch();
- }
- void ListaParecido(TpPalestra Plst[TFP], int TLP)
- {
- int i, linha = 2;
- char Aux[40];
- system("cls");
- printf("**Busca por titulo similar**\n\n");
- if(TLP == 0)
- {
- textbackground(7);
- textcolor(4);
- printf("Nenhuma palestra cadastrada\n");
- textbackground(0);
- textcolor(7);
- }
- else
- {
- printf("Digite o titulo:\n");
- fflush(stdin);
- gets(Aux);
- while(strcmp(Aux, "\0") != 0)
- {
- system("cls");
- textbackground(4);
- textcolor(14);
- CabecalhoPalestras();
- for(i = 0; i < TLP; i++)
- if(ProcuraMeio(Plst[i].Pal_Nome, Aux) == 1)
- ImprimePalestra(Plst[i], linha++);
- textbackground(0);
- textcolor(7);
- getch();
- system("cls");
- printf("Digite o titulo:\n");
- fflush(stdin);
- gets(Aux);
- }
- }
- getch();
- }
- 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 ");
- 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 ");
- 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':
- ListaParecido(Plst, TLP);
- break;
- case 'L':
- RelatorioPalestras(Plst, TLP);
- break;
- case 'M':
- ListaEstatistica(Est, Plst, TLP);
- break;
- case 'N':
- InsercaoDireta(Plst, TLP, Insc, TLI, Est);
- break;
- default:
- gotoxy(28, 21);
- textcolor(4);
- textbackground(WHITE);
- printf(" Opcao invalida ");
- textcolor(7);
- textbackground(0);
- getch();
- break;
- }
- Op = MenuPrincipal();
- }
- }
- int main(void)
- {
- Executa();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement