In the previous exercise, you used the C++ visual development tools to view the hierarchy of the C++ Shapes project. You can also use the C++ visual development tools to add classes to a project, or to add properties and methods to a class. In this exercise, you add the getCircumference method to the circle and sphere classes. The getCircumference method calculates the circumference of the shape and circle by using the radius.
Add the getCircumference method to the circle class
The formula that calculates the circumference of a circle is πr², where r is the radius of the circle. The global constant π is stored in the base shape class.
To add the getCircumference method to the circle class:
To add the getCircumference method to the sphere class:
To run the Shapes application:
Enter the radius of the sphere: 10 Enter the color of the sphere: Blue Sphere: Radius = 10 Circumference = 62.8319 Area = 1256.64 Volume = 4188.79 Color = Blue
The program displays the size and color of the current shape and prompts you to specify values for the new shape. The attributes of the new shape are displayed in the Console view. You can modify the code in main.cpp to run the circle class.