Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct data{
- int dia, mes, ano;
- };
- struct aluno{
- struct data nascimento;
- int id;
- char nome[256];
- double notas[5][2], media[5];
- };
- void inserir(struct aluno c[], int *n);
- void remover(struct aluno c[], int *n);
- void alterar(struct aluno c[], int *n);
- void buscar(struct aluno c[], int *n);
- void mostrar_tudo(struct aluno c[], int n);
- void mostrar_data(struct aluno c[], int n);
- void mostrar_aprovados(struct aluno c[], int n);
- void mostrar_reprovados(struct aluno c[], int n);
- int main(){
- int opc;
- struct aluno c[10];
- int n = 0;
- do{
- printf("1. Inserir\n");
- printf("2. Remover\n");
- printf("3. Buscar\n");
- printf("4. Alterar\n");
- printf("5. Mostrar tudo\n");
- printf("6. Mostar por ano\n");
- printf("7. Mostrar alunos Aprovados\n");
- printf("0. Sair\n");
- scanf("%d", &opc);
- switch(opc){
- case 1:
- inserir(c, &n);
- break;
- case 2:
- remover(c, &n);
- break;
- case 3:
- buscar(c, &n);
- break;
- case 4:
- alterar(c, &n);
- break;
- case 5:
- mostrar_tudo(c, n);
- break;
- case 6:
- mostrar_data(c, n);
- break;
- case 7:
- mostrar_aprovados(c, n);
- break;
- case 8:
- mostrar_reprovados(c, n);
- case 0:
- return 0;
- }
- }while(opc != 0);
- return 0;
- }
- void inserir(struct aluno c[], int *n){
- int i, j, id;
- printf("Insira os dados do aluno.\n");
- printf("Codigo: ");
- scanf("%d", &id);
- for(i = 0; i < *n; i++){
- if(id == c[i].id){
- printf("Codigo ja cadastrado.\n");
- return;
- }
- }
- c[*n].id = id;
- printf("Nome: ");
- getchar();
- gets(c[*n].nome);
- getchar();
- printf("Data de nascimento (dd/mm/aaaa): ");
- scanf("%d/%d/%d", c[*n].nascimento.dia, c[*n].nascimento.mes, c[*n].nascimento.ano);
- for(i = 0; i < 5; i++){
- printf("Notas da disciplina %d:\n", i+1);
- for(j = 0; j < 2; j++){
- printf("Nota %d: ", j+1);
- scanf("%lf", c[*n].notas[i][j]);
- }
- }
- *n = *n + 1;
- for(i = 0; i < 5; i++){
- c[*n].media[i] = (c[*n].notas[i][0] + c[*n].notas[i][1])/2;
- }
- printf("Inserido com sucesso.\n");
- return;
- }
- void buscar(struct aluno c[], int *n){
- int id, achou = 0, i, j, k;
- printf("Insira o codigo para busca: ");
- scanf("%d", &id);
- for(i = 0; i < *n; i++){
- if(id == c[i].id){
- achou = 1;
- printf("Nome: %s\n", c[i].nome);
- printf("Data de nascimento: %d/%d/%d\n", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
- printf("Notas:\n");
- for(j = 0; j < 5; j++){
- printf("Notas da disciplina %d:", j+1);
- for(k = 0; k < 2; k++){
- printf(" %.1lf", c[i].notas[j][k]);
- }
- printf("\n");
- }
- }
- }
- if(achou == 0){
- printf("Nao encontrado.\n");
- }
- return;
- }
- void alterar(struct aluno c[], int *n){
- int id, i, j, k, achou = 0,cod;
- printf("Insira o codigo do aluno:");
- scanf("%d", &cod);
- for(i = 0; i < *n; i++){
- if(id == c[i].id){
- achou = 1;
- printf("Insira o novo nome: ");
- getchar();
- gets(c[i].nome);
- getchar();
- printf("Insira a nova data de nascimento (dd/mm/aaaa):");
- scanf("%d/%d/%d", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
- printf("Insira as novas notas:");
- for(j = 0; j < 5; j++){
- printf("Notas da disciplina %d:\n", j+1);
- for(k = 0; k < 2; k++){
- printf("Nota %d: ", k+1);
- scanf("%lf", c[i].notas[i][j]);
- }
- }
- }
- }
- if(achou == 0){
- printf("Nao encontrado.");
- }
- return;
- }
- void remover(struct aluno c[], int *n){
- int id, i, j, achou = 0;
- printf("Insira o codigo:");
- scanf("%d", &id);
- for(int i = 0; i < *n; i++){
- if(id == c[i].id){
- achou = 1;
- for(j = i+1; j < *n; j++){
- c[j-1] = c[j];
- }
- printf("Excluido com sucesso.\n");
- *n = *n - 1;
- }
- }
- if(achou == 0){
- printf("Nao encontrado.\n");
- }
- return;
- }
- void mostrar_tudo(struct aluno c[], int n){
- int i, j, k;
- for(i = 0; i < n; i++){
- printf("Codigo: %d\n", c[i].id);
- printf("Nome: %s\n", c[i].nome);
- printf("Data de nascimento: %d/%d/%d\n", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
- printf("Notas:");
- for(j = 0; j < 5; j++){
- printf("Notas da disciplina %d:", j+1);
- for(k = 0; k < 2; k++){
- printf(" %lf", c[i].notas[j][k]);
- }
- printf("\n");
- printf("Media da disciplina %d: %.1lf",j+1,c[i].media[j]);
- printf("\n");
- }
- }
- return;
- }
- void mostrar_data(struct aluno c[], int n){
- int i,j,ano,k;
- printf("Ano: %d\n",&ano);
- for(i = 0; i < n; i++){
- if(ano == c[i].nascimento.ano){
- printf("Codigo: %d\n", c[i].id);
- printf("Nome: %s\n", c[i].nome);
- printf("Data de nascimento: %d/%d/%d\n", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
- printf("Notas:");
- for(j = 0; j < 5; j++){
- printf("Notas da disciplina %d:", j+1);
- for(k = 0; k < 2; k++){
- printf(" %.1lf", c[i].notas[j][k]);
- }
- printf("\n");
- printf("Media da disciplina %d: %.1lf",j+1,c[i].media[j]);
- printf("\n");
- }
- }
- }
- }
- void mostrar_aprovados(struct aluno c[], int n){
- int i,j,k,cont = 0;
- for(i = 0; i < n; i++){
- for(j = 0; j < 5; j++){
- if(c[i].media[j] < 6,0){
- cont++;
- }
- }
- if(cont == 0){
- printf("Codigo: %d\n", c[i].id);
- printf("Nome: %s\n", c[i].nome);
- printf("Data de nascimento: %d/%d/%d\n", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
- printf("Notas:");
- for(j = 0; j < 5; j++){
- printf("Notas da disciplina %d:", j+1);
- for(k = 0; k < 2; k++){
- printf(" %.1lf", c[i].notas[j][k]);
- }
- printf("\n");
- printf("Media da disciplina %d: %.1lf",j+1,c[i].media[j]);
- printf("\n");
- }
- }
- }
- }
- void mostrar_reprovados(struct aluno c[], int n){
- int i,j,k,cont = 0;
- for(i = 0; i < n; i++){
- for(j = 0; j < 5; j++){
- if(c[i].media[j] < 6,0){
- cont++;
- }
- }
- if(cont > 0){
- printf("Codigo: %d\n", c[i].id);
- printf("Nome: %s\n", c[i].nome);
- printf("Data de nascimento: %d/%d/%d\n", c[i].nascimento.dia, c[i].nascimento.mes, c[i].nascimento.ano);
- printf("Notas:");
- for(j = 0; j < 5; j++){
- printf("Notas da disciplina %d:", j+1);
- for(k = 0; k < 2; k++){
- printf(" %.1lf", c[i].notas[j][k]);
- }
- printf("\n");
- printf("Media da disciplina %d: %.1lf",j+1,c[i].media[j]);
- printf("\n");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement