Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab assignment # 5 Topics: class, object, instantiation, basic inheritance Problem Statement: The purpose of this lab assignment is to gain experience in pythons inheritance

Lab assignment # 5
Topics: class, object, instantiation, basic inheritance
Problem Statement: The purpose of this lab assignment is to gain experience in pythons
inheritance feature
Your Task:
1. Create a class called Rectangle
a. Rectangle will contain 2 sides: Length and Width
b. Create the following methods for this class
i.__init__(self, length, width) will initialize the length and width of the
rectangle
ii.__str__(self) will print the dimension of the rectangle (please refer to
sample output below)
iii. area(self) will compute and return the area of the rectangle
iv. increase_size(self, l, w) will take in two parameter l and w. It will
increase length of rectangle by l units and width of rectangle by w units
2. Create a class called Cuboid. This class will be a sub-class of Rectangle.
a. Cuboid will contain 3 sides: Length and Width (inherited from Rectangle) and
additional attribute Depth.
b. Create the following methods for this class
i.__init__(self, length, width, depth) will initialize the length, width, and
depth of the cuboid.
ii.__str__(self) will print the dimensions of the cuboid
iii. volume(self) will compute the volume of the cuboid
iv. increase_size(self, l, w, d) will take three parameters l, w, and d. It will
increase the length by l units, width by w units, and depth by d units.
c. All methods will require to use of the super() function. Not using this function in
your solution will be counted as incorrect implementation.
3. Object creation:
a. Create a rectangle object r1 with dimension length =1 and width =2
i. Print r1
ii. Print its area
iii. Increment its dimensions by 1
iv. Print r1 again
v. print its new area
b. Create a cuboid object c1 with dimension length =1, width =2 and depth =3
i. Print c1
ii. Print its volume
iii. Increment its dimensions by 1
iv. Print c1 again
v. Print its new volume
Sample Output
length =1
width =2
Initial area of r1 is 2
length =2
width =3
New area of r1 is 6
length =1
width =2
depth =3
Initial volume of c1 is 6
length =2
width =3
depth =4
New area of c1 is 24
Submission:
1. All submission will be via Blackboard during the lab time
2. You can take help from the GTA and/or you can look at the class resources: lecture
slides, class note, python documentation.
3. The codes need to be written in the firstname_lastname_LA5.py file.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions