nikolas_serafini

Lista 7 - Exercício 7

Aug 10th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAXNAME 41
  3. #define MAXSTUD 3
  4.  
  5. struct grade {
  6.     float test,test2,work,extra;
  7. };
  8.  
  9. typedef struct stud {
  10.     char matr[6],name[MAXNAME];
  11.     struct grade grades;
  12. }stud;
  13.  
  14. void inputStudents(stud students[]);
  15. void showAll(stud students[]);
  16. void showBestStud (stud students[]);
  17. float showBiggerMed (stud students[]);
  18. float medCalc(float test, float test2, float work, float extra);
  19.  
  20. int main() {
  21.    
  22.     struct stud students[MAXSTUD];
  23.  
  24.     inputStudents(students);
  25.     printf("Lista com todos os alunos :\n");
  26.     showAll(students);
  27.     printf("\n\nLista com os alunos cuja media excede 7.0 :\n");
  28.     showBestStud(students);
  29.     printf("\n\nMaior media : %f\n",showBiggerMed(students));
  30.  
  31.     return 0;
  32. }
  33.  
  34. void inputStudents(stud students[]) {
  35.     int i;
  36.  
  37.     for (i = 0; i < MAXSTUD; i++) {
  38.         printf("Entre com a matricula do aluno :\n");
  39.         gets(students[i].matr);
  40.         printf("Entre com o nome do aluno :\n");
  41.         gets(students[i].name);
  42.         printf("Entre com as notas das provas :\n");
  43.         scanf("%f %f",&students[i].grades.test,&students[i].grades.test2);
  44.         printf("Entre com o valor do trabalho :\n");
  45.         scanf("%f",&students[i].grades.work);
  46.         printf("Entre com o ponto extra :\n");
  47.         scanf("%f",&students[i].grades.extra);
  48.  
  49.         if (students[i].grades.test >10 || students[i].grades.test < 0 || students[i].grades.test2 > 10 || students[i].grades.test2 < 0) {
  50.             printf("Nota(s) invalida(s)!\n");
  51.             i--;
  52.         }
  53.         fflush(stdin);
  54.     }
  55. }
  56.  
  57. void showAll(stud students[]) {
  58.     int i;
  59.  
  60.     for (i = 0; i < MAXSTUD; i++) {
  61.         printf("Matricula :%s\nNome : %s\nMedia : %f\n\n",students[i].matr,students[i].name,medCalc(students[i].grades.test,students[i].grades.test2,students[i].grades.work,students[i].grades.extra));
  62.     }
  63. }
  64.  
  65. void showBestStud (stud students[]) {
  66.     int i;
  67.  
  68.     for (i = 0; i < MAXSTUD; i++) {
  69.         if (medCalc(students[i].grades.test,students[i].grades.test2,students[i].grades.work,students[i].grades.extra) >= 7 )
  70.             printf("Matricula :%s\nNome : %s\n\n",students[i].matr,students[i].name);
  71.  
  72.     }
  73. }
  74.  
  75. float showBiggerMed (stud students[]) {
  76.     int i;
  77.     float bigger = 0;
  78.  
  79.     for (i = 0; i < MAXSTUD; i++)
  80.         if (medCalc(students[i].grades.test,students[i].grades.test2,students[i].grades.work,students[i].grades.extra) > bigger)
  81.             bigger = medCalc(students[i].grades.test,students[i].grades.test2,students[i].grades.work,students[i].grades.extra);
  82.  
  83.     return bigger;
  84. }
  85.  
  86. float medCalc(float test, float test2, float work, float extra) {
  87.     float med = (test + test2 + work + extra)/ 3;
  88.  
  89.     if (med > 10)
  90.         return 10;
  91.     else
  92.         return med;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment