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

SECTION A Leroy Francisco

54yyyyyyyyy45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

SECTION A Leroy Francisco

54yyyyyyyyy45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

[email protected].

zw LEROY FRANCISCO ALGORITHMS

Section A: (30 Marks)


Arrupe Jesuit University is automating their student grading system using data structure
elements and Python language. Therefore, the requirement for you, is to answer questions
below to show how this can be achieved and by providing a working system where needed
for a prototype system. The system should be able to accept input of grade of 0 to 100 from
instructor, and give an output result of either failed, First class, pass or distinction).

1. Which Algorithm technique would you use to break down the problem to be more
understandable? Explain the reasons for your choice of algorithm technique to use. [8]
ANSWER:

To break down the problem of creating a student grading system, I would use a Top-Down
Approach in problem-solving, particularly focusing on the divide and conquer technique.
Here’s why this approach is suitable:
1. Simplicity: The creation of output, grading logic, and input processing are some of
the minor parts that make up the grading system. This makes every component easy to
comprehend and use.
2. Modularity: The system becomes modular when the work is broken down into
smaller elements, such as receiving input, classifying the grade, and delivering results.
It is possible to individually create, test, and maintain each module.
3. Scalability: This method makes it simple to incorporate more grading criteria (such
as grading on a curve) without completely redesigning the system in the event that
more are introduced in the future.
4. Clarity: It guarantees that programmers may concentrate on a single facet of the issue
at a time, resulting in more understandable code and improved debugging skills.
5. Effective Problem Solving: Logical flow and decision-making are improved by
approaching and resolving each minor issue separately.
6. Reusability: After the fundamental features for grading logic and input handling are
constructed, they may be used to other areas of the program or to other projects in the
future.

7. Collaboration: By allowing several developers to work on several modules at once,


the development process may be accelerated.

8. Ease of Testing: Before incorporating smaller components into the larger system,
they may be evaluated separately to verify accuracy, which aids in the early detection
of problems.

2. Using the algorithm technique, you selected in question 1, write down the algorithm
example for the grading system indicated above. [7]

ANSWER:
[email protected] LEROY FRANCISCO ALGORITHMS

1.
Start
2. Get Grade Input
o Prompt user to enter a grade (0 to 100).
o Validate the input:
 If valid (numeric and within range), proceed.
 If invalid, show an error message and repeat input prompt.
3. Determine Grade Category
o If grade < 40:
 Set result = "Failed"
o Else If 40 <= grade < 60:
 Set result = "Pass"
o Else If 60 <= grade < 80:
 Set result = "First Class"
o Else:
 Set result = "Distinction"
4. Output Result
o Print the result (grade category).
5. End

Pseudocode Representation
BEGIN

FUNCTION GetGradeInput()
WHILE True
PRINT "Enter the grade (0 to 100): "
INPUT grade
IF grade is numeric AND 0 <= grade <= 100 THEN
RETURN grade
ELSE
PRINT "Invalid input. Please enter a numerical value between 0 and 100."
END WHILE
END FUNCTION

FUNCTION DetermineGradeCategory(grade)
IF grade < 40 THEN
RETURN "Failed"
ELSE IF 40 <= grade < 60 THEN
[email protected] LEROY FRANCISCO ALGORITHMS

RETURN "Pass"
ELSE IF 60 <= grade < 80 THEN
RETURN "First Class"
ELSE
RETURN "Distinction"
END IF
END FUNCTION

FUNCTION Main()
grade = GetGradeInput()
result = DetermineGradeCategory(grade)
PRINT "The result is: " + result
END FUNCTION

Main()
END

Justification:
 The algorithm's beginning and finishing points are indicated by the Begin and End
variables.
 Functions for obtaining input and identifying the grade category make up the
algorithm.
 Because each function has distinct duties, the system as a whole is simpler to
comprehend and manage.
 In order to guarantee that input is legitimate and that the right grading category is
allocated in accordance with the grade provided, control structures like loops and
conditionals are used.
This methodical technique, which is consistent with the top-down approach employed in
programming, clarifies the input flow and grading rationale.

3. Write a PYTHON program to accept five students with student id, student name and
total from two assignments marks scored in python programming and print the result.
i. If marks are below 49. Print “You failed”.
ii. If the marks a above 50 and below 59, Print “Congratulation, you Passed”
iii. If the marks are above 60 and below 74, Print “Congratulation, you got First Class”
[email protected] LEROY FRANCISCO ALGORITHMS

iv. If the marks are above 75, Print “Congratulation, you got Distinction”
v. If the marks are above 101, print “invalid”
vi. Display Grades: Implement a function to display all student grades in sorted order
based on student ID.
vii. Arrange and sort marks in sorting algorithms of your choice for the five students
[15]
ANSWERS:
CODE:
class Student:
def __init__(self, student_id, name, marks):
self.student_id = student_id
self.name = name
self.marks = marks

def determine_grade(self):
if self.marks < 0 or self.marks > 100:
return "Invalid"
elif self.marks < 50:
return "You failed."
elif 50 <= self.marks < 60:
return "Congratulations, you Passed."
elif 60 <= self.marks < 74:
return "Congratulations, you got First Class."
elif self.marks >= 75:
return "Congratulations, you got Distinction."
def input_students():
students = []
for i in range(5):
student_id = input(f"Enter Student ID for student {i + 1}: ")
name = input(f"Enter Student Name for student {i + 1}: ")
[email protected] LEROY FRANCISCO ALGORITHMS

assignment1 = float(input(f"Enter marks for Assignment 1 for {name}: "))


assignment2 = float(input(f"Enter marks for Assignment 2 for {name}: "))
total_marks = (assignment1 + assignment2) / 2 # Average of two assignments
students.append(Student(student_id, name, total_marks))
return students

def display_grades(students):
print("\nStudent Grades:")
for student in sorted(students, key=lambda x: x.student_id):
grade_message = student.determine_grade()
print(f"ID: {student.student_id}, Name: {student.name}, Marks: {student.marks:.2f} -
{grade_message}")

def main():
students = input_students()
display_grades(students)

if __name__ == "__main__":
main()
[email protected] LEROY FRANCISCO ALGORITHMS

IMPLEMENTATION ON IDE:
[email protected] LEROY FRANCISCO ALGORITHMS

OUTPUT:

You might also like