Questions


Related Questions:


Questions

Asked By :  Devendra
Answers1

Define a class student that keeps tracks of academic record of

Define a class Student that keeps tracks of academic record of students in a school. 
The class should contain the following data members:
rollNum Roll number of student
name Name of student
marks- Total Marks of student (considering 500 as maximum marks)
stream- 'A': Arts, 'C': Commerce, 'S': Science
percent- Percentage computed using Marks
The class should support the following methods:




Answers :

0

To define the Student class that tracks the academic record of students in a school, we will include the following data members and methods:

Data Members:

  1. rollNum: Roll number of the student.
  2. name: Name of the student.
  3. marks: Total marks obtained by the student (out of 500).
  4. stream: Stream of the student, which can be 'A' (Arts), 'C' (Commerce), or 'S' (Science).
  5. percent: Percentage of the student, computed using the marks.

Methods:

  1. __init__(self, rollNum, name, marks, stream): Constructor method to initialize the student’s data.
  2. calculate_percentage(self): Method to calculate and store the percentage based on marks.
  3. display_details(self): Method to display the student's details, including roll number, name, stream, marks, and percentage.
  4. grade(self): Method to determine and return the grade based on the percentage.

Code Implementation:

class Student:
    # Constructor to initialize student data
    def __init__(self, rollNum, name, marks, stream):
        self.rollNum = rollNum  # Student's roll number
        self.name = name  # Student's name
        self.marks = marks  # Total marks obtained by the student
        self.stream = stream  # Stream: 'A', 'C', or 'S'
        self.percent = 0  # Initialize percentage to 0 initially
    # Method to calculate percentage
    def calculate_percentage(self):
        self.percent = (self.marks / 500) * 100  # Percentage = (marks/total marks) * 100
    # Method to display student's details
    def display_details(self):
        # Displaying all details of the student
        print(f"Roll Number: {self.rollNum}")
        print(f"Name: {self.name}")
        print(f"Stream: {self.stream}")
        print(f"Total Marks: {self.marks}")
        print(f"Percentage: {self.percent}%")
    # Method to calculate grade based on percentage
    def grade(self):
        if self.percent >= 80:
            return "A"
        elif self.percent >= 60:
            return "B"
        elif self.percent >= 45:
            return "C"
        else:
            return "D"
# Example usage:
# Create a student object
student1 = Student(101, "John Doe", 450, "S")
# Calculate the percentage
student1.calculate_percentage()
# Display student details
student1.display_details()
# Get and print the grade
print("Grade:", student1.grade())

Explanation of Methods:

  1. __init__ (Constructor):

    • Initializes the student's roll number, name, marks, and stream when a new Student object is created.
  2. calculate_percentage:

    • Calculates the percentage by dividing the total marks obtained by the student by 500 (the maximum possible marks) and multiplying by 100 to get the percentage.
  3. display_details:

    • Displays the student's roll number, name, stream, total marks, and calculated percentage.
  4. grade:

    • This method returns the grade based on the percentage:
      • A for percentages greater than or equal to 80.
      • B for percentages greater than or equal to 60 but less than 80.
      • C for percentages greater than or equal to 45 but less than 60.
      • D for percentages below 45.

Example Output:

Roll Number: 101
Name: John Doe
Stream: S
Total Marks: 450
Percentage: 90.0%
Grade: A

Usage:

  1. Create a Student object by providing roll number, name, marks, and stream.
  2. Use the calculate_percentage() method to compute the percentage.
  3. Use the display_details() method to print the student's details.
  4. Use the grade() method to determine and print the student's grade based on their percentage.

This program covers all the basic functionalities as requested, allowing you to track and calculate academic details for students.


Answered By

Devendra

Your Answer



XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Write your answer, be as detailed as possible...

Reply as a guest

Required but never shown

Try Now AI powered Content Automation