Inheritance shape hierarchy | Business & Finance homework help

  

Inheritance – Shape hierarchy
 

Necessary skills: Class inheritance, Member function overriding (virtual functions), Dynamic binding, Multiple classes (separate source and header files), C++ Standard Library string, iostream, iomanip, stringstream classes
 

Description
 

In this assignment, you’ll create a hierarchy of C++ classes representing various shapes (eg. circle, rectangle, square). Each class will have its own .cpp source file and .h header file..
 

For the Shape class hierarchy, create an abstract Shape class that will be the base class of all the other shapes. It should have one private std::string instance variable representing the shape’s color, and should have the following public member functions:
 

Shape(const string& color) – a constructor that sets the color instance value.
string getColor() – a const member function returning the object’s color value.
double area() – a const pure virtual member function that computes and returns the object’s area. It must be overridden in each derived class.
string toString() – a const pure virtual member function that returns the shape’s description (color, type, measurements, and area) as a std::string. It must be overridden in each derived class. See the example output below for the format.
Create a Circle class that is derived from Shape. It should have one private double instance variable representing the radius, and should have the following public member functions:
 

Circle(const string& color, double radius) – a constructor that invokes the base Shape constructor (passing the color), then sets it’s own radius instance value.
double area() – this overriding member function computes and returns the Circle object’s area value.
string toString() – this overriding member function returns the Circle object’s description (color, type, measurements, and area).
Create a Square class with one private double instance variable representing the side length, with a constructor and overriding member functions for area() and toString().
 

Create a Rectangle class with double instance variables representing the width and length, with a constructor and overriding member functions for area() and toString().
 

Each derived class .h header file should #include the base Shape.h header. Each derived class .cpp source file should #include its header (e.g. Circle.cpp has a #include Circle.h), plus the other header files needed (eg. iomanip, strstream)
 

Each derived class constructor must use the constructor initializer syntax to call the base Shape constructor with the color parameter.
 

Derived classes do not provide a member function override for getColor(). The base Shape class implementation is inherited.
 

All character data is held using std::string from the C++ Standard Library (no char* or char arrays).
 

All toString() methods use a local std::ostringstream object to format the output (using manipulators) using output stream syntax (<< insertion operators), and return the string contents of the ostringstream. These methods do not write any output, just return the formatted string (as shown below in the example) – the main program does the actual output of the string. The toString() methods will call their area() methods to obtain the area value to be formatted.
 

getShape.cpp
 

For reading shape data, create a getShape.cpp file containing a getShape() function that returns a base Shape * pointer. It should read a shape description from an input stream, create the correct type of derived shape with the new operator and parameters to the constructor, and return a base Shape * pointer to the new object. After reading a shape color and type (e.g. blue circle), it reads the additional information specific to that type of shape (e.g. for a circle, it reads the radius), and then uses the new operator to create the specific derived type of shape (e.g. new Circle(color, radius) )
 

Input can be from cin, or from a stream input file (use iostreams). When there is no more input data (or when ‘done’ is entered), return a NULL Shape pointer. All character data is kept in C++ strings (no char[] arrays).
 

This is the only file that #includes the Circle.h, Square.h, and Rectangle.h header files (since it needs them to create the various types of shapes with the new operator).
 

main.cpp
 

The main.cpp file contains the main() function. It defines an array of base Shape pointers, and loops calling getShape() and storing the returned Shape pointer into the next available element of the array. The loop completes when a NULL Shape pointer is returned from getShape.
 

Note that the array contains pointers that point to a variety of derived shape objects (circles, squares, rectangles). This is possible because of the IS-A public inheritance relationship (e.g. a Circle IS-A Shape, and thus has all the properties and behaviors of a Shape).
 

Once all the shapes have been read, main() then loops, printing the list of shapes by calling the toString() member function on each Shape* pointer in the

Punctual Essays
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

casibom giriş adresi
avia masters
polskie kasyno online
sugar rush 1000
neyine giriş
pinco giriş