Knowee
Questions
Features
Study Tools

Create a class called "Student" with private member variables for name, roll number, and marks in three subjects. Include public member functions to set the student details, calculate the average marks, and display the student detail

Question

Create a class called "Student" with private member variables for name, roll number, and marks in three subjects. Include public member functions to set the student details, calculate the average marks, and display the student detail

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is the code in Python:

class Student:
    def __init__(self):
        self.__name = ""
        self.__roll_number = 0
        self.__marks = [0, 0, 0]

    def set_details(self, name, roll_number, marks):
        self.__name = name
        self.__roll_number = roll_number
        self.__marks = marks

    def calculate_average(self):
        return sum(self.__marks) / len(self.__marks)

    def display_details(self):
        print(f"Name: {self.__name}")
        print(f"Roll Number: {self.__roll_number}")
        print(f"Marks: {self.__marks}")
        print(f"Average Marks: {self.calculate_average()}")

Here's how you can use this class:

student = Student()
student.set_details("John Doe", 1, [85, 90, 95])
student.display_details()

This will output:

Name: John Doe
Roll Number: 1
Marks: [85, 90, 95]
Average Marks: 90.0

This problem has been solved

Similar Questions

You are developing a Student Record Management System in C. The system needs to store and manage information for multiple students, including their names, roll numbers, and marks obtained in different subjects. Implement array in structures to read, write, and compute average marks and the students scoring above and below the average marks for a class of N students. INPUT/OUTPUT EXAMPLE: Enter the number of students: 3 Enter details for 3 students: Student 1: Name: A Roll Number: 1 Marks in 5 subjects: Subject 1: 12 Subject 2: 13 Subject 3: 14 Subject 4: 15 Subject 5: 16 Student 2: Name: BB Roll Number: 2 Marks in 5 subjects: Subject 1: 11 Subject 2: 13 Subject 3: 12 Subject 4: 15 Subject 5: 14 Student 3: Name: CC Roll Number: 10 Marks in 5 subjects: Subject 1: 13 Subject 2: 14 Subject 3: 16 Subject 4: 17 Subject 5: 11 Class average marks: 13.73 Students scoring above average: A (Roll Number: 1) CC (Roll Number: 10) Students scoring below average: BB (Roll Number: 2)

We want to calculate the total marks of each student of a class in Physics,Chemistry and Mathematics and the average marks of the class. The number of students in the class are entered by the user. Create a class named Marks with data members for roll number, name and marks. Create three other classes inheriting the Marks class, namely Physics, Chemistry and Mathematics, which are used to define marks in individual subject of each student. Roll number of each student will be generated automatically using inheritance by c++

Create a class VIT with data members student roll no, name, marks define a constructor to initilize the data members create a derived class student ,define a member function to calculate the average mark of the student

Write a C program using structure student which allows users to input details for three students including their names, roll numbers, and marks in 5 subjects. Use a function calculateTotalMarks(struct Student) which calculates the total marks and percentage for each student and displays the information. Each subject test is for 10 marks. Total marks = 50. Percentage = (marks obtained/total marks)*100.

DescriptionYou need to create a Constructor function which will create object for Student details of the following properties:name: It will store student nameroll_no: Stores the roll numberclass: Stores the classsection: Stores the sectionmarks_of_5_subjects: It will store marks of science, maths, social science, english & hindi. You can store marks in this format:{ science: 72, maths: 75, social_science: 79, english: 80, hindi: 67}printTop3Subjects: It is a function method. It will print top three subject names based on marks.printReportCard: It is also a function method. It will create and print a report card of a student. For example:+--------------------+| REPORT CARD |+--------------------+| Name - Huzaifa || Roll no. - 16 || Class - X || Section - A || Science - 73 || S.Sc - 79 || Maths - 75 || English - 80 | | Hindi - 67 || Prectage - 74.8 % |+--------------------+

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.