Modify part 2 by using both modules and functions appropriately. You also need t
ID: 3702199 • Letter: M
Question
Modify part 2 by using both modules and functions appropriately. You also need to validate the user’s input. The scores have to be numeric and between 0 and 100. Use Pseudocode!
Project Part 2:
// main module
Module main()
// Local variables
Declare total homework, total exam, total quiz, total discussion, total project, final score, letter grade
#include<stdio.h>
//calculate total homework score
real homework_total()
{
real hw[8],hw14,total=0;
int i;
printf(" Enter marks in homeworks(total 100 points): ");
for(i=0;i<8;i++)
{
printf(" Home work %d: ",i+1);
scanf("%f",&hw[i]);
total=total+hw[i];
}
printf(" Home work 14: ");
scanf("%f",&hw14);
total=total+hw14;
return(total/9 );
}
//calculate total exam score
real exam_score()
{
real ex[4],total=0;
int i;
printf(" Enter marks in Exam(total 100 points): ");
for(i=0;i<4;i++)
{
printf(" Exam %d: ",i+1);
scanf("%f",&ex[i]);
total=total+ex[i];
}
return(total/4);;
}
//calculate total quiz score
real quiz_total()
{
real qz[8],qz14,total=0;
int i;
printf(" Enter marks in Quiz(total 100 points): ");
for(i=0;i<8;i++)
{
printf(" Quiz %d: ",i+1);
scanf("%f",&qz[i]);
total=total+qz[i];
}
printf(" Quiz 14: ");
scanf("%f",&qz);
total=total+qz14;
return(total/9);
}
//calculate total discussio score
real discussion_total()
{
real diss[4],total=0;
int i;
printf(" Enter marks in Discussion(total 100 points): ");
for(i=0;i<4;i++)
{
printf(" Discussion %d: ",i+1);
scanf("%f",&diss[i]);
total=total+diss[i];
}
return(total/4);;
}
//calculate total roject score
real project_total()
{
real pro[6],total=0;
int i;
printf(" Enter marks in Project(total 100 points): ");
for(i=0;i<6;i++)
{
printf(" Quiz %d: ",i+1);
scanf("%f",&pro[i]);
total=total+pro[i];
}
return(total/6);
}
//calculate total final score in percentage
real final_score(real hw,real proj,real quiz,real diss,real exam)
{
real final;
final=(hw*.15)+(proj*.15)+(quiz*.05)+(diss*.05)+(exam*.6);
return(final);
}
//returns letter grade
char letter_grade(real score)
{
char grade;
If(score>=90 && score <=100)
grade='A';
Else If(score>=80 && score <=90)
grade='B';
Else If(score>=70 && score <=80)
grade='C';
Else If(score>=60 && score <=70)
grade='D';
Else If(score>=50 && score <=60)
grade='F';
End If
printf(" Final score: %.2f Grade=%c ",score,grade);
}
int main()
{
real homework,project,quiz,discussion,exam,total;
hw=homework_total();
pro=project_total();
qz=quiz_total();
diss=discussion_total();
exam=exam_score();
total=final_score(hw,pro,qz,diss,exam);
letter_grade(total);
}
End Module
Grading Rubric Correct variable declarations Correct declaration of constants Correct module/function declarations and endings15 Correct arguments in module/function call15 Correct parameters in module/function declaration 15 Correct parameter variable scope (value/reference)15 Correct calculations Code properly indented Correct input validation Points Score 10 10 5 5 10 Tota 100Explanation / Answer
// main module
// Local variables Declare total homework, total exam, total quiz, total discussion, total project, final score, grade
#include<stdio.h>
//calculate total homework score
float homework_total()
{
float hw[8],hw14,total=0;
int i;
printf(" Enter marks in homeworks(total 100 points): ");
for(i=0;i<8;i++)
{
printf(" Home work %d: ",i+1);
scanf("%f",&hw[i]);
total=total+hw[i];
}
printf(" Home work 14: ");
scanf("%f",&hw14);
total=total+hw14;
return(total/9 );
}
//calculate total exam score
float exam_score()
{
float ex[4],total=0;
int i;
printf(" Enter marks in Exam(total 100 points): ");
for(i=0;i<4;i++)
{
printf(" Exam %d: ",i+1);
scanf("%f",&ex[i]);
total=total+ex[i];
}
return(total/4);;
}
//calculate total quiz score
float quiz_total()
{
float qz[8],qz14,total=0;
int i;
printf(" Enter marks in Quiz(total 100 points): ");
for(i=0;i<8;i++)
{
printf(" Quiz %d: ",i+1);
scanf("%f",&qz[i]);
total=total+qz[i];
}
printf(" Quiz 14: ");
scanf("%f",&qz);
total=total+qz14;
return(total/9);
}
//calculate total discussio score
float discussion_total()
{
float diss[4],total=0;
int i;
printf(" Enter marks in Discussion(total 100 points): ");
for(i=0;i<4;i++)
{
printf(" Discussion %d: ",i+1);
scanf("%f",&diss[i]);
total=total+diss[i];
}
return(total/4);;
}
//calculate total roject score
float project_total()
{
float pro[6],total=0;
int i;
printf(" Enter marks in Project(total 100 points): ");
for(i=0;i<6;i++)
{
printf(" Quiz %d: ",i+1);
scanf("%f",&pro[i]);
total=total+pro[i];
}
return(total/6);
}
//calculate total final score in percentage
float final_score(float hw,float proj,float quiz,float diss,float exam)
{
float final;
final=(hw*.15)+(proj*.15)+(quiz*.05)+(diss*.05)+(exam*.6);
return(final);
}
//returns letter grade
char letter_grade(float score)
{
char grade;
if(score>=90 && score <=100)
grade='A';
else if(score>=80 && score <=90)
grade='B';
else if(score>=70 && score <=80)
grade='C';
else if(score>=60 && score <=70)
grade='D';
else if(score>=50 && score <=60)
grade='F';
printf(" Final score: %.2f Grade=%c ",score,grade);
}
int main()
{
float hw,pro,qz,diss,exam,total;
hw=homework_total();
pro=project_total();
qz=quiz_total();
diss=discussion_total();
exam=exam_score();
total=final_score(hw,pro,qz,diss,exam);
letter_grade(total);
}
Sample Output :
Enter marks in homeworks(total 100 points):
Home work 1: 7
Home work 2:
7
Home work 3: 90
Home work 4: 89
Home work 5: 78
Home work 6: 67
Home work 7: 56
Home work 8: 67
Home work 14: 89
Enter marks in Project(total 100 points):
Quiz 1: 34
Quiz 2: 56
Quiz 3: 78
Quiz 4: 90
Quiz 5: 98
Quiz 6: 78
Enter marks in Quiz(total 100 points):
Quiz 1: 67
Quiz 2: 45
Quiz 3: 56
Quiz 4: 67
Quiz 5: 78
Quiz 6: 56
Quiz 7: 45
Quiz 8: 67
Quiz 14: 78
Enter marks in Discussion(total 100 points):
Discussion 1: 88
Discussion 2: 56
Discussion 3: 67
Discussion 4: 44
Enter marks in Exam(total 100 points):
Exam 1: 55
Exam 2: 55
Exam 3: 55
Exam 4: 55
Final score: 59.31 Grade=F
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.