Question: 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 #
Topics: class, object, instantiation, basic inheritance
Problem Statement: The purpose of this lab assignment is to gain experience in pythons
inheritance feature
Your Task:
Create a class called Rectangle
a Rectangle will contain sides: Length and Width
b Create the following methods for this class
iinitself length, width will initialize the length and width of the
rectangle
iistrself will print the dimension of the rectangle please refer to
sample output below
iii. areaself will compute and return the area of the rectangle
iv increasesizeself 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
Create a class called Cuboid. This class will be a subclass of Rectangle.
a Cuboid will contain sides: Length and Width inherited from Rectangle and
additional attribute Depth.
b Create the following methods for this class
iinitself length, width, depth will initialize the length, width, and
depth of the cuboid.
iistrself will print the dimensions of the cuboid
iii. volumeself will compute the volume of the cuboid
iv increasesizeself 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.
Object creation:
a Create a rectangle object r with dimension length and width
i Print r
ii Print its area
iii. Increment its dimensions by
iv Print r again
v print its new area
b Create a cuboid object c with dimension length width and depth
i Print c
ii Print its volume
iii. Increment its dimensions by
iv Print c again
v Print its new volume
Sample Output
length
width
Initial area of r is
length
width
New area of r is
length
width
depth
Initial volume of c is
length
width
depth
New area of c is
Submission:
All submission will be via Blackboard during the lab time
You can take help from the GTA andor you can look at the class resources: lecture
slides, class note, python documentation.
The codes need to be written in the firstnamelastnameLApy file.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
