here is the question
thetype of class mentioned on the notes
programminglanguage pyhthon2. Based on the pre-exisiting code for the Shape classes. Add a new shape class called Rectangle that implements a common rectangle. Carefully consider the appropriate class to use as a parent to maximise code reuse. 1 ### Define a polygon class ### 2 class Regular Polygon (Shape): # Special initialisation method def __init__(self, argl): # All polygons defined by number and # length of their sides self.length = argl self. num Sides = 0 Shape. –init –(self) def print Sides (self): print(“Shape has”, self.numSides,” sides”) return Listing 10.6: Regular Polygon class Finally, the Shape class can be implemented as shown in Listing 10.7 This class is the base class for all types of shape and performs the important duty of ensuring that the area of the shape is calculated at instantiation time. The init() method on line 3 is explicitly called by the ..init() methods of the Circle class (line 6 of Listing 10.5) and the Regular Polygon class (line 9 of Listing 10.6). This method calls the appropriate calcArea() method depending on the child class. A data member area is defined thus any class that inherits from Shape will also have this data member. 1### Define a generic shape class ### 2 class Shape : def –init.- (self): self. area = self. calc Area Listing 10.7: Shape class We were unable to transcribe this image1##### Main body ##### 3 # Create instances of various shapes 4 tr = EqiTriangle (5) 5 sq = Square (7) 6 pt = Pentagon (4) 7 C = Circle (6) 9 # Store shapes in a list 10 shapeList = [tr, sq, pt, c] 11 12 # Iterate through list to print area 13 for item in shape List: 14 item.print Area () Listing 10.8: Polymorphism Listing 10.8 demonstrates the power of polymorphism: different types of object can be requested to perform the same general set of operations through a common interface (i.e. a common method call). What would happen if the main body of code were modified to call the method printSides() instead of printAreal), as shown in Listing 10.9 Modify your code accordingly and test it. 1 # #### Main body # #### 3 # Create instances of various shapes 4 tr = EqiTriangle (5) 5 sq = Square (7) 6 pt = Pentagon (4) 7 C = Circle (6) 9 # Store shapes in a list 10 shape List = [tr. sq. pt. c] 12 # Iterate through list to print num sides 13 for item in shape List: 14 item.printSides ( Show transcribed image text 2. Based on the pre-exisiting code for the Shape classes. Add a new shape class called Rectangle that implements a common rectangle. Carefully consider the appropriate class to use as a parent to maximise code reuse.
1 ### Define a polygon class ### 2 class Regular Polygon (Shape): # Special initialisation method def __init__(self, argl): # All polygons defined by number and # length of their sides self.length = argl self. num Sides = 0 Shape. –init –(self) def print Sides (self): print(“Shape has”, self.numSides,” sides”) return Listing 10.6: Regular Polygon class Finally, the Shape class can be implemented as shown in Listing 10.7 This class is the base class for all types of shape and performs the important duty of ensuring that the area of the shape is calculated at instantiation time. The init() method on line 3 is explicitly called by the ..init() methods of the Circle class (line 6 of Listing 10.5) and the Regular Polygon class (line 9 of Listing 10.6). This method calls the appropriate calcArea() method depending on the child class. A data member area is defined thus any class that inherits from Shape will also have this data member. 1### Define a generic shape class ### 2 class Shape : def –init.- (self): self. area = self. calc Area Listing 10.7: Shape class
1##### Main body ##### 3 # Create instances of various shapes 4 tr = EqiTriangle (5) 5 sq = Square (7) 6 pt = Pentagon (4) 7 C = Circle (6) 9 # Store shapes in a list 10 shapeList = [tr, sq, pt, c] 11 12 # Iterate through list to print area 13 for item in shape List: 14 item.print Area () Listing 10.8: Polymorphism Listing 10.8 demonstrates the power of polymorphism: different types of object can be requested to perform the same general set of operations through a common interface (i.e. a common method call). What would happen if the main body of code were modified to call the method printSides() instead of printAreal), as shown in Listing 10.9 Modify your code accordingly and test it. 1 # #### Main body # #### 3 # Create instances of various shapes 4 tr = EqiTriangle (5) 5 sq = Square (7) 6 pt = Pentagon (4) 7 C = Circle (6) 9 # Store shapes in a list 10 shape List = [tr. sq. pt. c] 12 # Iterate through list to print num sides 13 for item in shape List: 14 item.printSides (
Expert Answer
Answer to here is the question the type of class mentioned on the notes programming language pyhthon …