Table of Contents

    Practice Assignment: Grade Calculator

    Programming Mastery

    Practice Assignment: Grade Calculator

    Apply input, output, variables, arithmetic expressions, percentage calculation, validation, and decision-making logic by building a language-neutral grade calculator.

    Assignment Overview

    In this practice assignment, students will build a Grade Calculator that accepts student marks, validates the input, calculates total marks and percentage, assigns a grade, and displays a clear result summary.

    This assignment is designed to help students combine multiple programming fundamentals in one practical mini project. Students will use input, output, variables, data types, arithmetic operators, expressions, comparison operators, logical operators, else-if ladder, nested if, and basic input validation.

    A Grade Calculator is a beginner-friendly project that helps students understand how real programs use conditions to convert raw marks into meaningful results.

    Learning Objectives

    After completing this assignment, students should be able to:

    Objectives

    • Read student marks from the user.
    • Store marks in meaningful variables.
    • Validate that marks are within a correct range.
    • Calculate total marks.
    • Calculate percentage or average marks.
    • Use an else-if ladder to assign a grade.
    • Use nested if for validation before grading.
    • Display a formatted result summary.
    • Test the program using multiple test cases.
    • Write clear language-neutral pseudocode.

    Prerequisites

    Before attempting this assignment, students should revise the following topics:

    Required Topics

    • Input and output.
    • Variables and constants.
    • Data types.
    • Arithmetic operators.
    • Assignment operators.
    • Expressions.
    • Comparison operators.
    • Logical operators.
    • Decision making.
    • Else-if ladder.
    • Nested if.
    • Basic input validation.
    • Common mistakes in conditions.

    Assignment Instructions

    Build a grade calculator using language-neutral pseudocode. The program should accept marks for multiple subjects, calculate the total and percentage, assign a grade based on percentage, and display the final result.

    Important: This assignment is not specific to Java, Python, C, C++, JavaScript, or any single programming language. Students should write the solution using clear language-neutral pseudocode.

    General Instructions

    • Ask the user to enter the student name.
    • Ask the user to enter marks for five subjects.
    • Each subject mark should be between 0 and 100.
    • If any mark is invalid, display an error message.
    • If all marks are valid, calculate total marks.
    • Calculate percentage using total marks.
    • Assign grade using an else-if ladder.
    • Display student name, total marks, percentage, grade, and pass/fail status.
    • Use meaningful variable names.
    • Use proper indentation.
    • Test the calculator with normal, boundary, and invalid inputs.

    Grade Calculator Requirements

    Your grade calculator must satisfy the following requirements.

    Requirement Description
    Student Name The program should accept the student's name.
    Subject Marks The program should accept marks for five subjects.
    Validation Each mark must be between 0 and 100.
    Total Marks The program should calculate total marks obtained.
    Percentage The program should calculate percentage based on total marks.
    Grade The program should assign a grade using an else-if ladder.
    Pass / Fail Status The program should display whether the student passed or failed.
    Formatted Output The final result should be displayed in a clear and readable format.

    Grading Criteria

    Use the following grading scale for this assignment.

    Percentage Range Grade Performance Message
    90 - 100 A+ Outstanding performance
    80 - 89 A Excellent performance
    70 - 79 B Very good performance
    60 - 69 C Good performance
    50 - 59 D Average performance
    35 - 49 E Pass, but improvement needed
    0 - 34 F Fail
    Teacher Note: You can modify the grading scale based on your institution's rule. For this assignment, students should follow the grading scale given above.

    Input → Process → Output Plan

    Before writing pseudocode, students should understand the program using the IPO model.

    Stage Details Example
    Input Student name and five subject marks. Rahul, 80, 75, 90, 70, 85
    Process Validate marks, calculate total, calculate percentage, assign grade. Total = 400, Percentage = 80
    Output Display result summary. Grade A

    Expected User Inputs

    The program should read the following values:

    • Student name: Text value.
    • Subject 1 marks: Numeric value between 0 and 100.
    • Subject 2 marks: Numeric value between 0 and 100.
    • Subject 3 marks: Numeric value between 0 and 100.
    • Subject 4 marks: Numeric value between 0 and 100.
    • Subject 5 marks: Numeric value between 0 and 100.

    Example Input

    Student Name: Rahul
    Subject 1 Marks: 80
    Subject 2 Marks: 75
    Subject 3 Marks: 90
    Subject 4 Marks: 70
    Subject 5 Marks: 85

    Expected Output

    ----- Grade Report -----
    Student Name : Rahul
    Total Marks  : 400 / 500
    Percentage   : 80%
    Grade        : A
    Status       : Pass
    Message      : Excellent performance

    Validation Rules

    The grade calculator should validate all marks before calculating the grade.

    Input Validation Rule Error Message
    Student Name Should not be empty. Student name cannot be empty.
    Subject Marks Each mark must be numeric. Please enter valid numeric marks.
    Marks Range Each mark must be between 0 and 100. Marks must be between 0 and 100.

    Task 1: Write the Algorithm

    Write an algorithm for building a grade calculator.

    Expected Algorithm Structure

    Step 1: Start
    Step 2: Ask the user to enter student name
    Step 3: Read student name
    Step 4: Ask the user to enter marks for five subjects
    Step 5: Read all five marks
    Step 6: Validate that all marks are between 0 and 100
    Step 7: If any mark is invalid, display error message
    Step 8: If all marks are valid, calculate total marks
    Step 9: Calculate percentage
    Step 10: Use else-if ladder to assign grade
    Step 11: Decide pass or fail status
    Step 12: Display student name, total, percentage, grade, status, and message
    Step 13: Stop

    Task 2: Write Language-Neutral Pseudocode

    Write pseudocode for the grade calculator using clear and readable steps.

    Your Pseudocode Area

    WRITE YOUR GRADE CALCULATOR PSEUDOCODE HERE

    Task 3: Create a Trace Table

    Use the following test case and complete the trace table.

    Test Case

    Student Name = Meera
    Subject 1 = 90
    Subject 2 = 85
    Subject 3 = 80
    Subject 4 = 75
    Subject 5 = 70
    Step Variable / Action Value
    1 studentName ________
    2 totalMarks ________
    3 percentage ________
    4 grade ________
    5 status ________
    6 Output ________

    Task 4: Test Your Grade Calculator

    Test your program using the following test cases.

    Test Case Marks Percentage Expected Grade Expected Status
    1 95, 90, 92, 94, 89 92 A+ Pass
    2 80, 85, 82, 88, 84 83.8 A Pass
    3 70, 72, 75, 78, 74 73.8 B Pass
    4 35, 40, 45, 50, 55 45 E Pass
    5 20, 30, 25, 28, 34 27.4 F Fail
    6 100, 100, 100, 100, 100 100 A+ Pass
    7 101, 80, 70, 60, 50 Not calculated Error Invalid marks
    8 -5, 80, 70, 60, 50 Not calculated Error Invalid marks

    Sample Solution: Algorithm

    Step 1: Start
    Step 2: Declare studentName, subjectOne, subjectTwo, subjectThree, subjectFour, subjectFive
    Step 3: Declare totalMarks, percentage, grade, status, and message
    Step 4: Ask user to enter student name
    Step 5: Read studentName
    Step 6: Ask user to enter five subject marks
    Step 7: Read subjectOne, subjectTwo, subjectThree, subjectFour, subjectFive
    Step 8: Check whether all marks are between 0 and 100
    Step 9: If any mark is invalid, display error message
    Step 10: If all marks are valid, calculate totalMarks
    Step 11: Calculate percentage
    Step 12: If percentage is 90 or above, grade is A+
    Step 13: Else if percentage is 80 or above, grade is A
    Step 14: Else if percentage is 70 or above, grade is B
    Step 15: Else if percentage is 60 or above, grade is C
    Step 16: Else if percentage is 50 or above, grade is D
    Step 17: Else if percentage is 35 or above, grade is E
    Step 18: Else grade is F
    Step 19: If percentage is 35 or above, status is Pass
    Step 20: Otherwise status is Fail
    Step 21: Display final grade report
    Step 22: Stop

    Sample Solution: Grade Calculator Pseudocode

    /*
    Practice Assignment: Grade Calculator
    This program accepts marks for five subjects,
    calculates total and percentage, then assigns grade.
    */
    
    ENTRY POINT
        DECLARE studentName AS TEXT = ""
    
        DECLARE subjectOne AS DECIMAL = 0.0
        DECLARE subjectTwo AS DECIMAL = 0.0
        DECLARE subjectThree AS DECIMAL = 0.0
        DECLARE subjectFour AS DECIMAL = 0.0
        DECLARE subjectFive AS DECIMAL = 0.0
    
        DECLARE totalMarks AS DECIMAL = 0.0
        DECLARE percentage AS DECIMAL = 0.0
    
        DECLARE grade AS TEXT = ""
        DECLARE status AS TEXT = ""
        DECLARE message AS TEXT = ""
        DECLARE isValid AS BOOLEAN = true
    
        DISPLAY "----- Grade Calculator -----"
    
        DISPLAY "Enter student name:"
        INPUT studentName
    
        DISPLAY "Enter marks for subject 1:"
        INPUT subjectOne
    
        DISPLAY "Enter marks for subject 2:"
        INPUT subjectTwo
    
        DISPLAY "Enter marks for subject 3:"
        INPUT subjectThree
    
        DISPLAY "Enter marks for subject 4:"
        INPUT subjectFour
    
        DISPLAY "Enter marks for subject 5:"
        INPUT subjectFive
    
        IF studentName == "" THEN
            DISPLAY "Error: Student name cannot be empty"
            SET isValid = false
        END IF
    
        IF subjectOne < 0 OR subjectOne > 100 THEN
            DISPLAY "Error: Subject 1 marks must be between 0 and 100"
            SET isValid = false
        END IF
    
        IF subjectTwo < 0 OR subjectTwo > 100 THEN
            DISPLAY "Error: Subject 2 marks must be between 0 and 100"
            SET isValid = false
        END IF
    
        IF subjectThree < 0 OR subjectThree > 100 THEN
            DISPLAY "Error: Subject 3 marks must be between 0 and 100"
            SET isValid = false
        END IF
    
        IF subjectFour < 0 OR subjectFour > 100 THEN
            DISPLAY "Error: Subject 4 marks must be between 0 and 100"
            SET isValid = false
        END IF
    
        IF subjectFive < 0 OR subjectFive > 100 THEN
            DISPLAY "Error: Subject 5 marks must be between 0 and 100"
            SET isValid = false
        END IF
    
        IF isValid == true THEN
            SET totalMarks = subjectOne + subjectTwo + subjectThree + subjectFour + subjectFive
            SET percentage = totalMarks / 5
    
            IF percentage >= 90 THEN
                SET grade = "A+"
                SET message = "Outstanding performance"
    
            ELSE IF percentage >= 80 THEN
                SET grade = "A"
                SET message = "Excellent performance"
    
            ELSE IF percentage >= 70 THEN
                SET grade = "B"
                SET message = "Very good performance"
    
            ELSE IF percentage >= 60 THEN
                SET grade = "C"
                SET message = "Good performance"
    
            ELSE IF percentage >= 50 THEN
                SET grade = "D"
                SET message = "Average performance"
    
            ELSE IF percentage >= 35 THEN
                SET grade = "E"
                SET message = "Pass, but improvement needed"
    
            ELSE
                SET grade = "F"
                SET message = "Fail"
            END IF
    
            IF percentage >= 35 THEN
                SET status = "Pass"
            ELSE
                SET status = "Fail"
            END IF
    
            DISPLAY "----- Grade Report -----"
            DISPLAY "Student Name : " + studentName
            DISPLAY "Total Marks  : " + totalMarks + " / 500"
            DISPLAY "Percentage   : " + percentage + "%"
            DISPLAY "Grade        : " + grade
            DISPLAY "Status       : " + status
            DISPLAY "Message      : " + message
        END IF
    END ENTRY POINT

    Alternative Solution: Nested If for Validation

    The following version first validates all marks together. Only if marks are valid does it calculate the grade.

    /*
    Grade Calculator using nested if for validation.
    */
    
    ENTRY POINT
        DECLARE studentName AS TEXT = ""
        DECLARE mark1 AS DECIMAL = 0.0
        DECLARE mark2 AS DECIMAL = 0.0
        DECLARE mark3 AS DECIMAL = 0.0
        DECLARE mark4 AS DECIMAL = 0.0
        DECLARE mark5 AS DECIMAL = 0.0
        DECLARE total AS DECIMAL = 0.0
        DECLARE percentage AS DECIMAL = 0.0
        DECLARE grade AS TEXT = ""
    
        DISPLAY "Enter student name:"
        INPUT studentName
    
        DISPLAY "Enter marks for five subjects:"
        INPUT mark1
        INPUT mark2
        INPUT mark3
        INPUT mark4
        INPUT mark5
    
        IF mark1 >= 0 AND mark1 <= 100 AND
           mark2 >= 0 AND mark2 <= 100 AND
           mark3 >= 0 AND mark3 <= 100 AND
           mark4 >= 0 AND mark4 <= 100 AND
           mark5 >= 0 AND mark5 <= 100 THEN
    
            SET total = mark1 + mark2 + mark3 + mark4 + mark5
            SET percentage = total / 5
    
            IF percentage >= 90 THEN
                SET grade = "A+"
            ELSE IF percentage >= 80 THEN
                SET grade = "A"
            ELSE IF percentage >= 70 THEN
                SET grade = "B"
            ELSE IF percentage >= 60 THEN
                SET grade = "C"
            ELSE IF percentage >= 50 THEN
                SET grade = "D"
            ELSE IF percentage >= 35 THEN
                SET grade = "E"
            ELSE
                SET grade = "F"
            END IF
    
            DISPLAY "Student Name: " + studentName
            DISPLAY "Total Marks : " + total
            DISPLAY "Percentage  : " + percentage
            DISPLAY "Grade       : " + grade
    
        ELSE
            DISPLAY "Invalid marks. All marks must be between 0 and 100."
        END IF
    END ENTRY POINT

    Sample Answer: Trace Table

    For the test case Meera, 90, 85, 80, 75, and 70, the trace table should look like this:

    Step Variable / Action Value
    1 studentName Meera
    2 totalMarks = 90 + 85 + 80 + 75 + 70 400
    3 percentage = totalMarks / 5 80
    4 grade A
    5 status Pass
    6 Output Meera scored 80% and received Grade A

    Bonus Task 1: Add Subject-Wise Result

    As a bonus challenge, students can display whether the student passed or failed in each subject.

    Bonus Requirements

    • Check each subject individually.
    • If a subject mark is below 35, display Fail in that subject.
    • If all subjects are at least 35, display Passed in all subjects.
    • Use logical operators or nested if where needed.

    Bonus Pseudocode Idea

    IF subjectOne >= 35 AND subjectTwo >= 35 AND subjectThree >= 35 AND subjectFour >= 35 AND subjectFive >= 35 THEN
        DISPLAY "Passed in all subjects"
    ELSE
        DISPLAY "Failed in one or more subjects"
    END IF

    Bonus Task 2: Add Remarks

    Students can add personalized remarks based on the grade.

    Optional Remarks

    • A+ → Outstanding work.
    • A → Excellent effort.
    • B → Very good performance.
    • C → Good, but can improve.
    • D → Needs consistent practice.
    • E → Passed, but improvement required.
    • F → Failed, needs revision and practice.

    Bonus Task 3: Multiple Students

    Advanced students can modify the program to calculate grades for multiple students.

    • Ask how many students need grade calculation.
    • Repeat the grade calculator for each student.
    • Display a separate report for each student.
    • Calculate class average as an extra challenge.

    Common Mistakes to Avoid

    Mistakes

    • Not validating marks before calculation.
    • Allowing marks below 0 or above 100.
    • Using OR instead of AND for range validation.
    • Writing grade conditions in the wrong order.
    • Checking percentage > 90 instead of percentage >= 90.
    • Forgetting boundary values such as 35, 50, 80, and 90.
    • Calculating percentage before validating input.
    • Displaying output without clear labels.
    • Using unclear variable names like a, b, and x.

    Better Habits

    • Validate all marks first.
    • Use AND for range checks.
    • Write grade conditions from highest to lowest.
    • Use boundary-inclusive operators such as >=.
    • Use meaningful names such as totalMarks, percentage, and grade.
    • Test boundary values carefully.
    • Use formatted output.
    • Use trace tables to verify calculation.

    Submission Checklist

    Before submitting, students should verify the following:

    Checklist

    • The program accepts student name.
    • The program accepts five subject marks.
    • All marks are validated.
    • Invalid marks are handled correctly.
    • Total marks are calculated correctly.
    • Percentage is calculated correctly.
    • Grade is assigned using else-if ladder.
    • Pass/fail status is displayed.
    • Output is clear and formatted.
    • At least eight test cases are completed.
    • Boundary values are tested.
    • Pseudocode is properly indented.

    Evaluation Rubric

    The assignment can be evaluated using the following rubric.

    Criteria Marks What to Check
    Input Handling 15 Correctly reads student name and five marks.
    Input Validation 20 Checks marks are numeric and between 0 and 100.
    Total and Percentage Calculation 15 Calculates total and percentage correctly.
    Grade Logic 20 Uses correct else-if ladder and grade ranges.
    Output Formatting 10 Displays result clearly with labels.
    Code Readability 10 Uses meaningful names and proper indentation.
    Testing 10 Includes normal, boundary, and invalid test cases.

    Mini Viva Questions

    1

    Why is input validation important in a grade calculator?

    Input validation ensures that marks are within the valid range before calculation, preventing incorrect results.

    2

    Why should grade conditions be written from highest to lowest?

    Grade conditions should be written from highest to lowest because an else-if ladder stops after the first true condition.

    3

    Which control flow structure is best for assigning grades?

    An else-if ladder is best because grade assignment checks multiple percentage ranges in order.

    4

    What is a boundary value in this assignment?

    Boundary values are values at grade limits, such as 35, 50, 60, 70, 80, and 90.

    5

    Why should marks be converted to numeric data before calculation?

    Marks should be numeric so the program can correctly perform addition, division, and comparison operations.

    Interview Questions on Grade Calculator

    1

    How would you design a grade calculator?

    I would read marks, validate them, calculate total and percentage, use an else-if ladder to assign grade, and display the final result.

    2

    What condition would you use to validate marks?

    I would use marks >= 0 AND marks <= 100 to check whether marks are within the valid range.

    3

    Why is AND used for marks validation?

    AND is used because both conditions must be true: marks must be at least 0 and at most 100.

    4

    What is the role of percentage in a grade calculator?

    Percentage is used to compare the student's overall performance against grade ranges.

    5

    How can the grade calculator be improved?

    It can be improved by adding multiple students, subject-wise pass/fail, class average, highest marks, lowest marks, and performance remarks.

    Quick Summary

    Concept How It Is Used in Grade Calculator
    Input Reads student name and subject marks.
    Variables Stores marks, total, percentage, grade, and status.
    Arithmetic Operators Calculate total and percentage.
    Comparison Operators Check marks range and grade boundaries.
    Logical Operators Validate marks using range conditions.
    Nested If Checks grade only after validating marks.
    Else-If Ladder Assigns grades based on percentage ranges.
    Output Displays final grade report clearly.

    Final Takeaway

    The Grade Calculator assignment helps students apply control flow in a real-world academic scenario. It combines input, variables, arithmetic expressions, validation, nested if, else-if ladder, and formatted output. By completing this assignment, students learn how programming conditions can transform raw marks into meaningful results such as percentage, grade, status, and performance message.