IT 210: Assignment 4
TASK1:
Define and explain the following concepts with examples:
Class
Instance
Encapsulation
Abstraction
Inheritence
Polymorphism
Multiple Inheritence
You are allowed read books and materials from the Internet. Then answer to each of the above OOP related terminologies in your own words. Any indication of copying from any source will be seriously penalized as a case of plagiarism.
TASK 2: (Programming Exercises from chap 11 (q3 pg.575))
Write a class named ‘Person’ with data attributes: name, address and telephone number. Next, write a class named ‘Customer’ that is subclass of ‘Person’ class. The ‘Customer’ class should have a data attribute for customer number, and a Boolean data attribute indicating whether the customer wishes to be on a mailing list.
Once you have written the classes, write the main program that prompts the user to enter data for each of the Customer object’s data attributes and create multiple object of the Customer class. The number of objects to be created is determined by the user. Store the data in the object, then use the object’s accessor methods to retrieve each of the object and display them on the screen in a tabular form.
INSTRUCTIONS:
Include all your solutions in a single .py file. When the code is executed, the following message should appear before start of each task.
Press any key to start Task n, where n is the task number (1, 2, or 3) There should be two blank lines before and after this message.
The file name should be ‘YourFirstNameLastName.py’.
Add a substantial amount of comments for each solution. Read the requirements in the syllabus.
All applications must be developed using Python 3.x.
At least 20% will be deducted for deviation from any instruction in this assignment or in the syllabus.
NOTE: I have completed answer for your question. Please check and let me know if you have any queries. I will get back to you within 24 hours. Thanks for your patience.
Table seem to be misaligned while taking screenshot. But when you run the program it will generate a formatted table. Please check.
Task.1:
1)
class:
class is a blue print of an object. It represents the structure of
an object and in general contains member variables and member
functions. The class is a way of organizing information about a
real-world objects like Car, Person, Employee etc. Below is the
description of how we define a class.
class Employee:
def get_emp_name(self):
return self.name
def set_emp_name(self, name):
self.name = name
Above is a simple class where variables starting with self like self.name are member or instance variables. Whereas the methods get_emp_name and set_emp_name are member functions.
2)
Instance:
Instance is an object created from a class. It actually represents
the state of an object. Even though class represents the structure
instance is the one which stores the information about member
variables in memory. For the above example, we can create an object
like below.
e = Employee()
e.set_emp_name('Ravi')
e.get_emp_name()
The first instruction defines an object of class Employee. Then calls set_emp_name method to set the name of an object and get_emp_name to retreive the name of an object set.
3)
Encapsulation:
Encapsulation is the basic fundamentals of Object Oriented
programming. It actually describes the process of wrapping data and
functions operating on it in a structure like class. An example for
encapsulation is the Employee class.
Encapsulation is used to hide the internal representation of an object i.e. data which we call as information hiding.
4)
Abstraction:
Abstraction refers to the process of exposing only required
interfaces and hiding the implementation details from the user.
This is acheived by binding data and functions together.
For example if we want to access any data about Employee name instead of directly setting the name the interface are method we use to set the employee name. Following which if we want to get the information we can use get_emp_name method to obtain the data.
5)
Inheritance:
Inheritance refers to the process of acquiring the property of
another class. For example children acquires the traits of his/her
parents. Using inheritance we can reuse methods and variables
defined in another class instead of redefining them again.
Inheritance promotes reusability where we use the existing class
instead of redefining the structure.
There are different types of inheritance possible like single, multiple, multilevel, hierarchial, hybrid etc.
6)
Polymorphism:
Polymorphism means single interface multiple forms. It is the
ability of an object to take multiple forms.
Example:
class Animal:
def makeSound(self):
print('Animal makes a sound')
class Pig(Animal):
def makeSound(self):
print('Pig makes a wee wee
sound')
class Dog(Animal):
def makeSound(self):
print('Dog makes a bow bow
sound')
def main():
an = animal()
pig = pig()
dog = dog()
an.makeSound()
pig.makeSound()
dog.makeSound()
main()
In the above example the same makeSound method makes different sound based on the class object is instantiated. This is an example of polymorphism where we have single interface makeSound but gives different behaviour.
7)
Multiple Inheritance:
Multiple inheritance is the process of acquiring properties from
multiple classes. It allows user to acquire properties from
multiple classes without redefining them. Below is an example.
class A:
def get_name(self):
return self.name
def set_name(self, name):
self.name = name
class B:
def get_phone_number(self):
return self.phone_number
def set_phone_number(self, phone):
self.phone = phone
class C(A, B):
def get_emp_details(self):
name = get_name()
phone = get_phone_number()
return name, phone
class C is an example of multiple inheritance where it has used the properties of class A and B such as setting/getting name, setting/getting phone number without redefining it. Multiple inheritance promotes reusability and maintainability.
Task.2:
Code:
#!/usr/local/bin/python3
class Person:
def set_details(self, name, address, phone):
self.name = name
self.address = address
self.phone = phone
def get_details(self):
return self.name, self.address,
self.phone
class Customer(Person):
def set_customer_details(self, cust_number,
is_wish_email):
self.customer_number =
cust_number
self.customer_wish =
is_wish_email
def get_customer_details(self):
return self.customer_number,
self.customer_wish
def main():
obj_list = list()
print('Enter how many objects required? ')
n = int(input())
for i in range(n):
cust = Customer()
print('Enter customer number?
')
cust_num = input()
print('Enter is customer wish to be
on mailing list? ')
wish_list = input()
print('Enter name of the customer?
')
name = input()
print('Enter address? ')
addr = input()
print('Enter phone number? ')
ph = input()
cust.set_customer_details(cust_num, wish_list)
cust.set_details(name, addr,
ph)
obj_list.append(cust)
print('='*180)
print('%20s %30s %30s %25s %10s' %('Name', 'Address',
'Phone', 'CustomerNumber',
'Wish_to_be_on_Email'))
print('='*180)
for obj in obj_list:
num, wish =
obj.get_customer_details()
name, addr, phone =
obj.get_details()
print('%20s %30s %30s %25s %10s' %
(name, addr, phone, num, wish))
print('='*180)
if __name__=='__main__':
main()
Code screenshot:
Code output screenshot:
IT 210: Assignment 4 TASK1: Define and explain the following concepts with examples: Class Instance Encapsulation...
Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...
*Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented programming using classes to create objects. PROBLEM DEFINITION: Write a class named Employee that holds the following data about an employee in attributes: name, IDnumber, department, jobTitle The class should have 8 methods as follows: For each attribute, there should be a method that takes a parameter to be assigned to the attribute. This is known as a mutator method. For each...
In Python Programming: Write a class named Car that has the following data attributes: _ _year_model (for the car’s year model) _ _make (for the make of the car) _ _speed (for the car’s current speed) The Car class should have an _ _init_ _ method that accepts the car’s year model and make as arguments. These values should be assigned to the object’s _ _year_model and _ _make data attributes. It should also assign 0 to the _ _speed...
Lab 10C - Creating a new class This assignment assumes that you have read and understood the following documents: http://www.annedawson.net/Python3_Intro_OOP.pdf http://www.annedawson.net/Python3_Prog_OOP.pdf and that you're familiar with the following example programs: http://www.annedawson.net/python3programs.html 13-01.py, 13-02.py, 13-03.py, 13-04.py Instructions: Complete as much as you can in the time allowed. Write a Python class named "Car" that has the following data attributes (please create your own variable names for these attributes using the recommended naming conventions): - year (for the car's year of manufacture)...
Assignment Requirements
I have also attached a Class Diagram that describes the
hierarchy of the inheritance and interface behaviors . The link to
the PDF of the diagram is below
MotorVehical.pdf
Minimize File Preview
User Define Object Assignment:
Create a Intellij Project. The
Intellij project will contain three user defined
classes. The project will test two of the User Define Classes by
using the invoking each of their methods and printing the
results.
You are required to create three UML...
Please help with a source code for C++ and also need screenshot of output: Step 1: Create a Glasses class using a separate header file and implementation file. Add the following attributes. Color (string data type) Prescription (float data type) Create a default constructor that sets default attributes. Color should be set to unknown because it is not given. Prescription should be set to 0.0 because it is not given. Create a parameterized constructor that sets the attributes to the...
C++ Programing In this exercise, you will design a class memberType. The class has the following data members: memberName. A string that holds the name of a person memberID. A string that holds the member identification number numBooks. An int that holds the number of books bought purchaseAmt. A double that holds the amount spent on books In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the person’s name and member...
Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing this assignment, students will practice Object Oriented design and programming by creating a Java program that will implement Object Oriented basic concepts. RetailItem Class: Part 1: Write a class named RetailItem that holds data about an item in a retail store. The class should have the following fields: • description. The description field references a String object that holds a brief description of the...
I need some help with programming this assignment.
Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to write a Python class Be able to define class attributes Be able to define class methods .Be able to process input from a text file .Be able to write an application using objects The goal of this programming assignment is to develop a simple image processing application. The application will import a class that creates image objects with...
Question 11 (20 points) Given the class Point below, define a class Circle that represent a circle with a given center and radius. The circle class should have a center attribute named center as well as a floating point radius attribute. The center is a point object, defined by the class Point. The class should also have these members: the constructor of the class, which should take parameters to initialize all attributes - a getter for center a setter for...