Question

Question 1 (10) Create a class Student with public member variables: Student name, student number, contact...

Question 1 (10)
Create a class Student with public member variables: Student name, student number, contact number, ID number. The following specifications are required:
 Add init() method of the class that initializes string member variables to empty strings and numeric values to 0. (2)
 Add the method populate() to the class. The method is used to assign values to the member variables of the class. (2)
 Add the method display() to the class. The method is used to display the member variables of the class. (2)
 Create an instance StudentObj of the class Student in a main program. (2)
 The main program should prompt the user to enter values for five students. The attributes should be assigned to the instance of Student using its populate() method, and must be displayed using the display() method of the instance of Student. (2)

hint::

Create a skeleton of the Class and then build your program with each specification like :

Create a Student Class

def __init__method

initialise the public member variables to empty strings and 0

def populate () method

read in and assign the values for each public member variable from the user

def display () method

print each public member value

# main program

prompt the user to enter 5 student's records

create 5 instances of Student

assign member variable values using populate method for the each instance of Student

display values of member variables values for each instance of Student

The outlined structure of should enable you to build your solution for Question 1.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#python code

"""
Student with public member variables:
Student name, student number, contact number, ID number.
"""


class Student:
    def __init__(self):
        self._name = ""
        self._number = 0
        self._contactNumber = ""
        self._id = 0

    def populate(self):
        self._name = input("Enter student name: ")
        self._id = int(input("Enter student id: "))
        self._number = int(input("Enter student number: "))
        self._contactNumber = input("Enter student contact number: ")

    def display(self):
        print("Student Name: "+self._name+"\nStudent Number: "+str(self._number)
              + "\nStudent Id: "+str(self._id)+"\nStudent Contact Number: "+self._contactNumber)


if __name__ == "__main__":
     s = Student()
     s.populate()
     s.display()

#screeshot for indentation help

#Output

//If you need any help regarding this solution .......... please leave a comment.... thanks

Add a comment
Know the answer?
Add Answer to:
Question 1 (10) Create a class Student with public member variables: Student name, student number, contact...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT