Answer to Question #297550 in Python for snow

Question #297550

Construct a class named student consisting of a student identification number, list of five grades, and an integer representing the total value of grades entered. The constructor for this class should initialize all student data members to zero. Included in the class the functions/ methods for:


1. Constructor and a Destructor.


2. Create an assessor method to enter a student number


3. Create a method to enter a single test grade (used loop for entering 5 grades)


4. Create a mutator method – to computer an average grade


5. Create a method to display the student number and average grade.


1
Expert's answer
2022-02-14T12:04:38-0500
class Student:
    # Initializing
    def __init__(self):
        self.studentIdentificationNumber = ""
        self.listFiveGrades =[]
        self.totalValueGradesEntered = 0
 
    # Deleting (Calling destructor)
    def __del__(self):
        print('Destructor called, Student deleted.')
    def inputStudentNumber(self):
        self.studentIdentificationNumber = input("Enter a student number: ")
        


    def inputGrades(self):
        for i in range(1,6):
            grade=int(input(f"Enter grade {i}: "))
            self.listFiveGrades.append(grade)
            self.totalValueGradesEntered+=grade


    def calculateAverageGrade(self):
        return self.totalValueGradesEntered/5.0
    def display(self):
         print(f"The student number: {self.studentIdentificationNumber}")
         print(f"The student average grade: {self.calculateAverageGrade()}")
               
    
obj = Student()
obj.inputStudentNumber()
obj.inputGrades()
obj.display()
del obj

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS