C++
Define a class called Shape. The shape class will hold different
information about different
shapes. Specifically, each Shape object will contain:
• a letter to indicate the shape ('c' for circle, 's' for square,
or 'h' for hexagon)
• one integer variable for the dimension needed (representing the
radius of the circle, one
side of the square, or one side of the hexagon)
• a floating point value for area (used only internally - no
accessors nor mutators needed)
There should be the following member functions:
• a default constructor that has default values for the private
member variables ('n' for the
shape character and 0 for the dimension and area)
• accessors for the 3 private member variables,
• mutators for the character for shape and for the dimension
• a private member function that computes the area --- to be called
whenever a constructor
is used and whenever the dimension is changed using a mutator
function
Create a driver file that tests all functions and all computations
for area. Code the test into your
file, don't rely on user input!
Overload the following operators for the Shape class:
• == checks to see if the types of shapes are the same and have the
same dimension. NOTE: You
do not have to check to make sure the areas are the same.
• += checks to make sure the types of shapes are the same, then
changes the dimension of the
operand on the left of the operator to be the sum of the old
dimension value of the left operand
and the dimension of the right operand. The function should update
the value of area.
• != returns true if the types of shapes are different or, if the
same shape types, have dimension
values that are different
• + checks to make sure the shape types are the same. If they are,
a new Shape object is created,
its type set to the same type as the two operands to the right of
the =, sets the dimension to the
sum of the dimensions of the 2 operands, and computes the area
(calling the helper function).
Your program MUST include a test plan in the comments, detailing
what values will be tested with each
operator and what the output should be. Be sure to test your
operators thoroughly.
Be sure to prevent the user from trying to create a shape with a
dimension <= 0 or with a character for
shape other than 'c', 's', or 'h'
C++ Define a class called Shape. The shape class will hold different information about different shapes. Specifically, e
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
C++ Define a class called Shape. The shape class will hold different information about different shapes. Specifically, e
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!