0% found this document useful (0 votes)
4 views

Assignment3

The document outlines a student grading system that calculates and displays the average grade and letter grade for a specified number of students based on their subject grades. It includes error handling for invalid inputs such as negative numbers and grades outside the 0-100 range. The system provides a menu for processing student data or exiting the program.

Uploaded by

Afshan Tabassum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment3

The document outlines a student grading system that calculates and displays the average grade and letter grade for a specified number of students based on their subject grades. It includes error handling for invalid inputs such as negative numbers and grades outside the 0-100 range. The system provides a menu for processing student data or exiting the program.

Uploaded by

Afshan Tabassum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Function CalculateGrade(average)

If average >= 90 Then

Return "A"

Else If average >= 80 Then

Return "B"

Else If average >= 70 Then

Return "C"

Else If average >= 60 Then

Return "D"

Else

Return "F"

End Function

Function ProcessStudentData()

Try

Print "Enter the number of students: "

num_students <- Integer(Input())

If num_students <= 0 Then

Throw Exception("Number of students must be greater than 0")

End If

For i from 1 to num_students Do

Print "Enter student name: "

name <- Input()

Print "Enter number of subjects: "

num_subjects <- Integer(Input())

If num_subjects <= 0 Then

Throw Exception("Number of subjects must be greater than 0")

End If
grades <- []

For j from 1 to num_subjects Do

Print "Enter grade for subject " + j + ": "

grade <- Float(Input())

If grade < 0 or grade > 100 Then

Throw Exception("Invalid grade. Please enter a value between 0


and 100.")

End If

grades.append(grade)

End For

average <- Sum(grades) / num_subjects

grade_letter <- CalculateGrade(average)

Print "Student: " + name + ", Average: " + average + ", Grade: " + grade_letter

End For

Catch Exception as error

Print "Error: " + error.message

End Try

End Function

Repeat

Print "Student Grading System"

Print "1. Process Student Data"

Print "2. Exit"

Print "Enter your choice: "

choice <- Integer(Input())

If choice == 1 Then

ProcessStudentData()
Else If choice == 2 Then

Print "Exiting Program. Goodbye!"

Exit Program

Else

Print "Invalid choice. Please try again."

End If

End Repeat

You might also like