Object Oriented Programming (OOP) is a programming paradigm based on the concept of "objects." For example, consider a remote-controlled toy car: the car itself is the object, and the remote control is the device that controls it. You can move the RC car forward, backward, left, and right using the remote, illustrating the basic concept of OOP. Python supports Object Oriented Programming through features like functions and classes.
Class
A class is a prototype, blueprint, or design that defines the variables and methods for specific objects. It serves to encapsulate the content of the program that will be executed, containing attributes/data types and methods to carry out a program. In Python, a class is defined using the keyword class, followed by the name of the class, like this: class class_name. Calling a class is similar to calling a function/method in a program by invoking the class name along with its parameters. Typically, a class contains many methods/functions that represent the properties of that class.
Classes can take various forms in different programming languages, such as abstract classes, data classes, and more. A class can also relate to other classes in a relationship known as inheritance, where a Parent Class (Base Class) has a Child Class (Derived Class) that inherits the same properties and variables.
For example, consider a car class: the car has attributes like engine, wheels, battery, etc. The car is a class, while the engine, wheels, battery, etc., are functionalities.
Important Aspects of Declaring a Class:
Initialization Function
Self Parameter
Initialization Function
This is a mandatory function that must be initialized when creating and declaring a class. It is used to add arguments and store parameters within the class.
Self Parameter
This is a variable that can only be used within the class declaration.
Create a program that implements a class named Student with methods to display the biodata of the student inputted by the user.
Exercise 2
Create a class that implements getter and setter methods, utilizing branching and looping as in the previous exercise. The program should accept user input for variable declarations and store it in a class, allowing manipulation and modification based on user input. The data can be displayed using the getter and setter methods.
===== OOP Program ===== 1. Declare Object 2. Display Object 3. Change Object Value 4. Delete Object 5. Exit Program Enter Your Choice (1/2/3/4/5): 2 (Input by User)
Name: None Score: None
===== OOP Program ===== 1. Declare Object 2. Display Object 3. Change Object Value 4. Delete Object 5. Exit Program Enter Your Choice (1/2/3/4/5): 1 (Input by User) Enter Your Name: ARZ (Input by User) Enter Your Score: 95 (Input by User) Data Successfully Added
===== OOP Program ===== 1. Declare Object 2. Display Object 3. Change Object Value 4. Delete Object 5. Exit Program Enter Your Choice (1/2/3/4/5): 2 (Input by User)
Name: ARZ Score: 95
===== OOP Program ===== 1. Declare Object 2. Display Object 3. Change Object Value 4. Delete Object 5. Exit Program
Enter Your Choice (1/2/3/4/5): 3 (Input by User) What would you like to change (Name/Score): Score (Input by User) Enter New Score: 100 (Input by User) Score Data Successfully Changed
===== OOP Program ===== 1. Declare Object 2. Display Object 3. Change Object Value 4. Delete Object 5. Exit Program
Enter Your Choice (1/2/3/4/5): 2 (Input by User)
Name: ARZ Score: 100
===== OOP Program ===== 1. Declare Object 2. Display Object 3. Change Object Value 4. Delete Object 5. Exit Program Enter Your Choice (1/2/3/4/5): 4 (Input by User) Data Successfully Deleted
===== OOP Program ===== 1. Declare Object 2. Display Object 3. Change Object Value 4. Delete Object 5. Exit Program Enter Your Choice (1/2/3/4/5): 2 (Input by User)
Name: None Score: None
===== OOP Program ===== 1. Declare Object 2. Display Object 3. Change Object Value 4. Delete Object 5. Exit Program Enter Your Choice (1/2/3/4/5): 5 (Input by User) Thank you for using my program.