Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAXNAME 41
- #define MAXSTUD 3
- struct grade {
- float test,test2,work,extra;
- };
- typedef struct stud {
- char matr[6],name[MAXNAME];
- struct grade grades;
- }stud;
- void inputStudents(stud students[]);
- void showAll(stud students[]);
- void showBestStud (stud students[]);
- float showBiggerMed (stud students[]);
- float medCalc(float test, float test2, float work, float extra);
- int main() {
- struct stud students[MAXSTUD];
- inputStudents(students);
- printf("Lista com todos os alunos :\n");
- showAll(students);
- printf("\n\nLista com os alunos cuja media excede 7.0 :\n");
- showBestStud(students);
- printf("\n\nMaior media : %f\n",showBiggerMed(students));
- return 0;
- }
- void inputStudents(stud students[]) {
- int i;
- for (i = 0; i < MAXSTUD; i++) {
- printf("Entre com a matricula do aluno :\n");
- gets(students[i].matr);
- printf("Entre com o nome do aluno :\n");
- gets(students[i].name);
- printf("Entre com as notas das provas :\n");
- scanf("%f %f",&students[i].grades.test,&students[i].grades.test2);
- printf("Entre com o valor do trabalho :\n");
- scanf("%f",&students[i].grades.work);
- printf("Entre com o ponto extra :\n");
- scanf("%f",&students[i].grades.extra);
- if (students[i].grades.test >10 || students[i].grades.test < 0 || students[i].grades.test2 > 10 || students[i].grades.test2 < 0) {
- printf("Nota(s) invalida(s)!\n");
- i--;
- }
- fflush(stdin);
- }
- }
- void showAll(stud students[]) {
- int i;
- for (i = 0; i < MAXSTUD; i++) {
- 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));
- }
- }
- void showBestStud (stud students[]) {
- int i;
- for (i = 0; i < MAXSTUD; i++) {
- if (medCalc(students[i].grades.test,students[i].grades.test2,students[i].grades.work,students[i].grades.extra) >= 7 )
- printf("Matricula :%s\nNome : %s\n\n",students[i].matr,students[i].name);
- }
- }
- float showBiggerMed (stud students[]) {
- int i;
- float bigger = 0;
- for (i = 0; i < MAXSTUD; i++)
- if (medCalc(students[i].grades.test,students[i].grades.test2,students[i].grades.work,students[i].grades.extra) > bigger)
- bigger = medCalc(students[i].grades.test,students[i].grades.test2,students[i].grades.work,students[i].grades.extra);
- return bigger;
- }
- float medCalc(float test, float test2, float work, float extra) {
- float med = (test + test2 + work + extra)/ 3;
- if (med > 10)
- return 10;
- else
- return med;
- }
Advertisement
Add Comment
Please, Sign In to add comment