In: Computer Science
Professor Al Gorithum has the following grading policy:
Al likes to round each student's grade according to these rules:
For example, grade=84 will be rounded to 85 but grade=29 will not be rounded because the rounding would result in a number that is less than 40.
Given the initial grade value for each of Al's students, write code to automate the rounding process.
Detailed Description
What to submit:
Hello dear...
I understood the problem statement. But you haven't speified the programming language you want. That's why I wrote the code in C language, as we all know it the mother of programming languages.
C CODE:
//importing stdio.h for i/o purposes
#include <stdio.h>
//roundgrade() funtion to return the rounded grade according to Prof.AI grading policy
int roundgrade(int grade){
        //if grade less than 40 => fail, no need to round the grade
        if(grade<40)
                return grade;
        //if not, student is pass
        else{
                //finding the next multiple of 5 after grade
                int nextmul5 = ((grade/5)+1)*5;
                //if the differene between next multiple of 5 and grade is less than 3
                if(nextmul5-grade < 3){
                        //return the next multiple of 5
                        return nextmul5;
                }
        }
        return grade;
}
//main method
int main(){
        ///initializing requirend variables
        int i,n,grade;
        //prompting user to enter no of students in the class
        printf("Enter no. students in the class(1-30): ");
        scanf("%d",&n);
        //while the no. of students are less than 1 or greater than 30
        while(n<1 || n>30){
                //again prompt the user to enter no of students in the class until it is valid
                printf("Invaid number\nEnter no. students in the class(1-30): ");
                scanf("%d",&n);
        }
        //creating an array to store actual grades and rounded grades of students
        int grades[n],roundedgrades[n];
        //for-loop to prompt the user to enter grades of all students
        for(i=0; i<n; i++){
                printf("Enter grade of student %d: ",i);
                scanf("%d",&grade);
                //while the grade is not in inclusive range of 0-100, prompt the user to enter grade untl it is valid
                while(grade<0 || grade>100){
                        printf("Invaid grade\nEnter grade of student %d: ",i);
                        scanf("%d",&grade);
                }
                //storing the actual grade in grades array
                grades[i] = grade;
                //sroting the rounded grade in roundedgrades array by calling the function for every grade
                roundedgrades[i] = roundgrade(grade);   
        }
        //printing table of gardes
        printf("\n------------------------------------\nStudent's Grades.\n");
        printf("Id\tGrade\trounded Grade\n");
        //for-loop to iterate through the arrays and print actual and rounded grades of all students
        for(i=0; i<n; i++){
                printf("%d\t%d\t%d\n",i,grades[i],roundedgrades[i]);    
        }
        return 0;
        //end
}
IMAGES:


OUTPUT:

Even if you are not doing it in C language, it is easy for you to translate C code to any other languaue.
Hope you will like it.
If you have any doubts ask me in comment section.
If you like my work, please give me a like and feedback. That helps me a lot. Thank you.
All the best