Guest User

Untitled

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