Question 1: For the class hierarchy for the figure given below: 1. The Shape class has getArea() and getVolume( pure vir

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Question 1: For the class hierarchy for the figure given below: 1. The Shape class has getArea() and getVolume( pure vir

Post by answerhappygod »

Question 1 For The Class Hierarchy For The Figure Given Below 1 The Shape Class Has Getarea And Getvolume Pure Vir 1
Question 1 For The Class Hierarchy For The Figure Given Below 1 The Shape Class Has Getarea And Getvolume Pure Vir 1 (72.46 KiB) Viewed 114 times
Question 1 For The Class Hierarchy For The Figure Given Below 1 The Shape Class Has Getarea And Getvolume Pure Vir 2
Question 1 For The Class Hierarchy For The Figure Given Below 1 The Shape Class Has Getarea And Getvolume Pure Vir 2 (31.23 KiB) Viewed 114 times
Question 1: For the class hierarchy for the figure given below: 1. The Shape class has getArea() and getVolume( pure virtual functions. 2. The Circle is a Shape that overrides the getArea() function to return the area of the circle. The circle has a center (x and y) and radius r. The volume of the circle is always 0. 3. The Rectangle is a Shape that overrides the getArea() function to return the area of the rectangle. The Rectangle has width and length; the volume of the rectangle is always 0. 4. The Cuboid is a Shape with width, length and height as members and overrides the getArea() and getVolume() functions to return the area and volume of the cuboid. 5. Since we will delete the objects using the pointer of the parent class type, the destructors should be virtual, otherwise only the destructor of the parent class will be called and hence if you allocated memory in the child class constructor it will not be deleted (memory leak will occur). Print the following message in the destructors "I am dying (className]" replace (className] by the name of class to which the destructor belongs. Shape Circle Rectangle Cuboid . . In the main function create an array of Shape pointers, make them to point to different objects of type Circle, Rectangle and Cuboid, then using print areas and volumes of each objects Circle: Circle Area = 3.14 * radius * radius Rectangle: Area - side length * side length Cube: Area - 2*W*L + 2*H*L+2*W*H Volume = W*L*H: Test your classes with the following main: int main() { Shape* sh[3]; sh[0] = new Circle(0,0,5); sh[1] = new Rectangle(5, 4); sh [2] = new Cuboid(5,4,6); for (int i = 0; i < 3; i++)

Volume - W*L*H Test your classes with the following main: int main() { Shape* sh[31; sh[0] = new Circle(0,0,5); sh[1] = new Rectangle(5,4); sh[2] = new Cuboid(5,4,6); for (int i = 0; i < 3; i++) { cout << "Shapel" «i<"Areal" << sh(i)->getArea() << " Volume" << sh(i)->getVolume() << "l \n"; < for(int i=0;i<3; i++) delete shtil: } } You should get the output below: Shape [0] Area [78.5] Volume[0] Shape[1] Area(20) Volume [0] Shape[2] Area(148] Volume[120] I am dying Circle] I am dying Shape! I am dying [Rectangle] I am dying (Shape) I am dying [Cuboid) I am dying (Shape)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply