Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will implement 2 classes named Triangle and Circle. All names will be exactly as specified here, case included. You will submit a .cpp file

You will implement 2 classes named Triangle and Circle. All names will be exactly as specified here, case included. You will submit a .cpp file and a .h file for each of these classes. The submission is 4 files total. You will write your own test driver to exercise and test these classes but you will not submit the test driver to me. I will have my own test driver and will plug your classes into my project to test them. General note Make sure all the integers receive positive values. If a negative value is given, handle it gracefully. Suggestions include convert it to a positive value of the same magnitude (change -1 to 1), or provide a default value and issue an error message. See note about the Triangle::GetArea() function make sure this doesnt crash and do error checking as described. The Triangle class will contain the following private data: integer side1 integer side2 integer side3 The triangle classes will contain 2 constructors and one destructor. The destructor in this case will simply display a parting message (Ex: Good bye cruel world! You wont have the Triangle to kick around anymore!) The constructors will be: A default constructor with no arguments. It will provide default values to the member variables Another constructor will take 3 integers as arguments and will set the member variables to those values. The Triangle class will contain the following public functions: Function name Return type Argument(s) Description GetSide1() integer None Returns the integer member variable side1 SetSide1() void integer Sets the member variable side1 to the integer argument passed GetSide2() integer None Returns the integer member variable side2 SetSide2() void integer Sets the member variable side2 to the integer argument passed GetSide3() integer None Returns the integer member variable side3 SetSide3() void integer Sets the member variable side3 to the integer argument passed GetArea() float None Calculates the area of the triangle from the member data of the length of the sides of the triangle. If the values for the sides produce invalid results, return 0 and output a meaningful error statement. GetPerimeter() integer None Calculates the perimeter length of the triangle from the member data of the length of the sides of the triangle The Circle class will contain the following private data: integer radius string fillColor string borderColor Constant float PI, assigned the value of PI to 5 decimal places The Circle class will contain 2 constructors and one destructor. The destructor in this case will simply display a parting message (Ex: Help me, Im melting!) The constructors will be: A default constructor with no arguments. It will provide default values to the member variables Another constructor will take 1 integer and 2 strings as arguments and will set the member variables to those values. The Circle class will contain the following public functions: Function name Return type Argument(s) Description GetRadius() integer None Returns the integer member variable radius SetRadius() void integer Sets the member variable radius to the integer argument passed GetFillColor() string none Returns the member variable fillColor SetFillColor() void string Sets the member variable fillColor to the string argument given. GetBorderColor() string none Returns the member variable borderColor SetBorderColor() void string Sets the member variable fillColor to the string argument given. GetArea() float None Calculates the area of the from the member data of the radius of the circle. GetPerimeter() integer Non Calculates the perimeter length of the triangle from the member data of the length of the sides of the triangle If the Circle class needs any functions to do its work internally, they will be private.

For the second half of program 1, you will modify your Triangle and Circle classes created for Program 1A to inherit from a new base class called Shape. As before, all names will be exactly as specified here, case included. You will submit a .cpp file and a .h file for each of these three classes and each file will be named the exact name of the class; the submission is 6 files total. You will write your own test driver to exercise and test these classes but you will not submit the test driver to me. I will have my own test driver and will plug your classes into my project to test them. I would like for you to zip the following files and submit the zip file. The files you zip must have the following names: Shape.cpp Shape.h Triangle.cpp Triangle.h Circle.cpp Circle.h You will have some methods in the base class (Shape) that the derived classes (Triangle and Circle) will override to provide results specific to their particular shape. They are the previous functions already in place: GetArea() and GetPerimeter. Both of these will return 0 when the Shape class is instantiated because there is no information to calculate them with. There will be two methods in the base class, SetShapeType() and SetNumSides() that will be assigned the access level protected, rather than private or public. This allows the derived classes to set those values in their constructors, but the user/calling code cant change them. In essence I want to, in my calling code, be able to create objects of each of these 3 types (Shape, Triangle or Circle) and retrieve the available information on them. Shape default values: Not much can be told about a non-specific shape, so on instantiation (in the default constructor) the following default values will be set: shapeType = "undefined shape"; numSides = 0; borderColor = "clear"; fillColor = "clear"; And the overridden methods will return: GetArea() returns 0.0 GetPerimeter() = returns 0 Triangle default values: The triangle is being simplified over Program1A! It will now be an equilateral triangle (all sides the same) with only one side value as a data member. Perimeter and area calculations will need to be updated accordingly. Set in both constructors: shapeType = triangle always exactly this numSides = 3 always exactly this borderColor - pick a default value that is set in both constructors. User can set or retrieve at will. Triangle should have its own unique default color on instantiation. fillColor same as above side = 2 Circle default values: The circle class must eliminate the member variables that shape now handles (both the colors and their getters and setters) Set in both constructors: shapeType = circle always exactly this numSides = 1 always exactly this borderColor - pick a default value that is set in both constructors. User can set or retrieve at will. Circle should have its own unique default color on instantiation. fillColor same as above radius = 1 Example calling code (the test driver, for example) : #includeCircle.h #includeTriangle.h #includeShape.h ... Triangle triangle1; Circle circle1; Shape shape1; // call the appropriate methods and get the appropriate results on each // object. For example, shape1s perimeter should be 0, triangle1s // perimeter would be 6 and circle1s perimeter would be 6. Specific requirements for each class The Shape base class requirements: The shape class will contain the following private data: string shapeType Allowable values: undefined shape, triangle or circle int numSides Values: 0, 1 or 3 string fillColor moved from the previous Circle class definition, can have any string value. string borderColor Moved from the previous Circle class definition, can have any string value. The shape class will contain 1 default constructor and one destructor. The destructor in this case will simply display a parting message The default constructor will set the following values: shapeType = "undefined shape"; numSides = 0; borderColor = "clear"; fillColor = "clear"; The shape class will contain the following public (unless specified protected) functions: Shape class functions that replace ones previously in the Triangle or Circle classes: Function name Return type Argument(s) Description GetFillColor() string none Returns the member variable fillColor SetFillColor() void string Sets the member variable fillColor to the string argument given. GetBorderColor() string none Returns the member variable borderColor SetBorderColor() void string Sets the member variable fillColor to the string argument given. New Shape class getters and setters for new member data: Function Name Return Type Argument(s) Description GetShapeType() string returns member variable shapeType, which either receives the value undefined shape if a direct shape constructor was called or it receives a shape-defined value (triangle or circle) from a derived class. SetShapeType() void string Protected access. Sets the value of member variable shapeType presumably as called by a derived class. GetNumSides() Int None Returns member variable numSides, which will be 0, 1 or 3 if set by the Shape, Circle or Triangle classes respectively. SetNumSides() Void integer Protected access. Sets member variable numSides, as described above. Shape class functions that will be implemented in the shape class and will also be overridden by the derived classes: Function Name Return Type Argument(s) Description GetArea() float None Shape class returns 0.0 GetPerimeter() integer None Shape class returns 1

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

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions