Advertisement
BrunoMPP

300 Final

May 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <locale.h>
  5.  
  6. typedef struct aluno
  7. {
  8.     char CPF[15];       //CPF do aluno
  9.     char nome[80];      //nome do aluno
  10.     int *numaula;       //aponta p/o registro da aula
  11. } aluno;
  12.  
  13. typedef struct dance
  14. {
  15.     int regaula;        //registro gerado automaticamente
  16.     int qaluno;         //registra a quantidade de alunos matriculados
  17.     char *modalidade;   //exemplo: ballet, tap americano, jazz, street
  18.     char *grau;         //exemplo: iniciante, intermediário, avançado
  19.     float valor;        //valor da aula
  20. } dance;
  21.  
  22. //ALOCAÇÕES
  23. void alocaAluno(aluno **p,int tam);
  24. void alocaDance(dance **p, int tam);
  25. void alocaChar(char **p,int tam);
  26.  
  27. //OPERAÇÕES MENU
  28. void matricular(aluno *pa, dance *pd, int tamD);
  29. void montarClasse(dance *pd,int tamD);
  30. void buscarModalidade(aluno *pa, dance *pd, int tamA, int tamD);
  31. void buscarAluno(aluno *pa, dance *pd, int tamA, int tamD);
  32. void encerrarMatricula(aluno *pa, dance *pd, int tamA, int tamD);
  33. void encerrarAula(aluno *pa, dance *pd, int tamA, int tamD);
  34.  
  35. //VERIFICAÇÕES
  36. int procurarAula(dance *pd, int tamD, char *mod, char *grau);
  37.  
  38. //OUTRAS
  39. void maiuscula(char *p);
  40.  
  41. main()
  42. {
  43.     setlocale(LC_ALL,"");
  44.  
  45.     aluno *pa=NULL;
  46.     dance *pd=NULL;
  47.  
  48.     int tamA=0,tamD=0;
  49.     char op;
  50.  
  51.     do
  52.     {
  53.         system("cls");
  54.         printf("\n.:MENU:.\n");
  55.         printf("[1] - Matrícular\n[2] - Montar Classe\n[3] - Buscar Modalidade\n[4] - Buscar Aluno\n[5] - Encerrar Matrícula\n[6] - Encerrar Classe\n[7] - Sair\n:>   ");
  56.         scanf("%i", &op);
  57.         fflush(stdin);
  58.  
  59.  
  60.         switch(op)
  61.         {
  62.         case 1:
  63.             alocaAluno(&pa,tamA+1);
  64.             matricular(pa+tamA,pd,tamD);
  65.             tamA++;
  66.             break;
  67.         case 2:
  68.             alocaDance(&pd,tamD+1);
  69.             montarClasse(pd+tamD,tamD);
  70.             tamD++;
  71.             break;
  72.         case 3:
  73.             buscarModalidade(pa, pd, tamA, tamD);
  74.             break;
  75.         case 4:
  76.             buscarAluno(pa, pd, tamA, tamD);
  77.             break;
  78.         case 5:
  79.             encerrarMatricula(pa,pd,tamA,tamD);
  80.             break;
  81.         case 6:
  82.             encerrarAula(pa,pd,tamA,tamD);
  83.             break;
  84.         }//switch
  85.     }
  86.     while(op!= 7);
  87.  
  88. }//main
  89.  
  90. void matricular(aluno *pa, dance *pd, int tamD)
  91. {
  92.     char mod[80],grau[2];
  93.     int x;
  94.  
  95.     system("cls");
  96.     printf("\n.:MATRÍCULA:.\n");
  97.  
  98.     printf("\nNome:\n:>\t");
  99.     gets(pa->nome);
  100.     fflush(stdin);
  101.  
  102.     printf("\nCPF:\n:>\t");
  103.     gets(pa->CPF);
  104.     fflush(stdin);
  105.  
  106.     printf("\nInforme a Modalidade que deseja cursar:\n:>\t");
  107.     gets(mod);
  108.     //maiuscula(mod);
  109.     fflush(stdin);
  110.  
  111.     printf("\nQual o grau do curso <0 - Iniciante / 1 - Intermediário / 2 - Avançado>:\n:>\t");
  112.     gets(grau);
  113.     fflush(stdin);
  114.  
  115.     x = procurarAula(pd,tamD,mod,grau);
  116.  
  117.     if(x == -1)
  118.     {
  119.         printf("\nAula Indisponível!\n");
  120.         system("pause");
  121.     }
  122.     else if(x == -2)
  123.     {
  124.         printf("\nAula Cheia!\n");
  125.         system("pause");
  126.  
  127.     }
  128.     else
  129.     {
  130.         printf("Valor da aula:\n:>\t");
  131.         scanf("%f",((pd+x)->valor));
  132.         fflush(stdin);
  133.  
  134.         pa->numaula = &((pd+x)->regaula);
  135.         (pd+x)->qaluno+=1;
  136.     }
  137. }//matricula
  138.  
  139. int procurarAula(dance *pd, int tamD, char *mod, char *grau)
  140. {
  141.     int i;
  142.  
  143.     for(i=0; i<tamD; i++)
  144.     {
  145.         if((strcmp((pd+i)->modalidade, mod) == 0) && (strcmp((pd+i)->grau, grau) == 0))
  146.         {
  147.             if(((pd+i)->qaluno)<=20)
  148.                 return i;
  149.             else
  150.               return -2;
  151.         }
  152.     }
  153.     return -1;
  154. }//procura Aula
  155.  
  156. void montarClasse(dance *pd,int tamD)
  157. {
  158.     char mod[80], grau[2];
  159.     int taux;
  160.  
  161.     (pd)->modalidade=NULL;
  162.     (pd)->grau=NULL;
  163.  
  164.     system("cls");
  165.     printf("\n.:MONTAR CLASSE:.\n");
  166.  
  167.     printf("\nModalidade:\n:>\t");
  168.     gets(mod);
  169.     //maiuscula(mod);
  170.     fflush(stdin);
  171.  
  172.     taux = strlen(mod)+1;
  173.     alocaChar(&((pd)->modalidade),taux);
  174.     strcpy((pd)->modalidade,mod);
  175.  
  176.     printf("\nGrau:\n:>\t");
  177.     gets(grau);
  178.     fflush(stdin);
  179.  
  180.     taux = strlen(grau)+1;
  181.     alocaChar(&((pd)->grau),taux);
  182.     strcpy(((pd)->grau),grau);
  183.  
  184.     printf("\nValor Aula:\n:>\t");
  185.     scanf("%f", &((pd)->valor));
  186.     fflush(stdin);
  187.  
  188.     ((pd)->qaluno) = 0;
  189.     ((pd)->regaula) = tamD+1;
  190. }//Montar Classe
  191.  
  192. void buscarModalidade(aluno *pa, dance *pd, int tamA, int tamD)
  193. {
  194.     char mod[80], grau[2];
  195.     int x, i,j=0;
  196.  
  197.     system("cls");
  198.     printf("\n.:BUSCAR MODALIDADE:.\n");
  199.  
  200.     printf("\nModalidade:\n:>\t");
  201.     gets(mod);
  202.     maiuscula(mod);
  203.     fflush(stdin);
  204.  
  205.     printf("\nGrau:\n:>\t");
  206.     gets(grau);
  207.     fflush(stdin);
  208.  
  209.     x = procurarAula(pd,tamD,mod,grau);
  210.  
  211.     if(x != -1)
  212.     {
  213.         printf("\n<RESULTADO DA PESQUISA>\n");
  214.  
  215.         printf("\nRegistro da Aula: [ %i ]\n", (pd+x)->regaula);
  216.         printf("\nQuantidade de Alunos Matrículados: [ %i ]\n", (pd+x)->qaluno);
  217.         printf("Valor da Aula: [ R$ %.2f ]\n", (pd+x)->valor);
  218.  
  219.         printf("\n<LISTA DE ALUNOS MATRÍCULADOS>\n");
  220.         for(i=0; i<20; i++)
  221.         {
  222.             if((*(pa+i)->numaula)==((pd+x)->regaula))
  223.             {
  224.                 printf("\n[ %i ]\nNome:>\t%s\nCPF:>\t%s\n",++j , (pa+i)->CPF, (pa+i)->nome);
  225.             }
  226.         }
  227.     }
  228.     else if(x == -1)
  229.     {
  230.         printf("\nAula Inexistente!");
  231.         system("pause");
  232.     }
  233. }//Buscar Modalidade
  234.  
  235. void buscarAluno(aluno *pa, dance *pd, int tamA, int tamD)
  236. {
  237.     char CPF[13];
  238.     int i, j, aux;
  239.     float total=0;
  240.  
  241.     system("cls");
  242.     printf("\n.:BUSCAR ALUNO:.\n");
  243.     printf("\nDigite o CPF do aluno:\n:>\t");
  244.     gets(CPF);
  245.     fflush(stdin);
  246.  
  247.     for(i=0; i<tamA; i++)
  248.     {
  249.         if(strcmp(((pa+i)->CPF),CPF)==0)
  250.         {
  251.             printf("\nNome do Aluno:> %s\n", (pa+i)->nome);
  252.  
  253.             aux = *(pa+i)->numaula;
  254.             printf("\n<AULAS CURSADAS PELO ALUNO>\n");
  255.  
  256.             for(j=0; j<tamD; j++)
  257.             {
  258.                 if(aux==(pd+j)->regaula)
  259.                 {
  260.                     printf("\nModalidade:> %s\n", (pd+j)->modalidade);
  261.                     printf("\nGrau:> %s\n", (pd+j)->grau);
  262.  
  263.                     total+=(pd+j)->valor;
  264.                 }
  265.             }//for j
  266.         }
  267.     }//for i
  268.  
  269.     printf("\nValor Total:> R$ %.2f\n", total);
  270.     system("pause");
  271.  
  272. }// buscar aluno
  273.  
  274. void encerrarMatricula(aluno *pa, dance *pd, int tamA, int tamD)
  275. {
  276.     char CPF[13];
  277.     int i;
  278.  
  279.     system("cls");
  280.     printf("\n.:ENCERRAR MATRÍCULA:.\n");
  281.  
  282.     printf("\nDigite o CPF do Aluno:\n:>\t\n");
  283.     gets(CPF);
  284.     fflush(stdin);
  285.  
  286.     for(i=0; i<tamA; i++)
  287.     {
  288.         if(strcmp(((pa+i)->CPF), CPF)==0)
  289.         {
  290.             if((*(pa+i)->numaula)==(pd+i)->regaula)
  291.             {
  292.                 ((pd+i)->qaluno)-=1;
  293.                 (pa+i)->numaula = NULL;
  294.             }
  295.         }
  296.     }
  297.  
  298.     printf("\nMATRÍCULA ENCERRADA COM SUCESSO!\n");
  299.     system("pause");
  300. }//encerra matricula
  301.  
  302. void encerrarAula(aluno *pa, dance *pd, int tamA, int tamD)
  303. {
  304.     int i, reg;
  305.  
  306.     system("cls");
  307.     printf("\n.:ENCERRAR CLASSE:.\n");
  308.  
  309.     printf("\nInforme o Registro da Aula:\n:>\t");
  310.     scanf("%i", &reg);
  311.  
  312.     for(i=0; i<tamD; i++)
  313.     {
  314.         if(((pd+i)->regaula)==reg)
  315.         {
  316.             (pd+i)->modalidade=NULL;
  317.         }
  318.     }
  319.  
  320.     for(i=0; i<tamA; i++)
  321.     {
  322.         if((*(pa+i)->numaula)==reg)
  323.         {
  324.             (pa+i)->numaula=NULL;
  325.         }
  326.     }
  327.     printf("\nCLASSE ENCERRADA COM SUCESSO!\n");
  328.     system("pause");
  329. }//encerra aula
  330.  
  331.  
  332.  
  333.  
  334. void alocaAluno(aluno **p,int tam)
  335. {
  336.     if((*p = (aluno*)realloc(*p,tam*sizeof(aluno)))==NULL)
  337.     {
  338.         printf("Erro de alocação ALUNO");
  339.         exit(1);
  340.     }
  341. }//aloca aluno
  342.  
  343. void alocaDance(dance **p, int tam)
  344. {
  345.  
  346.     if((*p = (dance*)realloc(*p,tam*sizeof(dance)))==NULL)
  347.     {
  348.         printf("Erro de alocação DANCE");
  349.         exit(1);
  350.     }
  351. }//aloca dance
  352.  
  353. void alocaChar(char **p,int tam)
  354. {
  355.     if((*p=(char*)realloc(*p,tam*sizeof(char)))==NULL)
  356.     {
  357.         printf("Erro de alocação MODALIDADE");
  358.         exit(1);
  359.     }
  360. }
  361.  
  362. void maiuscula(char *p)
  363. {
  364.     int i,tam;
  365.     tam=strlen(p);
  366.  
  367.     for(i=0; i<tam; i++)
  368.         if(*(p+i)>='a'&&*(p+i)<='z')
  369.             *(p+i)-=32;
  370. }//maiuscula
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement