Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.14 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #define MAX_ALUNOS 1
  4.  
  5. struct TipoAluno
  6. {
  7.        char nome[30];
  8.        float media;
  9.        int faltas;
  10. };
  11.  
  12. float solicitaNota(void);
  13. float calculaMedia(float nota1, float nota2, float pontos, int faltas);
  14. float bonusMedia(int faltas);
  15. void exibeAluno(struct TipoAluno aluno);
  16. void fim(void);
  17.  
  18.  
  19. int main(void)
  20. {  
  21.       struct TipoAluno alunos[MAX_ALUNOS];
  22.       float nota1, nota2, pontos;
  23.       int i, faltas;
  24.       for(i=0; i < MAX_ALUNOS; i++)
  25.       {
  26.             printf("\nEntre com o nome do aluno: ");
  27.             gets(alunos[i].nome);
  28.             printf("Entre com a primeira nota (0 a 10): ");
  29.             nota1 = solicitaNota();
  30.             printf("Entre com a segunda nota (0 a 10): ");
  31.             nota2 = solicitaNota();
  32.             printf("Entre com os pontos (0 a 10): ");
  33.             pontos = solicitaNota();
  34.             printf("Entre com as faltas: ");
  35.             scanf("%d", &faltas);
  36.             getchar();
  37.             alunos[i].media = calculaMedia(nota1, nota2, pontos, faltas);
  38.       }
  39.       printf("\n\nExibicao dos dados:");
  40.       for(i=0; i < MAX_ALUNOS; i++)
  41.             exibeAluno(alunos[i]);  
  42.  
  43.       fim();
  44. }        
  45. //FUNCÕES
  46.  
  47. float solicitaNota(void)
  48. {
  49.      
  50.       float nota;
  51.       do
  52.       {
  53.             scanf("%f", &nota);
  54.             if(nota < 0 || nota > 10)
  55.             {
  56.                   printf("Erro, valor deve ser de 0 a 10 \n");
  57.             }
  58.       }while(nota < 0 || nota > 10);
  59.        
  60.       return nota;
  61. }
  62.  
  63. float bonusMedia(int faltas)
  64. {
  65.     if (faltas==0)
  66.         return 0.5;            
  67.     else
  68.     return 0;
  69. }    
  70.  
  71. float calculaMedia(float nota1, float nota2, float pontos, int faltas)
  72. {      
  73.       float media = (nota1 + nota2)/2 + pontos + bonusMedia(faltas);
  74.      
  75.      
  76.       if(media > 10)
  77.             return 10;
  78.            
  79.            
  80.       else
  81.             return media;
  82. }  
  83.    
  84.  
  85. void exibeAluno(struct TipoAluno aluno)
  86. {
  87.       printf("\n\nAluno: %s", aluno.nome);
  88.       printf("\nMedia: %.2f", aluno.media);    
  89. }
  90.  
  91.  
  92. void fim(void)
  93. {
  94.       printf("\n\n\n");
  95.       system("pause");
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement