Guest User

Untitled

a guest
Jan 20th, 2011
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4.  
  5. struct aluno
  6. {
  7.    char nome[81];
  8.    char matricula[8];
  9.    char turma;
  10.    float p1;
  11.    float p2;
  12.    float p3;
  13.    
  14. };
  15.  
  16. typedef struct aluno Aluno;
  17.  
  18. #define MAX 100
  19. Aluno* turmas[MAX];
  20.  
  21. void inicializa (int n, Aluno** turmas) /*funçãos para imprimir os aprovados*/
  22. {
  23. int i;
  24. for (i=0; i<n; i++)
  25. turmas[i] = NULL;
  26. }
  27.  
  28. void preenche (int n, Aluno** turmas, int i)
  29. {
  30.      
  31.      if (i<0 || i>=n) {
  32.      printf("Indice fora do limite do vetor\n");
  33.      exit(1);
  34.      }
  35.      
  36.      if (turmas[i]==NULL)
  37.      turmas[i] = (Aluno*)malloc(sizeof(Aluno));
  38.      
  39.      printf("Entre com o nome");
  40.      scanf("%80[^\n]", &turmas[i]->nome);
  41.      printf("Entre com a matricula");
  42.      scanf("%c", &turmas[i]->matricula);
  43.      printf("Entre com a turma");
  44.      scanf("%120[^\n]", &turmas[i]->turma);
  45.      printf("Entre com a primeira nota");
  46.      scanf("%f", &turmas[i]->p1);
  47.      printf("Entre com a segunda nota");
  48.      scanf("%f", &turmas[i]->p2);
  49.      printf("Entre com a terceira nota");
  50.      scanf("%f", &turmas[i]->p3);
  51.      
  52. }
  53.  
  54. void imprime (int n, Aluno** turmas, int i)
  55. {
  56.    
  57.      if (i<0 || i>=n) {
  58.      printf("Indice fora do limite do vetor\n");
  59.      exit(1);
  60.      }
  61.      
  62.      if (turmas[i]!=NULL)
  63.     {
  64.     printf("\n\nMatricula: %d\n", turmas[i]->matricula);
  65.     printf("\n\nNome: %s\n", turmas[i]->nome);
  66.     printf("\n\nTurma: %s\n", turmas[i]->turma);
  67.   printf("\n\n");
  68.     }
  69. }    
  70.      
  71.  
  72. void imprime_aprovados (int n, Aluno** turmas)
  73. {
  74.  
  75. int i;
  76. float media;
  77. float p1,p2,p3;
  78.  
  79. media = (p1+p2+p3)/3;
  80.  
  81. for (i=0; i<n; i++)
  82.  
  83. {
  84.  
  85. if (media>6.0)
  86.  {
  87.  imprime(n,turmas,i);    
  88.  }  
  89. }
  90.    
  91. }
  92.      
  93. /*programa principal*/
  94. main(){
  95.        
  96.        Aluno* turmas[10];
  97.        preenche(10,turmas,0);
  98.        preenche(10,turmas,1);
  99.        preenche(10,turmas,1);
  100.        imprime_aprovados(10,turmas);
  101.        getch();
  102.        
  103. }
Advertisement
Add Comment
Please, Sign In to add comment