QuestionQuestion

Design and write classes in a class hierarchy to describe different types of geometric shapes. Provide information in the classes in order to compute the area of each of the shapes. Create three separate classes (Triangle, Rectangle, Circle) that are derived from a separate base class (Shape). Write a program that allows a user to create any of the different shape types. Prompt the user to select the shape type and enter the necessary dimensions (i.e. refer to formulas below; rectangle needs width and height, circle needs radius, triangle needs height and base). After the user has finished creating the shape, compute and print out the area.

Use the following formulas for your program:

Triangle:
area = ½ * base * height
Rectangle:
area = width * height
Circle:
area = PI * radius2

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include "Rectangle.h"

Rectangle::Rectangle() {
    width = 0;
    height = 0;
}

Rectangle::Rectangle(const Rectangle& orig) {
    width = orig.width;
    height = orig.height;
}

Rectangle::~Rectangle() {
}

double Rectangle::getArea(){
    return width * height;
}

void Rectangle::setDimensions(){
    cin>>*this;
}

istream &operator>>(istream &stream, Rectangle &o){
    cout<<"\n";
    cout<<"Enter width: ";
    stream>>o.width;
    cout<<"Enter height: ";
    stream>>o.height;
    return stream;
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$20.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats