Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <locale.h>
- typedef struct aluno
- {
- char CPF[15]; //CPF do aluno
- char nome[80]; //nome do aluno
- int *numaula; //aponta p/o registro da aula
- } aluno;
- typedef struct dance
- {
- int regaula; //registro gerado automaticamente
- int qaluno; //registra a quantidade de alunos matriculados
- char *modalidade; //exemplo: ballet, tap americano, jazz, street
- char *grau; //exemplo: iniciante, intermediário, avançado
- float valor; //valor da aula
- } dance;
- //ALOCAÇÕES
- void alocaAluno(aluno **p,int tam);
- void alocaDance(dance **p, int tam);
- void alocaChar(char **p,int tam);
- //OPERAÇÕES MENU
- void matricular(aluno *pa, dance *pd, int tamD);
- void montarClasse(dance *pd,int tamD);
- void buscarModalidade(aluno *pa, dance *pd, int tamA, int tamD);
- void buscarAluno(aluno *pa, dance *pd, int tamA, int tamD);
- void encerrarMatricula(aluno *pa, dance *pd, int tamA, int tamD);
- void encerrarAula(aluno *pa, dance *pd, int tamA, int tamD);
- //VERIFICAÇÕES
- int procurarAula(dance *pd, int tamD, char *mod, char *grau);
- //OUTRAS
- void maiuscula(char *p);
- main()
- {
- setlocale(LC_ALL,"");
- aluno *pa=NULL;
- dance *pd=NULL;
- int tamA=0,tamD=0;
- char op;
- do
- {
- system("cls");
- printf("\n.:MENU:.\n");
- 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:> ");
- scanf("%i", &op);
- fflush(stdin);
- switch(op)
- {
- case 1:
- alocaAluno(&pa,tamA+1);
- matricular(pa+tamA,pd,tamD);
- tamA++;
- break;
- case 2:
- alocaDance(&pd,tamD+1);
- montarClasse(pd+tamD,tamD);
- tamD++;
- break;
- case 3:
- buscarModalidade(pa, pd, tamA, tamD);
- break;
- case 4:
- buscarAluno(pa, pd, tamA, tamD);
- break;
- case 5:
- encerrarMatricula(pa,pd,tamA,tamD);
- break;
- case 6:
- encerrarAula(pa,pd,tamA,tamD);
- break;
- }//switch
- }
- while(op!= 7);
- }//main
- void matricular(aluno *pa, dance *pd, int tamD)
- {
- char mod[80],grau[2];
- int x;
- system("cls");
- printf("\n.:MATRÍCULA:.\n");
- printf("\nNome:\n:>\t");
- gets(pa->nome);
- fflush(stdin);
- printf("\nCPF:\n:>\t");
- gets(pa->CPF);
- fflush(stdin);
- printf("\nInforme a Modalidade que deseja cursar:\n:>\t");
- gets(mod);
- //maiuscula(mod);
- fflush(stdin);
- printf("\nQual o grau do curso <0 - Iniciante / 1 - Intermediário / 2 - Avançado>:\n:>\t");
- gets(grau);
- fflush(stdin);
- x = procurarAula(pd,tamD,mod,grau);
- if(x == -1)
- {
- printf("\nAula Indisponível!\n");
- system("pause");
- }
- else if(x == -2)
- {
- printf("\nAula Cheia!\n");
- system("pause");
- }
- else
- {
- printf("Valor da aula:\n:>\t");
- scanf("%f",((pd+x)->valor));
- fflush(stdin);
- pa->numaula = &((pd+x)->regaula);
- (pd+x)->qaluno+=1;
- }
- }//matricula
- int procurarAula(dance *pd, int tamD, char *mod, char *grau)
- {
- int i;
- for(i=0; i<tamD; i++)
- {
- if((strcmp((pd+i)->modalidade, mod) == 0) && (strcmp((pd+i)->grau, grau) == 0))
- {
- if(((pd+i)->qaluno)<=20)
- return i;
- else
- return -2;
- }
- }
- return -1;
- }//procura Aula
- void montarClasse(dance *pd,int tamD)
- {
- char mod[80], grau[2];
- int taux;
- (pd)->modalidade=NULL;
- (pd)->grau=NULL;
- system("cls");
- printf("\n.:MONTAR CLASSE:.\n");
- printf("\nModalidade:\n:>\t");
- gets(mod);
- //maiuscula(mod);
- fflush(stdin);
- taux = strlen(mod)+1;
- alocaChar(&((pd)->modalidade),taux);
- strcpy((pd)->modalidade,mod);
- printf("\nGrau:\n:>\t");
- gets(grau);
- fflush(stdin);
- taux = strlen(grau)+1;
- alocaChar(&((pd)->grau),taux);
- strcpy(((pd)->grau),grau);
- printf("\nValor Aula:\n:>\t");
- scanf("%f", &((pd)->valor));
- fflush(stdin);
- ((pd)->qaluno) = 0;
- ((pd)->regaula) = tamD+1;
- }//Montar Classe
- void buscarModalidade(aluno *pa, dance *pd, int tamA, int tamD)
- {
- char mod[80], grau[2];
- int x, i,j=0;
- system("cls");
- printf("\n.:BUSCAR MODALIDADE:.\n");
- printf("\nModalidade:\n:>\t");
- gets(mod);
- maiuscula(mod);
- fflush(stdin);
- printf("\nGrau:\n:>\t");
- gets(grau);
- fflush(stdin);
- x = procurarAula(pd,tamD,mod,grau);
- if(x != -1)
- {
- printf("\n<RESULTADO DA PESQUISA>\n");
- printf("\nRegistro da Aula: [ %i ]\n", (pd+x)->regaula);
- printf("\nQuantidade de Alunos Matrículados: [ %i ]\n", (pd+x)->qaluno);
- printf("Valor da Aula: [ R$ %.2f ]\n", (pd+x)->valor);
- printf("\n<LISTA DE ALUNOS MATRÍCULADOS>\n");
- for(i=0; i<20; i++)
- {
- if((*(pa+i)->numaula)==((pd+x)->regaula))
- {
- printf("\n[ %i ]\nNome:>\t%s\nCPF:>\t%s\n",++j , (pa+i)->CPF, (pa+i)->nome);
- }
- }
- }
- else if(x == -1)
- {
- printf("\nAula Inexistente!");
- system("pause");
- }
- }//Buscar Modalidade
- void buscarAluno(aluno *pa, dance *pd, int tamA, int tamD)
- {
- char CPF[13];
- int i, j, aux;
- float total=0;
- system("cls");
- printf("\n.:BUSCAR ALUNO:.\n");
- printf("\nDigite o CPF do aluno:\n:>\t");
- gets(CPF);
- fflush(stdin);
- for(i=0; i<tamA; i++)
- {
- if(strcmp(((pa+i)->CPF),CPF)==0)
- {
- printf("\nNome do Aluno:> %s\n", (pa+i)->nome);
- aux = *(pa+i)->numaula;
- printf("\n<AULAS CURSADAS PELO ALUNO>\n");
- for(j=0; j<tamD; j++)
- {
- if(aux==(pd+j)->regaula)
- {
- printf("\nModalidade:> %s\n", (pd+j)->modalidade);
- printf("\nGrau:> %s\n", (pd+j)->grau);
- total+=(pd+j)->valor;
- }
- }//for j
- }
- }//for i
- printf("\nValor Total:> R$ %.2f\n", total);
- system("pause");
- }// buscar aluno
- void encerrarMatricula(aluno *pa, dance *pd, int tamA, int tamD)
- {
- char CPF[13];
- int i;
- system("cls");
- printf("\n.:ENCERRAR MATRÍCULA:.\n");
- printf("\nDigite o CPF do Aluno:\n:>\t\n");
- gets(CPF);
- fflush(stdin);
- for(i=0; i<tamA; i++)
- {
- if(strcmp(((pa+i)->CPF), CPF)==0)
- {
- if((*(pa+i)->numaula)==(pd+i)->regaula)
- {
- ((pd+i)->qaluno)-=1;
- (pa+i)->numaula = NULL;
- }
- }
- }
- printf("\nMATRÍCULA ENCERRADA COM SUCESSO!\n");
- system("pause");
- }//encerra matricula
- void encerrarAula(aluno *pa, dance *pd, int tamA, int tamD)
- {
- int i, reg;
- system("cls");
- printf("\n.:ENCERRAR CLASSE:.\n");
- printf("\nInforme o Registro da Aula:\n:>\t");
- scanf("%i", ®);
- for(i=0; i<tamD; i++)
- {
- if(((pd+i)->regaula)==reg)
- {
- (pd+i)->modalidade=NULL;
- }
- }
- for(i=0; i<tamA; i++)
- {
- if((*(pa+i)->numaula)==reg)
- {
- (pa+i)->numaula=NULL;
- }
- }
- printf("\nCLASSE ENCERRADA COM SUCESSO!\n");
- system("pause");
- }//encerra aula
- void alocaAluno(aluno **p,int tam)
- {
- if((*p = (aluno*)realloc(*p,tam*sizeof(aluno)))==NULL)
- {
- printf("Erro de alocação ALUNO");
- exit(1);
- }
- }//aloca aluno
- void alocaDance(dance **p, int tam)
- {
- if((*p = (dance*)realloc(*p,tam*sizeof(dance)))==NULL)
- {
- printf("Erro de alocação DANCE");
- exit(1);
- }
- }//aloca dance
- void alocaChar(char **p,int tam)
- {
- if((*p=(char*)realloc(*p,tam*sizeof(char)))==NULL)
- {
- printf("Erro de alocação MODALIDADE");
- exit(1);
- }
- }
- void maiuscula(char *p)
- {
- int i,tam;
- tam=strlen(p);
- for(i=0; i<tam; i++)
- if(*(p+i)>='a'&&*(p+i)<='z')
- *(p+i)-=32;
- }//maiuscula
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement