Task - 6 Given the following class, write the code for the Sphere and the Cylinder class so that the following output is printed. | OUTPUT: Shape name: Sphere, Area Formula: 4 * pi * r class Shape3D: pi = 3.14159 def _init_(self, name = 'Default', radius = 0): self._area = 0 self._name = name self._height = 'No need' self._radius = radius *r Radius: 5, Height: No need Area: 314.159 ============== ============= Shape name: Cylinder, Area Formula: 2 * pi r * (r + h) def calc_surface_area(self): return 2 * Shape3D.pi * self._radius Radius: 5, Height: 10 Area: 471.2385 def _str_(self): return "Radius: "+str(self._radius) sph = Sphere('Sphere', 5) print('- sph.calc_surface_area() print(sph) print('======-: cyl = Cylinder('Cylinder', 5, 10) print('- cyl.calc_surface_area() print(cyl) ') ==== =========') ')

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

solve Using Python 3 and inheritance method. ***DO NOT GIVE THE WRONG ANSWER**** ***DO NOT CHANGE THE CODE****

Task - 6
Given the following class, write the code for the Sphere and the Cylinder class so that
the following output is printed.
class Shape3D:
OUTPUT:
Shape name: Sphere, Area Formula: 4 * pi * r
* r
pi = 3.14159
def _init_(self, name =
self._area = 0
self._name = name
self._height = 'No need'
self._radius = radius
'Default', radius
0):
Radius: 5, Height: No need
Area: 314.159
====
=====
Shape name: Cylinder, Area Formula: 2 * pi
r * (r + h)
def calc_surface_area(self):
return 2 * Shape3D.pi * self._radius
Radius: 5, Height: 10
Area: 471.2385
def _str_(self):
return "Radius: "+str(self._radius)
Sphere ('Sphere', 5)
sph
print('----
sph.calc_surface_area()
print(sph)
print('====
cyl = Cylinder('Cylinder', 5, 10)
print('
cyl.calc_surface_area()
print(cyl)
- ')
Transcribed Image Text:Task - 6 Given the following class, write the code for the Sphere and the Cylinder class so that the following output is printed. class Shape3D: OUTPUT: Shape name: Sphere, Area Formula: 4 * pi * r * r pi = 3.14159 def _init_(self, name = self._area = 0 self._name = name self._height = 'No need' self._radius = radius 'Default', radius 0): Radius: 5, Height: No need Area: 314.159 ==== ===== Shape name: Cylinder, Area Formula: 2 * pi r * (r + h) def calc_surface_area(self): return 2 * Shape3D.pi * self._radius Radius: 5, Height: 10 Area: 471.2385 def _str_(self): return "Radius: "+str(self._radius) Sphere ('Sphere', 5) sph print('---- sph.calc_surface_area() print(sph) print('==== cyl = Cylinder('Cylinder', 5, 10) print(' cyl.calc_surface_area() print(cyl) - ')
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning