Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(please help me with this C++ code. this can be in the simplest form of C++ if possible. im having a hard time with this

(please help me with this C++ code. this can be in the simplest form of C++ if possible. im having a hard time with this assignment. thanks)

This assignment will work with abstract classes, pure virtual functions, regular virtual functions, pointers with dynamic binding and polymorphism.

This program will involve creating an abstract class named Shape with 3 pure virtual functions named printInfo(), getArea() and getPerimeter. There are also 2 regular virtual functions in Shape named getColor() and setColor().

There will be 2 derived classes: Circle and Rectangle that implement the printInfo(), getArea() and getPerimeter functions.

The main function will create Circle and Rectangle objects using pointers of the abstract class type and dynamic binding. Use the pointers to print out the general information and also the area and perimeter of each object.

Use the UML diagrams below to create your classes.

Shape

#color : string

+Shape() //set color to unknown

+Shape(string clr)

+getArea() : double //pure virtual function

+getPerimeter() : double //pure virtual function

+printInfo() : void //pure virtual function

+setColor(string clr) : virtual void //regular virtual will be coded

+getColor() : virtual string //regular virtual will be coded

Circle //inherits from Shape

-radius : double

+Circle() //set radius to zero; call Shape default constructor

+Circle(string clr, double rad)

+getArea() : double //area of circle is radius * radius * 3.14159

+getPerimeter() : double //calculate circumference as radius * 2 * 3.14159

+printInfo() : void //prints out: This is a circle with color: _____ and radius: _____

+getRadius() : double

+setRadius(double rad) : void

rectangle //inherits from Shape

-width : double

-height : double

+Rectangle() //set width and height to zero; call Shape default constructor

+Rectangle(string clr, double w, double h)

+getArea() : double //return width * height

+getPerimeter() : double //return (width * 2) + (height * 2)

+printInfo() : void //prints out: This is a rectangle with color: ____, width: ____ and height: _____

+getWidth() : double

+setWidth(double w) : void

+getHeight() : double

+setHeight(double h) : void

Step 1: Create header files for Shape, Circle and Rectangle with the class definition; create code files for the methods of Shape, Circle and Rectangle.

Step 2: Write the main function in a separate code file as follows:

The main function should create a Circle object with a radius set to some color and length of your choice; this must be done with a pointer of type Shape and using the reserved word, new. Example:

Shape *cptr = new Circle(red, 5.8);

Print out information about the circle using the pointer and the printInfo() method. Print out the area and perimeter of the circle object using the pointer and the getters.

Change the color of the samecircle object using the pointer and color setter (coded in Shape). Call printInfo() again to show the new color.

Create a Rectangle object also using a Shape type pointer and dynamic binding; call printInfo() and then print out the area and perimeter using the getters.

Step 3: Debug your program and get it running with correct output.

Step 4: Copy the code from all files into a Word document. Include a screenshot of the test run.

Step 5: Submit the Word document and the zipped project folder. All submittals should be named with a title including your last name.

Example output:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

User Defined Tensor Data Analysis

Authors: Bin Dong ,Kesheng Wu ,Suren Byna

1st Edition

3030707490, 978-3030707491

More Books

Students also viewed these Databases questions