When writing C++ programs include comments in your code, make the program readable by indenting, use meaningful variable and function names, give end users instructions on what the program does and produce meaningful output.
Program: 20 points – shapes1.cpp
Create the following class hierarchy
-
Shape has nothing in it for now, we will add stuff to shape next assignment. Just the begin/end and semicolon {};
-
Circle class, you can grab from CS 112 Wed. Sep. 30th slide #16 or #17. Make this circle class a derived class of Shape. Rename calc_circum to calc_perimeter, this will be done so we have matching method names in all our objects (since circumference is really a circle’s perimeter it is okay to rename this). You can remove the constructors and the destructor methods if you want as we will just be using the default methods for these.
-
Sphere class, you will make as a derived class of Circle. You will add member function calc_volume and override parent’s member function calc_area. NO new data, you will use the radius from circle that you inherit.
calc_volume will return the value from the sphere volume formula 4.0/3.0*3.14*radius*radius*radius;
calc_area will return the value from the sphere area formula 4.0*3.14*radius*radius; -
Rectangle class, you will make as a derived class of Shape. The object will have length and width. You will have to create the following methods – store_sides, return_sides (or two return sides), calc_area (length*width), calc_perimeter (2*length + 2*width).
-
Square class, you will make as a derived class of Rectangle. You will need to create two methods store_side and return_side (one side only). NO new data, you will use the length and width inherited from Rectangle. You will also use the calc_area and calc_perimeter methods inherited from Rectangle for output.
When the program runs, you will prompt for the type of shape to enter – then using a switch/case statement you will create the requested object, prompt for the required values for the type of object requested, then print out the perimeter (volume for sphere) and the area. You program should prompt for unlimited number of objects, meaning your switch/case will need to be in a while loop – allowing the user to quit when entering a ‘Q’.
Example program run:
This program will ask for a shape and calculate the area and perimeter (or volume).
What shape do you want to enter (c=Circle, p=Sphere, r=Rectangle, s=Square, q=Quit) ?c
Enter Radius of your Circle :5
The Circle
with radius of 5
has a perimeter of 31.4
and has an area of 78.5
What shape do you want to enter (c=Circle, p=Sphere, r=Rectangle, s=Square, q=Quit) ?p
Enter Radius of your Sphere :6
The Sphere
with radius of 6
has a volume of 904.32
and has an area of 452.16
What shape do you want to enter (c=Circle, p=Sphere, r=Rectangle, s=Square, q=Quit) ?r
Enter Length and Width of your Rectangle :4 5
The Rectangle
with length of 4 width of 5
has a perimeter of 18
and has an area of 20
What shape do you want to enter (c=Circle, p=Sphere, r=Rectangle, s=Square, q=Quit) ?s
Enter side of your Square :6
The Square
with sides of 6
has a perimeter of 24
and has an area of 36
What shape do you want to enter (c=Circle, p=Sphere, r=Rectangle, s=Square, q=Quit) ?d
Invalid option
What shape do you want to enter (c=Circle, p=Sphere, r=Rectangle, s=Square, q=Quit) ?q
For a custom paper on the above topic, place your order now!
What We Offer:
• On-time delivery guarantee
• PhD-level writers
• Automatic plagiarism check
• 100% money-back guarantee
• 100% Privacy and Confidentiality
• High Quality custom-written papers
Is this question part of your Assignment?
We can help
Our aim is to help you get A+ grades on your Coursework.
We handle assignments in a multiplicity of subject areas including Admission Essays, General Essays, Case Studies, Coursework, Dissertations, Editing, Research Papers, and Research proposals
Header Button Label: Get Started NowGet Started Header Button Label: View writing samplesView writing samples