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)
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
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images
Knowledge Booster
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.Recommended textbooks for you
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,