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 * * r pi r pi = 3.14159 def init_(self, name = 'Default', radius = 0): self._area = 0 self._name = name self._height = 'No need' self._radius = radius 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 _str_(self): return "Radius: "+str(self._radius) def sph = Sphere('Sphere', 5) print('. sph.calc_surface_area() print(sph) print('========: cyl = ') =====') Cylinder('Cylinder', 5, 10) print(' cyl.calc_surface_area() print(cyl)

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter11: More Object-oriented Programming Concepts
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question
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
def
= 3.14159
init_(self, name =
self._area
0):
Radius: 5, Height: No need
'Default', radius
= 0
Area: 314.159
self._name = name
self._height
self._radius
'No need'
radius
=======
====
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)
%3D
')
=====
')
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 def = 3.14159 init_(self, name = self._area 0): Radius: 5, Height: No need 'Default', radius = 0 Area: 314.159 self._name = name self._height self._radius 'No need' radius ======= ==== 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) %3D ') ===== ')
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
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
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
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
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,