FranciscoSoccol

Lista 07 - Exercicio 03

Aug 5th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX_ALUNOS 500
  4. #define TAM_NOME 50
  5.  
  6. struct TipoAluno {
  7.     char nome[TAM_NOME];
  8.     float media;
  9.     int faltas;
  10. };
  11. // protótipos das funções
  12. float solicitaNota();
  13. int solicitaFaltas();
  14. float calculaMedia(float nota1, float nota2, float pontos, int faltas);
  15. float bonusMedia(int faltas);
  16. void exibeAluno(struct TipoAluno alunos[], int i);
  17. void exibeTodosAlunos(struct TipoAluno alunos[], int qtde);
  18.  
  19. // programa principal com as chamadas das funções criadas
  20. int main() {
  21.     struct TipoAluno alunos[MAX_ALUNOS];
  22.     float nota1, nota2, pontos;
  23.     int i, faltas, qtde=0;
  24.  
  25.     for(i=0; i < MAX_ALUNOS; i++)
  26.         {
  27.             printf("\nEntre com o nome do aluno: ");
  28.             fflush(stdin);
  29.             gets(alunos[i].nome);
  30.             if(alunos[i].nome[0]==alunos[i].nome['\n'])
  31.                 break;
  32.             printf("Entre com a primeira nota (0 a 10): ");
  33.             nota1 = solicitaNota();
  34.             printf("Entre com a segunda nota (0 a 10): ");
  35.             nota2 = solicitaNota();
  36.             printf("Entre com os pontos (0 a 10): ");
  37.             pontos = solicitaNota();
  38.             faltas=solicitaFaltas();
  39.             alunos[i].faltas=faltas;
  40.             alunos[i].media = calculaMedia(nota1, nota2, pontos, faltas);
  41.             qtde++;
  42.         }
  43.     exibeTodosAlunos(alunos,qtde);
  44.     return 0;
  45. }
  46. //solicitando a nota
  47. float solicitaNota()
  48. {
  49.     float nota;
  50.     scanf("%f",&nota);
  51.     if(nota>=0 && nota<=10)
  52.         return nota;
  53.         else
  54.             return printf("Erro de nota!\n\n");
  55. }
  56.  
  57. //solicitando as faltas
  58. int solicitaFaltas()
  59. {
  60.     int faltas;
  61.     printf("Digite as faltas: ");
  62.     scanf("%d", &faltas);
  63.     return faltas;
  64. }
  65.  
  66. //calculando a media
  67. float calculaMedia(float nota1, float nota2, float pontos, int faltas)
  68. {
  69.     float media;
  70.     //calculando a media
  71.     if((nota1>=0 && nota1<=10) && (nota2>=0 && nota2<=10))//verifica se as notas sao validas
  72.         media=(nota1+nota2)/2+pontos+bonusMedia(faltas);
  73.         else
  74.             media=0;
  75.     return media;
  76. }
  77.  
  78. //bonus media
  79. float bonusMedia(int faltas)
  80. {
  81.     float aux=0.5, aux2=0;
  82.     if(faltas==0)//verificando
  83.         return aux;
  84.         else
  85.             return aux2;
  86. }
  87.  
  88. //exibe alunos
  89. void exibeAluno(struct TipoAluno alunos[], int i)
  90. {
  91.     printf("Nome: %s\n",alunos[i].nome);
  92.     printf("Media: %.2f\n",alunos[i].media);
  93.     printf("Faltas: %d\n\n",alunos[i].faltas);
  94. }
  95.  
  96. //exibe todos os alunos
  97. void exibeTodosAlunos(struct TipoAluno alunos[], int qtde)
  98. {
  99.     int i;
  100.     system("cls");
  101.     printf("Exibicao de todos os alunos:\n\n");
  102.     for(i=0;i<qtde;i++)
  103.         exibeAluno(alunos, i);
  104. }
Advertisement
Add Comment
Please, Sign In to add comment