Question

In: Computer Science

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)

Please make the answer simple and straightforward for a beginner intro to python . Thank you

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

EDIT: Screenshots are added.

#code

#Student class
class Student:
    #constructor initializing student fields to default values
   
def __init__(self):
        self.__name='' #string name, ex: John
       
self.__number=0 #int number, ex: 100
       
self.__contact='' #string contact number, ex: 123-457-9991
       
self.__id='' #string id number, ex: ABC112
   
    #method to read data from user and fill the fields of this Student
   
def populate(self):
        self.__name=input('Enter name: ')
        self.__number=int(input('Enter student number: '))
        self.__contact=input('Enter contact number: ')
        self.__id=input('Enter ID number: ')
   
    #method to display student's data to console
   
def display(self):
        print('Name:',self.__name)
        print('Student number:',self.__number)
        print('Contact number:',self.__contact)
        print('ID number:',self.__id)

    #end of Student class

#main method

def main():
    #creating a Student instance
   
studentObj=Student()
    #looping for 5 times
   
for i in range(5):
        #populating student's fields
       
studentObj.populate()
        #displaying it
       
studentObj.display()
        print() #line break

main()

#output

Enter name: Oliver

Enter student number: 1234

Enter contact number: 999-112-123

Enter ID number: ABC1234

Name: Oliver

Student number: 1234

Contact number: 999-112-123

ID number: ABC1234

Enter name: John

Enter student number: 101

Enter contact number: 999-123-101

Enter ID number: ABC1235

Name: John

Student number: 101

Contact number: 999-123-101

ID number: ABC1235

Enter name: Barry

Enter student number: 102

Enter contact number: 999-125-102

Enter ID number: ABC0101

Name: Barry

Student number: 102

Contact number: 999-125-102

ID number: ABC0101

Enter name: Kevin

Enter student number: 103

Enter contact number: 112-112-110

Enter ID number: ABC1236

Name: Kevin

Student number: 103

Contact number: 112-112-110

ID number: ABC1236

Enter name: Jane

Enter student number: 104

Enter contact number: 110-8585-120

Enter ID number: XCV0012

Name: Jane

Student number: 104

Contact number: 110-8585-120

ID number: XCV0012

CODE SCREENSHOT

OUTPUT SCREENSHOT


Related Solutions

Create a student class that stores name, registration number and percentage, grade. Add member functions -...
Create a student class that stores name, registration number and percentage, grade. Add member functions - Read( string n, int r, float p): Read function that accepts parameter - Display(): To display student’s information - CalculateGrade()
1)  Create a UEmployee class that contains member variables for the university employee name and salary. The...
1)  Create a UEmployee class that contains member variables for the university employee name and salary. The UEmployee class should contain member methods for returning the employee name and salary. Create Faculty and Staff classes that inherit the UEmployee class. The Faculty class should include members for storing and returning the department name. The Staff class should include members for storing and returning the job title. Write a runner program that creates one instance of each class and prints all of...
Create a UEmployee class that contains member variables for the university employee name and salary. The...
Create a UEmployee class that contains member variables for the university employee name and salary. The UEmployee class should contain member methods for returning the employee name and salary. Create Faculty and Staff classes that inherit the UEmployee class. The Faculty class should include members for storing and returning the department name. The Staff class should include members for storing and returning the job title. Write a runner program that creates one instance of each class and prints all of...
Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
directions: use c++ Create a  ContactInfo class that contains the following member variables: name age phoneNumber The...
directions: use c++ Create a  ContactInfo class that contains the following member variables: name age phoneNumber The ContactInfo class should have a default constructor that sets name = "", phoneNumber = "", and age = 0. The ContactInfo class should have a constructor that accepts the name and phone number as parameters and sets name = <value of parameter name>, aAge = 0, and phoneNumber = <value of parameter phone number>. The ContactInfo class should have accessor and mutator functions for...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all of the methods required for a standard user defined class: constructors, accessors, mutators, toString, equals Create the client for testing the Student class Create another class called CourseSection Include instance variables for: course name, days and times course meets (String), description of course, student a, student b, student c (all of type Student) Create all of the methods required for a standard user defined...
First lab: Create a Fraction class Create member variables to store numerator denominator no additional member...
First lab: Create a Fraction class Create member variables to store numerator denominator no additional member variable are allowed Create accessor and mutator functions to set/return numerator denominator Create a function to set a fraction Create a function to return a fraction as a string ( common name ToString(), toString())  in the following format: 2 3/4 use to_string() function from string class to convert a number to a string; example return to_string(35)+ to_string (75) ; returns 3575 as a string Create...
Create a class called Student which stores • the name of the student • the grade...
Create a class called Student which stores • the name of the student • the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into the grade field. • Calculate the...
Write a C++ programs to: 1. Create a class called Student with four (4) private member...
Write a C++ programs to: 1. Create a class called Student with four (4) private member variables, name (string), quiz, midterm, final (all double type); 2. Include all necessary member functions for this class (at least 1 constructor, 1 get function, and 1 grading function – see #6); 3. Declare three (3) objects of Student type (individual or array); 4. Read from the keyboard three (3) sets of values of name, quiz, midterm, final and assign them to each object;...
Using C# Create the “TestQuestion” class. It will have two class variables: 1) a question and...
Using C# Create the “TestQuestion” class. It will have two class variables: 1) a question and 2) the answer to that question. Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. There should be a constructor method. We will also have a “ToString” or “__str__” method, which will print the question followed by its answer. The constructor method has two parameters...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT