build a student class implement the student class with the following instance variables: * id * firstName *lastName *dateOfBirth * Major create an __init__ function adn initialize all the fields make the "major" an option field and set a default value to "undefined" create a setter and getter function for all these five variables create another function: "print_student_info()" which prints 5 pieces of information: id, first name, last name, date of birth, and major. Make sure to have proper formatting done for printing these 5 things. Use the student class Task 1: create an empty list named "all_students" Task 2: create a variable named "id" and initialize it to 100 (some default value to start with, next id would be 101) Task 3: ask the user for input "How many students:" Task 4: Now run a for loop based on that input number and do the following things for each iteration: - get input of student's first name, last name, date of birth, and major - user should be able to skip the "major" input if choose to do so. (user simply hit "enter") - once all the inputs are collected, increment the "id" by 1 - then create a student object and pass that 5 information. If "major" input is skipped, pass 4 information instead - insert this object into the "all_students" list Task 5: Now iterate all the objects inside "all_students" and call the function "print_student_info()". Make sure you see all the student's info. Task 6: After that, input a student's "last name" and input "major"/ Once you get these two inputs, search all students by their last name and do the following: - if no match found, then print "No such student found" - if match found, update that student's "major" by the newly entered "major" Task 7: Lastly, do Task 5 again and observe whether specific student info got updated with the new "major" or not.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
build a student class
implement the student class with the following instance variables:
* id
* firstName
*lastName
*dateOfBirth
* Major
create an __init__ function adn initialize all the fields
make the "major" an option field and set a default value to "undefined"
create a setter and getter function for all these five variables
create another function: "print_student_info()" which prints 5 pieces of information: id, first name, last name, date of birth, and major. Make sure to have proper formatting done for printing these 5 things.
Use the student class
Task 1: create an empty list named "all_students"
Task 2: create a variable named "id" and initialize it to 100 (some default value to start with, next id would be 101)
Task 3: ask the user for input "How many students:"
Task 4: Now run a for loop based on that input number and do the following things for each iteration:
- get input of student's first name, last name, date of birth, and major
- user should be able to skip the "major" input if choose to do so. (user simply hit "enter")
- once all the inputs are collected, increment the "id" by 1
- then create a student object and pass that 5 information. If "major" input is skipped, pass 4 information instead
- insert this object into the "all_students" list
Task 5: Now iterate all the objects inside "all_students" and call the function "print_student_info()". Make sure you see all the student's info.
Task 6: After that, input a student's "last name" and input "major"/ Once you get these two inputs, search all students by their last name and do the following:
- if no match found, then print "No such student found"
- if match found, update that student's "major" by the newly entered "major"
Task 7: Lastly, do Task 5 again and observe whether specific student info got updated with the new "major" or not.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images