Advertisement
Jvsierra

b

Sep 17th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio2.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6.  
  7. #define TFI 100
  8. #define TFP 10
  9.  
  10. struct TpInscrito
  11. {
  12. int Ins_Numero, Cod_Palestra1, Cod_Palestra2;
  13. char Ins_Nome[30], Ins_Sexo, Ins_Cidade[30];
  14. };
  15.  
  16. struct TpPalestra
  17. {
  18. int Pal_Codigo, Pal_TotVagas;
  19. char Pal_Nome[40], Pal_Horario[6];
  20. };
  21.  
  22. struct TpEstatistica
  23. {
  24. int Eve_Palestra, Eve_TotalInscritos, Eve_TotInscrFem, Eve_TotInscrMasc;
  25. float Eve_InscrVagas;
  26. };
  27.  
  28. int BuscaPalestra(TpPalestra Plst[TFP], int TL, int Chave)
  29. {
  30. int i = 0;
  31.  
  32. while(i < TL && Plst[i].Pal_Codigo != Chave)
  33. i++;
  34.  
  35. if(i < TL)
  36. return i;
  37. else
  38. return -1;
  39. }
  40.  
  41. int BuscaInscritos(TpInscrito Insc[TFI], int TL, int Chave)
  42. {
  43. int i = 0;
  44.  
  45. while(i < TL && Insc[i].Ins_Numero != Chave)
  46. i++;
  47.  
  48. if(i < TL)
  49. return i;
  50. else
  51. return -1;
  52. }
  53.  
  54. int BuscaEstatistica(TpEstatistica Est[TFP], int TL, int Chave)
  55. {
  56. int i = 0;
  57.  
  58. while(i < TL && Est[i].Eve_Palestra != Chave)
  59. i++;
  60.  
  61. if(i < TL)
  62. return i;
  63. else
  64. return -1;
  65. }
  66.  
  67. int ValidaExclusao(TpInscrito Insc[TFI], int TLI, int CodPalestra)
  68. {
  69. int i = 0;
  70.  
  71. while(i < TLI && Insc[i].Cod_Palestra1 != CodPalestra && Insc[i].Cod_Palestra2 != CodPalestra)
  72. i++;
  73.  
  74. if(i == TLI)
  75. return 1;
  76. else
  77. return -1;
  78. }
  79.  
  80. void meustrncpy(char str[40], char dest[40], int inicio, int fim)
  81. {
  82. int i, pos = 0;
  83.  
  84. strcpy(dest, "\0");
  85.  
  86. for(i = inicio; i < fim; i++)
  87. dest[pos++] = str[i];
  88.  
  89. dest[pos] = '\0';
  90. }
  91.  
  92. int ProcuraInicio(char str[40], char chave[40], int n)
  93. {
  94. int i = 0;
  95.  
  96. while(i < n && toupper(str[i]) == toupper(chave[i]))
  97. i++;
  98.  
  99. if(i == n)
  100. return 1;
  101. else
  102. return -1;
  103. }
  104.  
  105. int ProcuraMeio(char str[40], char chave[40])
  106. {
  107. int i, inicio = 0, fim = strlen(chave);
  108. char dest[40] = "\0";
  109.  
  110. for(i = 0; fim < strlen(str) && stricmp(dest, chave) != 0; i++)
  111. meustrncpy(str, dest, inicio++, fim++);
  112.  
  113. if(i < strlen(str) && stricmp(dest, chave) == 0)
  114. return 1;
  115. else
  116. return -1;
  117. }
  118.  
  119. void CalculaEstatistica(TpEstatistica Est[TFP], TpPalestra Plst[TFP], int TLP, int Inicio, int Fim)
  120. {
  121. int i;
  122.  
  123. for(i = 0; i < Fim; i++)
  124. Est[i].Eve_InscrVagas = (float)Est[i].Eve_TotalInscritos / Plst[BuscaPalestra(Plst, TLP, Est[i].Eve_Palestra)].Pal_TotVagas;
  125. }
  126.  
  127. void AtualizaEstatistica(TpEstatistica &Est1, TpEstatistica &Est2, char Sexo, int Tipo)
  128. {
  129. /*
  130. Tipo == 1 -> Inserir estatística
  131. Tipo == 2 -> Remover estatística
  132. Tipo == 3 -> Alterar sexo da estatística
  133. Tipo == 4 -> "Swap" entre as estatísticas
  134. */
  135.  
  136. if(Tipo == 1)
  137. {
  138. Est1.Eve_TotalInscritos++;
  139. Est2.Eve_TotalInscritos++;
  140.  
  141. if(Sexo == 'M')
  142. {
  143. Est1.Eve_TotInscrMasc++;
  144. Est2.Eve_TotInscrMasc++;
  145. }
  146. else
  147. {
  148. Est1.Eve_TotInscrFem++;
  149. Est2.Eve_TotInscrFem++;
  150. }
  151. }
  152. else if(Tipo == 2)
  153. {
  154. Est1.Eve_TotalInscritos--;
  155. Est2.Eve_TotalInscritos--;
  156.  
  157. if(Sexo == 'M')
  158. {
  159. Est1.Eve_TotInscrMasc--;
  160. Est2.Eve_TotInscrMasc--;
  161. }
  162. else
  163. {
  164. Est1.Eve_TotInscrFem--;
  165. Est2.Eve_TotInscrFem--;
  166. }
  167. }
  168. else if(Tipo == 3)
  169. {
  170. if(Sexo == 'M')
  171. {
  172. Est1.Eve_TotInscrFem--;
  173. Est1.Eve_TotInscrMasc++;
  174.  
  175. Est2.Eve_TotInscrFem--;
  176. Est2.Eve_TotInscrMasc++;
  177. }
  178. else
  179. {
  180. Est1.Eve_TotInscrFem++;
  181. Est1.Eve_TotInscrMasc--;
  182.  
  183. Est2.Eve_TotInscrFem++;
  184. Est2.Eve_TotInscrMasc--;
  185. }
  186. }
  187. else
  188. {
  189. Est1.Eve_InscrVagas--;
  190. Est2.Eve_InscrVagas++;
  191.  
  192. if(Sexo == 'M')
  193. {
  194. Est1.Eve_TotInscrMasc--;
  195. Est2.Eve_TotInscrMasc++;
  196. }
  197. else
  198. {
  199. Est1.Eve_TotInscrFem--;
  200. Est2.Eve_TotInscrMasc++;
  201. }
  202. }
  203. }
  204.  
  205. void OrdenaInscrito(TpInscrito Insc[TFI], int TLI)
  206. {
  207. int i, j;
  208. TpInscrito Aux;
  209.  
  210. for(i = 0; i < TLI - 1; i++)
  211. for(j = i + 1; j < TLI; j++)
  212. if(strcmp(Insc[i].Ins_Nome, Insc[j].Ins_Nome) > 0)
  213. {
  214. Aux = Insc[i];
  215. Insc[i] = Insc[j];
  216. Insc[j] = Aux;
  217. }
  218. }
  219.  
  220. void OrdenaEstatistica(TpEstatistica Est[TFP], int TL)
  221. {
  222. int i, j;
  223. TpEstatistica Aux;
  224.  
  225. for(i = 0; i < TL - 1; i++)
  226. for(j = i + 1; j < TL; j++)
  227. if(Est[i].Eve_InscrVagas < Est[j].Eve_InscrVagas)
  228. {
  229. Aux = Est[i];
  230. Est[i] = Est[j];
  231. Est[j] = Aux;
  232. }
  233. }
  234.  
  235. void IncluiInscrito(TpInscrito Insc[TFI], int &TLI, TpPalestra Plst[TFP],
  236. int TLP, TpEstatistica Est[TFP])
  237. {
  238. int NumAux, Cont;
  239.  
  240. system("cls");
  241.  
  242. if(TLP >= 2)
  243. {
  244. Cont = 0;
  245.  
  246. printf("**Cadastro de Inscritos**\n\n");
  247.  
  248. printf("Digite o numero do inscrito:\n");
  249. scanf("%d", &NumAux);
  250.  
  251. while(TLI < TFI && NumAux > 0)
  252. {
  253. if(BuscaInscritos(Insc, TLI, NumAux) >= 0)
  254. printf("Numero do inscrito ja cadastrado\n");
  255. else
  256. {
  257. Insc[TLI].Ins_Numero = NumAux;
  258.  
  259. printf("Nome do inscrito:\n");
  260. fflush(stdin);
  261. gets(Insc[TLI].Ins_Nome);
  262.  
  263. while(strcmp(Insc[TLI].Ins_Nome, "\0") == 0)
  264. {
  265. printf("Digite um nome valido:\n");
  266. fflush(stdin);
  267. gets(Insc[TLI].Ins_Nome);
  268. }
  269.  
  270. printf("Sexo:\n");
  271. fflush(stdin);
  272. scanf("%c", &Insc[TLI].Ins_Sexo);
  273. Insc[TLI].Ins_Sexo = toupper(Insc[TLI].Ins_Sexo);
  274.  
  275. while(Insc[TLI].Ins_Sexo != 'M' && Insc[TLI].Ins_Sexo != 'F')
  276. {
  277. textcolor(4);
  278. printf("Voce digitou uma opcao invalida.\nSexo do inscrito (M/F):\n");
  279. fflush(stdin);
  280. scanf("%c", &Insc[TLI].Ins_Sexo);
  281. Insc[TLI].Ins_Sexo = toupper(Insc[TLI].Ins_Sexo);
  282. }
  283.  
  284. textcolor(7);
  285.  
  286. printf("Cidade:\n");
  287. fflush(stdin);
  288. gets(Insc[TLI].Ins_Cidade);
  289.  
  290. while(strcmp(Insc[TLI].Ins_Cidade, "\0") == 0)
  291. {
  292. printf("Digite uma cidade valida:\n");
  293. fflush(stdin);
  294. gets(Insc[TLI].Ins_Cidade);
  295. }
  296.  
  297. printf("Codigo da primeira palestra: \n");
  298. scanf("%d", &Insc[TLI].Cod_Palestra1);
  299.  
  300. while(BuscaPalestra(Plst, TLP, Insc[TLI].Cod_Palestra1) == -1)
  301. {
  302. textcolor(4);
  303. printf("Codigo de palestra inexistente\n");
  304. printf("Codigo da primeira palestra: \n");
  305. scanf("%d", &Insc[TLI].Cod_Palestra1);
  306. }
  307.  
  308. printf("Codigo da segunda palestra:\n");
  309. scanf("%d", &Insc[TLI].Cod_Palestra2);
  310.  
  311. while(BuscaPalestra(Plst, TLP, Insc[TLI].Cod_Palestra2) == -1
  312. || Insc[TLI].Cod_Palestra1 == Insc[TLI].Cod_Palestra2)
  313. {
  314. textcolor(4);
  315. printf("Codigo da palestra invalido.\n");
  316. printf("Codigo da segunda palestra:\n");
  317. scanf("%d", &Insc[TLI].Cod_Palestra2);
  318. }
  319.  
  320. AtualizaEstatistica(Est[BuscaEstatistica(Est, TLP, Insc[TLI].Cod_Palestra1)],
  321. Est[BuscaEstatistica(Est, TLP, Insc[TLI].Cod_Palestra2)],
  322. Insc[TLI].Ins_Sexo, 1);
  323.  
  324. TLI++;
  325.  
  326. Cont++;
  327.  
  328. textcolor(3);
  329. printf("\nInscrito cadastrado\n\n");
  330. }
  331.  
  332. system("cls");
  333.  
  334. textcolor(7);
  335. printf("Digite o numero do inscrito:\n");
  336. scanf("%d", &NumAux);
  337. }
  338.  
  339. CalculaEstatistica(Est, Plst, TLP, TLI - Cont, TLI);
  340. OrdenaEstatistica(Est, TLP);
  341. OrdenaInscrito(Insc, TLI);
  342. }
  343. else
  344. {
  345. textcolor(4);
  346. printf("Nao ha palestras suficientes\n");
  347. }
  348.  
  349. getch();
  350. }
  351.  
  352. void RemoveInscrito(TpInscrito Insc[TFI], int &TLI, TpPalestra Plst[TFP],
  353. int TLP, TpEstatistica Est[TFP])
  354. {
  355. int NumeroAux, Pos, i, PosEst, Cont;
  356.  
  357. system("cls");
  358.  
  359. printf("Exclusao de inscritos\n\n");
  360.  
  361. if(TLI == 0)
  362. {
  363. textcolor(4);
  364. printf("Nenhum inscrito cadastrado\n\n");
  365. }
  366. else
  367. {
  368. printf("Digite o numero do inscrito (0 para sair):\n");
  369. scanf("%d", &NumeroAux);
  370.  
  371. while(NumeroAux > 0)
  372. {
  373. Cont = 0;
  374.  
  375. Pos = BuscaInscritos(Insc, TLI, NumeroAux);
  376.  
  377. if(Pos == -1)
  378. {
  379. textcolor(4);
  380. printf("Nenhum inscrito com esse numero\n");
  381. }
  382. else
  383. {
  384. AtualizaEstatistica(Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra1)],
  385. Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra2)],
  386. Insc[Pos].Ins_Sexo, 2);
  387.  
  388. CalculaEstatistica(Est, Plst, TLP, 0, TLP);
  389.  
  390. for(; Pos < TLI - 1; Pos++)
  391. Insc[Pos] = Insc[Pos + 1];
  392.  
  393. TLI--;
  394.  
  395. textcolor(3);
  396. printf("Inscrito excluido\n");
  397. }
  398.  
  399. printf("Digite o numero do inscrito (0 para sair):\n");
  400. scanf("%d", &NumeroAux);
  401. }
  402.  
  403. }
  404.  
  405. getch();
  406. }
  407.  
  408. char MenuAlteraInscrito(void)
  409. {
  410. printf("Escolha:\n");
  411. printf("[A] - Alterar nome\n");
  412. printf("[B] - Alterar sexo\n");
  413. printf("[C] - Alterar cidade\n");
  414. printf("[D] - Alterar codigo da primeira palestra\n");
  415. printf("[E] - Alterar codigo da segunda palestra\n");
  416. printf("[ESC] - Sair\n");
  417.  
  418. return toupper(getche());
  419. }
  420.  
  421. void AlteraInscrito(TpInscrito Insc[TFI], int TLI, TpPalestra Plst[TFP], int TLP,
  422. TpEstatistica Est[TFP])
  423. {
  424. int Pos, NumAux, PalAux;
  425. char Op, AuxS, StrAux[30];
  426.  
  427. system("cls");
  428.  
  429. printf("**Alteração inscritos**\n\n");
  430.  
  431. if(TLI == 0)
  432. printf("Nenhum inscrito cadastrado\n\n");
  433. else
  434. {
  435. printf("Digite o numero do inscrito (0 para sair):\n");
  436. scanf("%d", &NumAux);
  437.  
  438. while(NumAux > 0)
  439. {
  440. Pos = BuscaInscritos(Insc, TLI, NumAux);
  441.  
  442. if(Pos == -1)
  443. {
  444. textcolor(4);
  445. printf("Nenhum inscrito com esse numero\n");
  446. }
  447. else
  448. {
  449. Op = MenuAlteraInscrito();
  450.  
  451. while(Op != 27)
  452. {
  453. switch(Op)
  454. {
  455. case 'A':
  456. printf("Nome atual: %s\n", Insc[Pos].Ins_Nome);
  457.  
  458. printf("Digite o novo nome:\n");
  459. fflush(stdin);
  460. gets(Insc[Pos].Ins_Nome);
  461.  
  462. while(strcmp(Insc[Pos].Ins_Nome, "\0") == 0)
  463. {
  464. printf("Nome invalido.\n");
  465. printf("Digite o novo nome:\n");
  466. fflush(stdin);
  467. gets(Insc[Pos].Ins_Nome);
  468. }
  469.  
  470. printf("Nome alterado\n");
  471. break;
  472. case 'B':
  473. printf("Sexo atual: %c\n", Insc[Pos].Ins_Sexo);
  474. printf("Digite o novo sexo:\n");
  475. fflush(stdin);
  476. scanf("%c", &AuxS);
  477. AuxS = toupper(AuxS);
  478.  
  479. while(AuxS != 'M' && AuxS != 'F')
  480. {
  481. printf("Sexo invalido\n");
  482.  
  483. printf("Digite o novo sexo:\n");
  484. fflush(stdin);
  485. scanf("%c", &AuxS);
  486. AuxS = toupper(AuxS);
  487. }
  488.  
  489. //Atualizando as estatísticas por sexo das palestras do inscrito
  490. AtualizaEstatistica(Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra1)],
  491. Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra2)],
  492. AuxS, 3);
  493.  
  494. Insc[Pos].Ins_Sexo = AuxS;
  495.  
  496. printf("Sexo alterado\n");
  497. break;
  498. case 'C':
  499. printf("Cidade atual: %c\n", Insc[Pos].Ins_Cidade);
  500.  
  501. printf("Digite a nova cidade:\n");
  502. fflush(stdin);
  503. gets(Insc[Pos].Ins_Cidade);
  504.  
  505. while(strcmp(Insc[Pos].Ins_Cidade, "\0") == 0)
  506. {
  507. printf("Dado invalido\n");
  508.  
  509. printf("Digite a nova cidade:\n");
  510. fflush(stdin);
  511. gets(Insc[Pos].Ins_Cidade);
  512. }
  513.  
  514. printf("Cidade alterada\n");
  515. break;
  516. case 'D':
  517. printf("Codigo atual: %d\n", Insc[Pos].Cod_Palestra1);
  518.  
  519. printf("Digite o novo codigo da primeira palestra:\n");
  520. scanf("%d", &PalAux);
  521.  
  522. while(BuscaPalestra(Plst, TLP, PalAux) == - 1 ||
  523. PalAux == Insc[Pos].Cod_Palestra2)
  524. {
  525. printf("Codigo de palestra invalido\n");
  526. printf("Digite o novo codigo da primeira palestra:\n");
  527. scanf("%d", &PalAux);
  528. }
  529.  
  530. AtualizaEstatistica(Est[BuscaEstatistica(Est, TLP, PalAux)],
  531. Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra1)],
  532. Insc[Pos].Ins_Sexo, 4);
  533.  
  534. Insc[Pos].Cod_Palestra1 = PalAux;
  535.  
  536. printf("Codigo da primeira palestra alterado\n");
  537. break;
  538. case 'E':
  539. printf("Codigo atual: %d\n", Insc[Pos].Cod_Palestra2);
  540.  
  541. printf("Digite o novo codigo da segunda palestra:\n");
  542. scanf("%d", &PalAux);
  543.  
  544. while(BuscaPalestra(Plst, TLP, PalAux) == - 1 ||
  545. PalAux == Insc[Pos].Cod_Palestra1)
  546. {
  547. printf("Codigo de palestra invalido\n");
  548. printf("Digite o novo codigo da segunda palestra:\n");
  549. scanf("%d", &PalAux);
  550. }
  551.  
  552. AtualizaEstatistica(Est[BuscaEstatistica(Est, TLP, PalAux)],
  553. Est[BuscaEstatistica(Est, TLP, Insc[Pos].Cod_Palestra2)],
  554. Insc[Pos].Ins_Sexo, 4);
  555.  
  556. Insc[Pos].Cod_Palestra2 = PalAux;
  557.  
  558. printf("Codigo da segunda palestra alterado\n");
  559. break;
  560. default:
  561. printf("Opcao invalida\n");
  562. }
  563.  
  564. getch();
  565.  
  566. system("cls");
  567.  
  568. Op = MenuAlteraInscrito();
  569. }
  570. }
  571.  
  572. getch();
  573.  
  574. printf("Digite o numero do inscrito (0 para sair):\n");
  575. scanf("%d", &NumAux);
  576. }
  577.  
  578. OrdenaInscrito(Insc, TLI);
  579. }
  580.  
  581. getch();
  582. }
  583.  
  584. void CabecalhoInscritos(void)
  585. {
  586. gotoxy(1, 1);
  587. printf("Nome");
  588. gotoxy(20, 1);
  589. printf("Sexo");
  590. gotoxy(25, 1);
  591. printf("Cidade");
  592. gotoxy(55, 1);
  593. printf("Palestra 1");
  594. gotoxy(67, 1);
  595. printf("Palestra 2");
  596.  
  597. }
  598.  
  599. void ImprimeInscrito(TpInscrito Insc, int linha)
  600. {
  601. gotoxy(1,linha);
  602. printf("%s", Insc.Ins_Nome);
  603. gotoxy(20,linha);
  604. printf("%c", Insc.Ins_Sexo);
  605. gotoxy(25,linha);
  606. printf("%s", Insc.Ins_Cidade);
  607. gotoxy(55,linha);
  608. printf("%d", Insc.Cod_Palestra1);
  609. gotoxy(67,linha);
  610. printf("%d", Insc.Cod_Palestra2);
  611. }
  612.  
  613. void ConsultaInscrito(TpInscrito Insc[TFI], int TLI, TpPalestra Plst[TFP], int TLP)
  614. {
  615. int NumAux, Pos, linha = 2;
  616.  
  617. textbackground(0);
  618.  
  619. system("cls");
  620.  
  621. printf("**Consulta de Inscritos**\n");
  622.  
  623. if(TLI == 0)
  624. {
  625. textcolor(4);
  626. printf("Nenhum inscrito cadastrado\n");
  627. }
  628. else
  629. {
  630. printf("Digite o numero do inscrito (0 para sair):\n");
  631. scanf("%d", &NumAux);
  632.  
  633. while(NumAux > 0)
  634. {
  635. Pos = BuscaInscritos(Insc, TLI, NumAux);
  636.  
  637. system("cls");
  638.  
  639. if(Pos == -1)
  640. {
  641. textcolor(4);
  642. printf("Nenhum inscrito com esse numero");
  643. textcolor(7);
  644. }
  645. else
  646. {
  647. textbackground(4);
  648. textcolor(14);
  649.  
  650. CabecalhoInscritos();
  651. ImprimeInscrito(Insc[Pos], linha);
  652. textcolor(7);
  653. }
  654.  
  655. textbackground(0);
  656.  
  657. printf("\nDigite o numero do inscrito (0 para sair):\n");
  658. scanf("%d", &NumAux);
  659. }
  660. }
  661.  
  662. getch();
  663. }
  664.  
  665. void ListaInscritos(TpInscrito Insc[TFI], int TLI, TpPalestra Plst[TFP], int TLP)
  666. {
  667. int i, linha = 2;
  668.  
  669. system("cls");
  670.  
  671. if(TLI == 0)
  672. printf("Nenhum inscrito cadastrado\n\n");
  673. else
  674. {
  675. textbackground(4);
  676. textcolor(14);
  677.  
  678. CabecalhoInscritos();
  679.  
  680. for(i = 0; i < TLI; i++)
  681. {
  682. ImprimeInscrito(Insc[i], linha++);
  683. }
  684.  
  685. textbackground(0);
  686. }
  687.  
  688. getch();
  689. }
  690.  
  691. void OrdenaPalestra(TpPalestra Plst[TFP], int TLP)
  692. {
  693. int i, j;
  694. TpPalestra Aux;
  695.  
  696. for(i = 0; i < TLP - 1; i++)
  697. for(j = i + 1; j < TLP; j++)
  698. if(strcmp(Plst[i].Pal_Nome, Plst[j].Pal_Nome) > 0)
  699. {
  700. Aux = Plst[i];
  701. Plst[i] = Plst[j];
  702. Plst[j] = Aux;
  703. }
  704. }
  705.  
  706. void IncluiPalestra(TpPalestra Plst[TFP], int &TL, TpEstatistica Est[TFP])
  707. {
  708. int CodigoAux, TotVagasAux;
  709. char NomeAux[40], HorarioAux[6];
  710.  
  711. system("cls");
  712.  
  713. printf("\n\nCadastro de palestras\n\n");
  714.  
  715. printf("Codigo da palestra:\n");
  716. scanf("%d", &CodigoAux);
  717.  
  718. while(TL < TFP && CodigoAux > 0)
  719. {
  720. if(BuscaPalestra(Plst, TL, CodigoAux) >= 0)
  721. printf("Codigo de palestra ja cadastrado\n\n");
  722. else
  723. {
  724. Plst[TL].Pal_Codigo = CodigoAux;
  725.  
  726. printf("Nome da palestra:\n");
  727. fflush(stdin);
  728. gets(NomeAux);
  729.  
  730. while(strcmp(NomeAux, "\0") == 0)
  731. {
  732. printf("Digite um nome valido\n");
  733. fflush(stdin);
  734. gets(NomeAux);
  735. }
  736.  
  737. strcpy(Plst[TL].Pal_Nome, NomeAux);
  738.  
  739. printf("Horario da palestra (hh:mm)\n");
  740. fflush(stdin);
  741. gets(Plst[TL].Pal_Horario);
  742.  
  743. printf("Total de vagas:\n");
  744. scanf("%d", &Plst[TL].Pal_TotVagas);
  745.  
  746. Est[TL].Eve_Palestra = Plst[TL].Pal_Codigo;
  747. Est[TL].Eve_TotalInscritos = 0;
  748.  
  749. TL++;
  750.  
  751. printf("Palestra cadastrada\n\n");
  752. }
  753.  
  754. printf("Codigo da palestra:\n");
  755. scanf("%d", &CodigoAux);
  756. }
  757.  
  758. OrdenaPalestra(Plst, TL);
  759.  
  760. getch();
  761. }
  762.  
  763. void CabecalhoPalestras(void)
  764. {
  765. textcolor(15);
  766. textbackground(1);
  767.  
  768. gotoxy(1, 1);
  769. printf("Codigo");
  770.  
  771. gotoxy(15, 1);
  772. printf("Nome");
  773.  
  774. gotoxy(65, 1);
  775. printf("Horario");
  776.  
  777. gotoxy(75, 1);
  778. printf("Vagas");
  779. }
  780.  
  781. void ImprimePalestra(TpPalestra Plst, int linha)
  782. {
  783. gotoxy(1, linha);
  784. printf("%d", Plst.Pal_Codigo);
  785.  
  786. gotoxy(15, linha);
  787. printf("%s", Plst.Pal_Nome);
  788.  
  789. gotoxy(65, linha);
  790. printf("%s", Plst.Pal_Horario);
  791.  
  792. gotoxy(75, linha);
  793. printf("%d", Plst.Pal_TotVagas);
  794. }
  795.  
  796. void ListaPalestras(TpPalestra Plst[TFP], int TLP)
  797. {
  798. int i, linha = 2;
  799.  
  800. system("cls");
  801.  
  802. if(TLP == 0)
  803. {
  804. textbackground(15);
  805. textcolor(4);
  806. printf("Nenhuma palestra cadastrada\n");
  807. }
  808. else
  809. {
  810. textbackground(4);
  811. textcolor(14);
  812.  
  813. CabecalhoPalestras();
  814.  
  815. for(i = 0; i < TLP; i++)
  816. ImprimePalestra(Plst[i], linha++);
  817.  
  818.  
  819. textbackground(0);
  820. }
  821.  
  822. getch();
  823. }
  824.  
  825. void ConsultaPalestras(TpPalestra Plst[TFP], int TLP)
  826. {
  827. int CodAux, Pos;
  828.  
  829. system("cls");
  830.  
  831. printf("Consulta de palestras\n\n");
  832.  
  833. if(TLP == 0)
  834. printf("Nenhuma palestra cadastrada\n");
  835. else
  836. {
  837. printf("\nDigite o codigo da palestra (0 para sair):\n");
  838. scanf("%d", &CodAux);
  839.  
  840. while(CodAux > 0)
  841. {
  842. Pos = BuscaPalestra(Plst, TLP, CodAux);
  843.  
  844. if(Pos == -1)
  845. printf("Nenhuma palestra com esse codigo\n");
  846. else
  847. {
  848.  
  849. }
  850.  
  851. printf("\nDigite o codigo da palestra (0 para sair):\n");
  852. scanf("%d", &CodAux);
  853. }
  854. }
  855.  
  856. textbackground(0);
  857.  
  858. getch();
  859. }
  860.  
  861. void ExcluiPalestra(TpPalestra Plst[TFP], TpInscrito Insc[TFI],
  862. int TLI, TpEstatistica Est[TFP], int &TLP)
  863. {
  864. int CodAux, Pos;
  865.  
  866. system("cls");
  867.  
  868. printf("Exclusao de palestras\n\n");
  869.  
  870. if(TLP == 0)
  871. printf("Nenhuma palestra cadastrada\n\n");
  872. else
  873. {
  874. printf("Digite o codigo da palestra (0 para sair):\n");
  875. scanf("%d", &CodAux);
  876.  
  877. while(CodAux > 0)
  878. {
  879. Pos = BuscaPalestra(Plst, TLP, CodAux);
  880.  
  881. if(Pos == -1)
  882. printf("Nenhuma palestra com esse codigo\n");
  883. else
  884. {
  885. if(ValidaExclusao(Insc, TLI, Plst[Pos].Pal_Codigo) == -1)
  886. {
  887. textbackground(7);
  888. textcolor(4);
  889. printf("Palestra tem inscritos cadastrados\n");
  890. textbackground(0);
  891. textcolor(7);
  892. }
  893. else
  894. {
  895. for(;Pos < TLP - 1; Pos++)
  896. {
  897. Plst[Pos] = Plst[Pos + 1];
  898. Est[Pos] = Est[Pos + 1];
  899. }
  900.  
  901. TLP--;
  902.  
  903. textcolor(3);
  904. printf("Palestra excluida\n");
  905. textcolor(7);
  906. }
  907.  
  908. }
  909.  
  910. printf("Digite o codigo da palestra (0 para sair):\n");
  911. scanf("%d", &CodAux);
  912. }
  913. }
  914.  
  915. getch();
  916. }
  917.  
  918. char MenuAlteraPalestra(void)
  919. {
  920. printf("Escolha:\n");
  921. printf("[A] - Alterar nome\n");
  922. printf("[B] - Alterar horario\n");
  923. printf("[C] - Alterar numero de vagas\n");
  924. printf("[ESC] - Sair\n");
  925.  
  926. return toupper(getche());
  927. }
  928.  
  929. void AlteraPalestra(TpPalestra Plst[TFP], int TLP)
  930. {
  931. int Pos, TotVagasAux, CodAux;
  932. char NomeAux[40], HorarioAux[6], Op;
  933.  
  934. system("cls");
  935.  
  936. printf("Alteração de palestras\n\n");
  937.  
  938. if(TLP == 0)
  939. printf("Nenhuma palestra cadastrada\n");
  940. else
  941. {
  942. printf("Digite o codigo da palestra (0 para sair):\n");
  943. scanf("%d", &CodAux);
  944.  
  945. while(CodAux > 0)
  946. {
  947. Pos = BuscaPalestra(Plst, TLP, CodAux);
  948.  
  949. if(Pos == -1)
  950. printf("Nenhuma palestra com esse codigo\n");
  951. else
  952. {
  953. Op = MenuAlteraPalestra();
  954.  
  955. while(Op != 27)
  956. {
  957. switch(Op)
  958. {
  959. case 'A':
  960. printf("Nome atual: %s\n", Plst[Pos].Pal_Nome);
  961.  
  962. printf("Digite o novo nome:\n");
  963. fflush(stdin);
  964. gets(NomeAux);
  965.  
  966. while(strcmp(NomeAux, "\0") == 0)
  967. {
  968. printf("Nome invalido\n");
  969.  
  970. printf("Digite o novo nome:\n");
  971. fflush(stdin);
  972. gets(NomeAux);
  973. }
  974.  
  975. strcpy(Plst[Pos].Pal_Nome, NomeAux);
  976.  
  977. printf("Nome alterado\n");
  978. break;
  979. case 'B':
  980. printf("Horario atual: %s\n", Plst[Pos].Pal_Horario);
  981.  
  982. printf("Digite o novo horario:\n");
  983. fflush(stdin);
  984. gets(HorarioAux);
  985.  
  986. while(strcmp(HorarioAux, "\0") == 0)
  987. {
  988. printf("Horario invalido\n");
  989.  
  990. printf("Digite o novo horario:\n");
  991. fflush(stdin);
  992. gets(HorarioAux);
  993. }
  994.  
  995. strcpy(Plst[Pos].Pal_Horario, HorarioAux);
  996.  
  997. printf("Horario alterado\n");
  998. break;
  999. case 'C':
  1000. printf("\nVagas atuais: %d\n", Plst[Pos].Pal_TotVagas);
  1001.  
  1002. printf("Digite o novo numero de vagas:\n");
  1003. scanf("%d", &TotVagasAux);
  1004.  
  1005. while(TotVagasAux < 1)
  1006. {
  1007. printf("Numero de vagas invalido\n");
  1008.  
  1009. printf("Digite o novo numero de vagas:\n");
  1010. scanf("%d", &TotVagasAux);
  1011. }
  1012.  
  1013. Plst[Pos].Pal_TotVagas = TotVagasAux;
  1014.  
  1015. printf("Numero de vagas alterado\n");
  1016. break;
  1017. default:
  1018. printf("Opcao invalida\n");
  1019. }
  1020.  
  1021. getch();
  1022.  
  1023. Op = MenuAlteraPalestra();
  1024. }
  1025. }
  1026.  
  1027. printf("Digite o codigo da palestra (0 para sair):\n");
  1028. scanf("%d", &CodAux);
  1029. }
  1030. }
  1031.  
  1032. getch();
  1033. }
  1034.  
  1035. char MenuRelatorioPalestras(void)
  1036. {
  1037.  
  1038. printf("[A] - Busca a partir do inicio\n");
  1039. printf("[B] - Busca em qualquer parte do titulo\n");
  1040. printf("[ESC] - Sair\n");
  1041.  
  1042. return toupper(getche());
  1043. }
  1044.  
  1045. void RelatorioPalestras(TpPalestra Plst[TFP], int TLP)
  1046. {
  1047. int i, linha = 2;
  1048. char Op, NomeAux[40];
  1049.  
  1050. system("cls");
  1051.  
  1052. printf("**Busca de palestras por titulo**\n\n");
  1053.  
  1054. if(TLP == 0)
  1055. printf("Nenhuma palestra cadastrada\n");
  1056. else
  1057. {
  1058. Op = MenuRelatorioPalestras();
  1059.  
  1060. while(Op != 27)
  1061. {
  1062. switch(Op)
  1063. {
  1064. case 'A':
  1065. printf("\nDigite o nome:\n");
  1066. fflush(stdin);
  1067. gets(NomeAux);
  1068.  
  1069. system("cls");
  1070.  
  1071. CabecalhoPalestras();
  1072.  
  1073. for(i = 0; i < TLP; i++)
  1074. if(ProcuraInicio(Plst[i].Pal_Nome, NomeAux, strlen(NomeAux)) == 1)
  1075. ImprimePalestra(Plst[i], linha++);
  1076.  
  1077. linha = 1;
  1078.  
  1079. printf("\nBusca Concluida\n");
  1080. break;
  1081. case 'B':
  1082. printf("\nDigite o nome:\n");
  1083. fflush(stdin);
  1084. gets(NomeAux);
  1085.  
  1086. system("cls");
  1087.  
  1088. CabecalhoPalestras();
  1089.  
  1090. for(i = 0; i < TLP; i++)
  1091. if(ProcuraMeio(Plst[i].Pal_Nome, NomeAux) == 1)
  1092. ImprimePalestra(Plst[i], linha++);
  1093.  
  1094. linha = 1;
  1095.  
  1096. printf("\nBusca concluida\n");
  1097. break;
  1098. default:
  1099. printf("Opcao invalida\n");
  1100. }
  1101.  
  1102. Op = MenuRelatorioPalestras();
  1103. }
  1104. }
  1105.  
  1106. textbackground(0);
  1107.  
  1108. getch();
  1109. }
  1110.  
  1111. void InsercaoDireta(TpPalestra Plst[TFP], int &TLP, TpInscrito Insc[TFI], int &TLI,
  1112. TpEstatistica Est[TFP])
  1113. {
  1114. int i;
  1115.  
  1116. TpPalestra InsercPalestra[5] = {{1, 2, "Big Data em Universidades", "21:00"},
  1117. {2, 3, "Skills para ser cientista de dados", "18:30"},
  1118. {3, 4, "Marcos tecnicos do Hadoop 3", "09:00"},
  1119. {4, 5, "Impactos da IA nos empregos", "19:00"},
  1120. {5, 10, "Usando Big Data em corporacoes", "20:30"}};
  1121.  
  1122. TpInscrito InsercInscrito[5] = {{1, 1, 2, "Joao Victor Sierra", 'M', "Regente Feijo"},
  1123. {2, 1, 2, "Lucas Gomes", 'M', "Pirapo"},
  1124. {3, 3, 5, "Luana Campos", 'F', "Presidente Venceslau"},
  1125. {4, 5, 4, "Sofia Vieira", 'F', "Sao Paulo"},
  1126. {5, 1, 5, "Manoel Silva", 'M', "Uberaba"}};
  1127.  
  1128. system("cls");
  1129.  
  1130. if(TLP > 0 || TLI > 0)
  1131. {
  1132. textcolor(4);
  1133. textbackground(8);
  1134. printf("Ja existem dados cadastrados\n");
  1135. }
  1136. else
  1137. {
  1138. for(i = 0; i < 5; i++)
  1139. {
  1140. Plst[TLP].Pal_Codigo = InsercPalestra[i].Pal_Codigo;
  1141. Plst[TLP].Pal_TotVagas = InsercPalestra[i].Pal_TotVagas;
  1142. strcpy(Plst[TLP].Pal_Nome, InsercPalestra[i].Pal_Nome);
  1143. strcpy(Plst[TLP].Pal_Horario, InsercPalestra[i].Pal_Horario);
  1144.  
  1145. Est[TLP].Eve_Palestra = InsercPalestra[i].Pal_Codigo;
  1146. Est[TLP].Eve_TotalInscritos = 0;
  1147. Est[TLP].Eve_TotInscrFem = 0;
  1148. Est[TLP].Eve_TotInscrMasc = 0;
  1149.  
  1150. TLP++;
  1151. }
  1152.  
  1153. for(i = 0; i < 5; i++)
  1154. {
  1155. Insc[TLI].Ins_Numero = InsercInscrito[i].Ins_Numero;
  1156. Insc[TLI].Cod_Palestra1 = InsercInscrito[i].Cod_Palestra1;
  1157. Insc[TLI].Cod_Palestra2 = InsercInscrito[i].Cod_Palestra2;
  1158. strcpy(Insc[TLI].Ins_Nome, InsercInscrito[i].Ins_Nome);
  1159. strcpy(Insc[TLI].Ins_Cidade, InsercInscrito[i].Ins_Cidade);
  1160. Insc[TLI].Ins_Sexo = InsercInscrito[i].Ins_Sexo;
  1161.  
  1162. AtualizaEstatistica(Est[BuscaPalestra(Plst, TLP, InsercInscrito[i].Cod_Palestra1)],
  1163. Est[BuscaPalestra(Plst, TLP, InsercInscrito[i].Cod_Palestra2)],
  1164. InsercInscrito[i].Ins_Sexo, 1);
  1165.  
  1166. TLI++;
  1167. }
  1168.  
  1169. CalculaEstatistica(Est, Plst, TLP, 0, 5);
  1170. OrdenaEstatistica(Est, TLP);
  1171. OrdenaInscrito(Insc, TLI);
  1172. OrdenaPalestra(Plst, TLP);
  1173.  
  1174. textbackground(4);
  1175. textcolor(14);
  1176. printf("Dados cadastrados\n");
  1177. }
  1178.  
  1179. textbackground(0);
  1180.  
  1181. getch();
  1182. }
  1183.  
  1184. void CabecalhoEstatistica(void)
  1185. {
  1186. gotoxy(1, 1);
  1187. printf("Palestra");
  1188. gotoxy(42, 1);
  1189. printf("Vagas");
  1190. gotoxy(52, 1);
  1191. printf("Insc/vaga");
  1192. gotoxy(65, 1);
  1193. printf("Homens");
  1194. gotoxy(72, 1);
  1195. printf("Mulheres");
  1196. }
  1197.  
  1198. void ImprimeEstatistica(TpEstatistica Est, TpPalestra Plst[TFP], int TLP, int linha)
  1199. {
  1200.  
  1201. int Pos = BuscaPalestra(Plst, TLP, Est.Eve_Palestra);
  1202.  
  1203. gotoxy(1, linha);
  1204. printf("%s", Plst[Pos].Pal_Nome);
  1205. gotoxy(42, linha);
  1206. printf("%d", Plst[Pos].Pal_TotVagas);
  1207. gotoxy(52, linha);
  1208. printf("%.2f", Est.Eve_InscrVagas);
  1209. gotoxy(65, linha);
  1210. printf("%d", Est.Eve_TotalInscritos);
  1211. gotoxy(65, linha);
  1212. printf("%d", Est.Eve_TotInscrMasc);
  1213. gotoxy(72, linha);
  1214. printf("%d", Est.Eve_TotInscrFem);
  1215. }
  1216.  
  1217. void ListaEstatistica(TpEstatistica Est[TFP], TpPalestra Plst[TFP], int TLP)
  1218. {
  1219. int i, Pos, linha = 2;
  1220.  
  1221. system("cls");
  1222.  
  1223. if(TLP == 0)
  1224. printf("Nenhuma palestra cadastrada\n");
  1225. else
  1226. {
  1227. textbackground(4);
  1228. textcolor(14);
  1229.  
  1230. CabecalhoEstatistica();
  1231.  
  1232. for(i = 0; i < TLP; i++)
  1233. ImprimeEstatistica(Est[i], Plst, TLP, linha++);
  1234.  
  1235. gotoxy(1, linha);
  1236.  
  1237. textbackground(0);
  1238. textcolor(7);
  1239. }
  1240.  
  1241. getch();
  1242. }
  1243.  
  1244. void Quadro(int LI, int CI, int LF, int CF, int CorT, int corF)
  1245. {
  1246. int i;
  1247.  
  1248. textcolor(CorT);
  1249. textbackground(corF);
  1250.  
  1251. gotoxy(CI, LI);
  1252. printf("%c", 201);
  1253.  
  1254. gotoxy(CI, LF);
  1255. printf("%c", 200);
  1256.  
  1257. gotoxy(CF, LI);
  1258. printf("%c", 187);
  1259.  
  1260. gotoxy(CF, LF);
  1261.  
  1262. printf("%c", 188);
  1263.  
  1264. for(i = CI+1; i < CF; i++)
  1265. {
  1266. gotoxy(i, LI);
  1267. printf("%c", 205);
  1268. }
  1269.  
  1270. for(i = LI + 1; i < LF; i++)
  1271. {
  1272. gotoxy(CI, i);
  1273. printf("%c", 186);
  1274. gotoxy(CF, i);
  1275. printf("%c", 186);
  1276. }
  1277.  
  1278. for(i = CI + 1; i < CF; i++)
  1279. {
  1280. gotoxy(i, LF);
  1281. printf("%c", 205);
  1282. }
  1283.  
  1284. textcolor(7);
  1285. textbackground(0);
  1286. }
  1287.  
  1288. char MenuPrincipal(void)
  1289. {
  1290. int Linha = 5;
  1291. system("cls");
  1292.  
  1293. Quadro(2, 20, 22, 54, 14, 0);
  1294.  
  1295. Quadro(4, 22, 20, 52, 14, 0);
  1296.  
  1297. textbackground(4);
  1298. textcolor(14);
  1299.  
  1300. gotoxy(28, 3);
  1301.  
  1302. printf("MENU - Big Data Week");
  1303.  
  1304. gotoxy(24,Linha++);
  1305. printf("[A] - Incluir inscritos");
  1306. gotoxy(24,Linha++);
  1307. printf("[B] - Consultar inscritos");
  1308. gotoxy(24,Linha++);
  1309. printf("[C] - Alterar inscritos");
  1310. gotoxy(24,Linha++);
  1311. printf("[D] - Excluir inscritos");
  1312. gotoxy(24,Linha++);
  1313. printf("[E] - Exibir inscritos");
  1314. gotoxy(24,Linha++);
  1315. printf("[F] - Incluir palestras");
  1316. gotoxy(24,Linha++);
  1317. printf("[G] - Consultar palestras");
  1318. gotoxy(24,Linha++);
  1319. printf("[H] - Alterar palestras");
  1320. gotoxy(24,Linha++);
  1321. printf("[I] - Excluir palestras");
  1322. gotoxy(24,Linha++);
  1323. printf("[J] - Exibir palestras\n");
  1324. gotoxy(24,Linha++);
  1325. printf("[K] - Consultar por tema");
  1326. gotoxy(24,Linha++);
  1327. printf("[L] - Relatorio por nome");
  1328. gotoxy(24,Linha++);
  1329. printf("[M] - Exibir estatistica");
  1330. gotoxy(24,Linha++);
  1331. printf("[N] - Insercao direta");
  1332. gotoxy(24,Linha);
  1333. printf("[ESC] - Sair\n");
  1334.  
  1335. textbackground(0);
  1336. textcolor(7);
  1337.  
  1338. gotoxy(37, Linha);
  1339.  
  1340. return toupper(getch());
  1341. }
  1342.  
  1343. void Executa(void)
  1344. {
  1345. TpInscrito Insc[TFI];
  1346. TpPalestra Plst[TFP];
  1347. TpEstatistica Est[TFP];
  1348. int TLI = 0, TLP = 0;
  1349. char Op;
  1350.  
  1351. Op = MenuPrincipal();
  1352.  
  1353. while(Op != 27)
  1354. {
  1355. switch(Op)
  1356. {
  1357. case 'A':
  1358. IncluiInscrito(Insc, TLI, Plst, TLP, Est);
  1359. break;
  1360. case 'B':
  1361. ConsultaInscrito(Insc, TLI, Plst, TLP);
  1362. break;
  1363. case 'C':
  1364. AlteraInscrito(Insc, TLI, Plst, TLP, Est);
  1365. break;
  1366. case 'D':
  1367. RemoveInscrito(Insc, TLI, Plst, TLP, Est);
  1368. break;
  1369. case 'E':
  1370. ListaInscritos(Insc, TLI, Plst, TLP);
  1371. break;
  1372. case 'F':
  1373. IncluiPalestra(Plst, TLP, Est);
  1374. break;
  1375. case 'G':
  1376. ConsultaPalestras(Plst, TLP);
  1377. break;
  1378. case 'H':
  1379. AlteraPalestra(Plst, TLP);
  1380. break;
  1381. case 'I':
  1382. ExcluiPalestra(Plst, Insc, TLI, Est, TLP);
  1383. break;
  1384. case 'J':
  1385. ListaPalestras(Plst, TLP);
  1386. break;
  1387. case 'K':
  1388. //
  1389. break;
  1390. case 'L':
  1391. RelatorioPalestras(Plst, TLP);
  1392. break;
  1393. case 'M':
  1394. ListaEstatistica(Est, Plst, TLP);
  1395. break;
  1396. case 'N':
  1397. InsercaoDireta(Plst, TLP, Insc, TLI, Est);
  1398. break;
  1399. default:
  1400. printf("\nOpcao invalida\n");
  1401. }
  1402.  
  1403. Op = MenuPrincipal();
  1404. }
  1405. }
  1406.  
  1407. int main(void)
  1408. {
  1409. Executa();
  1410.  
  1411. return 1;
  1412. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement