Write the code for the function in the prototype: int grade point (int test_scor
ID: 2081126 • Letter: W
Question
Write the code for the function in the prototype: int grade point (int test_score, int *threshold); Function grade point () returns a grade point value in the range 0 = F, 1 = D 2 = C, 3 = B, and 4 = A, depending on the test_score, using the threshold array, which contains the minimum scores for each letter grade. If grade point () was called from main () as follows: int array[] = {60, 70, 80, 90}; gp = grade point (85, array); gp should be loaded with the value 3 int grade point (int test_score, int -threshold)//complete the function code here:Explanation / Answer
First I am solving the example given in the question and then I will make the generalised code;
1st code
#include<stdio.h>
int gradepoint(int test_score, int *threshold);
void main()
{
int gp;
int score;
int array[]={60,70,80,90};
printf("Enter the test score ");
scanf("%d",&score);
gp = gradepoint(score,array);
printf("%d",gp);
}
int gradepoint(int test_score, int *threshold)
{
int gp;
if (test_score>=90)
gp=4;
else if (test_score<90 && test_score>=80)
gp=3;
else if (test_score<80 && test_score>=70)
gp=2;
else if (test_score<70 && test_score>=60)
gp=1;
else
gp=0;
return gp;
}
2nd code
#include<stdio.h>
int gradepoint(int test_score, int *threshold);
void main()
{
int gp;
int score,a,b,c,d;
printf("Enter the minimum score for grade A ");
scanf("%d",&a);
printf("Enter the minimum score for grade B ");
scanf("%d",&b);
printf("Enter the minimum score for grade C ");
scanf("%d",&c);
printf("Enter the minimum score for grade D ");
scanf("%d",&d);
int array[]={d,c,b,a};
printf("Enter the test score ");
scanf("%d",&score);
gp = gradepoint(score,array);
printf("%d",gp);
}
int gradepoint(int test_score, int *threshold)
{
int gp;
if (test_score>=threshold[3])
gp=4;
else if (test_score<threshold[3] && test_score>=threshold[2])
gp=3;
else if (test_score<threshold[2] && test_score>=threshold[1])
gp=2;
else if (test_score<threshold[1] && test_score>=threshold[0])
gp=1;
else
gp=0;
return gp;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.