Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write this c program STEP 2 The Requirements and Programming As is the case with anything in life, there are a couple of rules that

write this c program STEP 2 The Requirements and Programming As is the case with anything in life, there are a couple of rules that we need to play by It is imperative that you write your own code that is, you dont cut and paste from any of my examples, any of your existing code or any code found elsewhere! Having said that you can look at your notes and the lessons, you can look at how I might have done something within my code or how you might have done something within your code but resist the temptation to cut and paste I am trying to see what you can produce from scratch. For the Stage 1 deliverable, you will start with a blank (new) Visual Studio C++ project that has the following files : o myShape.cpp the test harness where your main() function will be o Shape.h and Shape.cpp the 2 source files where you will place your code for the Shape class o Circle.h and Circle.cpp where you will place your Circle class definition o Square.h and Square.cpp where you will place your Square class definition Sound simple enough? Lets get into the particulars In this exercise, you will be developing a Shape class, a Circle class and a Square class. As you may have guessed, Shape is the parent of Circle and of Square. Here are the details of these 3 classes: The Shape Class The class has the following data members o name a string-type1 data member large enough to hold a value of up to 50 characters allowed names are Circle, Square and Unknown o colour a string-type1 data member large enough to hold a value of up to 10 characters allowed colours include red, green, blue, yellow, purple, pink, orange and undefined The class should have the following methods o a constructor which takes values for the 2 data members and sets them o a default constructor sets the name to Unknown and the colour to undefined o accessors for each of the data members watch the return data type you dont want to allow anyone calling the accessor to be able to change the data members value!! HINT you want to make sure that you return your data member values as constant o a mutator for each of the data members your mutators do not need to pass back a succeed / fail status but they do need to validate the input to ensure that it is proper for that data member if it is not, then leave the attribute value as it was o 3 pure virtual functions called Perimeter(void), Area(void) and OverallDimension(void) o all methods are to be placed in the .CPP file The Circle Class Remember that this class is a child of the Shape class and will inherit publicly from it The class has the following data members o radius a float data-type used to hold the circles radius value (in centimeters) allowed values are greater than or equal to 0.00 The class should have the following methods o a constructor which takes values for the colour of the circle and its radius need to ensure that the radius value is valid no other input validation is necessary in this constructor o a default constructor 1 You can choose to use a char[] for this data member or a string object either way, you still need to be able to limit the maximum length to the size needed sets the radius to a value of 0.00 o a destructor that states The circle is broken o accessor for the data member o mutator for the data member your mutators do not need to pass back a succeed / fail status but they do need to validate the input to ensure that it is proper for that data member and if it is not, then leave the attribute as it was o a method called Show(void) which prints out the shapes name, colour, radius, perimeter and area as follows Shape Information Name : Circle Colour : red Radius : 3.56 cm Circumference : 22.37 cm Area : 39.82 square cm o Use the following formulae for your Perimeter(void) and Area(void) methods perimeter = 2r area = r2 where is 3.1415926 and r is the radius value o the OverallDimension(void) method should return the diameter of the circle (return the value 2r) o all methods are to be placed in the .CPP file The Square Class Remember that this class is a child of the Shape class and will inherit publicly from it The class has the following data members o sideLength a float data-type used to hold the side-length value (in centimeters) for the square allowed values are greater than or equal to 0.00 The class should have the following methods o a constructor which takes values for the colour of the square and its sideLength need to ensure that the sideLength value is valid no other input validation is necessary in this constructor o a default constructor sets the sideLength to a value of 0.00 o a destructor that states The square is squished o accessor for the data member o mutator for the data member your mutators do not need to pass back a succeed / fail status but they do need to validate the input to ensure that it is proper for that data member and if it is not, then leave the attribute as it was o a method called Show(void) which prints out the shapes name, colour, sideLength, perimeter and area as follows Shape Information Name : Square Colour : blue Side-Length : 10.50 cm Perimeter : 42.00 cm Area : 110.25 square cm o Use the following formulae for your Perimeter(void) and Area(void) methods perimeter = 4s area = s2 where s is the sideLength value o the OverallDimension(void) method should return the side-length of the square (return the value s) o All methods are to be placed in the .CPP file The TestHarness It is in this source file (myShape.cpp) that you place your main() function and drive all of the wonderful things that can be done with the various classes effectively testing your classes. You can use the source file (SampleMain.zip) Ive placed in eConestoga along with this exercise as a starting point if you like it has a couple of pre-written functions (C-Style) that you might want to use or you can develop your own In your mainline, I want you to simply create a circle object and a square object by o Asking the user for specifics about the shape you are trying to create Ask for the shapes colour Ask for the radius (in the case of the circle) and the side-length in the case of the square o As soon as you have this information from the user you can instantiate the shape Since you are getting user input before instantiating the objects, this means that you will need to dynamically instantiate the circle and square objects [HINT] I wish I new how to do this ! o Once both shapes have been instantiated, simply print out the specifics of each shape to the screen (using the Show() method) This is the end of this programming exercise make sure that your class definitions follow the requirements and that your testHarness works.

/*

Purpose: this source drives the use of the Shape, Circle and Square classes

*/

#include

#include

// local function prototypes

int getInteger(void);

float getFloat(void);

int getString(char* myString);

/* this is where you "do your magic ..." */

int main(void)

{

/* ... place your code here ... */

return 0;

}

// some useful functions

int getInteger(void)

{

char record[121] = {0}; /* record stores the string */

int number = 0;

/* use fgets() to get a string from the keyboard */

fgets(record, sizeof(record), stdin);

/* extract the number from the string; sscanf() returns

a number corresponding with the number of items it

found in the string */

if( sscanf(record, "%d", &number) != 1 )

{

/* if the user did not enter a number recognizable by

* the system, set number to -1 */

number = -1;

}

return number;

}

float getFloat(void)

{

char record[121] = {0}; /* record stores the string */

float number = 0.00;

/* use fgets() to get a string from the keyboard */

fgets(record, sizeof(record), stdin);

/* extract the number from the string; sscanf() returns

a number corresponding with the number of items it

found in the string */

if( sscanf(record, "%f", &number) != 1 )

{

/* if the user did not enter a number recognizable by

* the system, set number to -1.00 */

number = -1.00;

}

return number;

}

int getString(char* myString)

{

char record[121] = {0}; /* record stores the string */

int retCode = 0; /* success code */

/* use fgets() to get a string from the keyboard */

fgets(record, sizeof(record), stdin);

/* extract the number from the string; sscanf() returns

a number corresponding with the number of items it

found in the string */

if( sscanf(record, "%s", myString) != 1 )

{

/* if the user did not enter a number recognizable by

* the system, set number to -1 */

retCode = -1;

}

return retCode;

}

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_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Databases questions

Question

=+e) State the hypotheses (in words, not symbols).

Answered: 1 week ago