Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write all the code necessary to implement the SpaceObject class as given in the following section. Note that it makes use of a Point type
Write all the code necessary to implement the SpaceObject class as given in the following section. Note that it makes use of a Point type which youll need to define. A Point should be a struct that contains an x and y coordinate both doubles We use this to store both locations and velocities vectors stored using xy values Your project should be called polygons. well build on this over the next few assignmentsYour class definition and implementation should be in separate files.When complete, you should have the following three files:spaceObject.h class definition also should include Point definitionspaceObjectcpp class implementation spaceObjectTest.cpp includes a main that tests the SpaceObject class codeWhat you will do:Create a project named polygons and add the three files listed above to it in the appropriate locations.Copy the text given below constants struct, SpaceObject enum and SpaceObject class definition into your spaceObject.h file and add appropriate include guards to itAdd documentation to each of the functions in the header file details about the functions are given in the table following the class definition.Implement each function one at a time, and test each function implementation as you go Write the default constructor and dumpData then add a line in main to create an object using that constructor and call dumpData to verify the member variables are all as they should beThen implement the next constructor and test itRepeat with each member function until all have been implemented and tested.Following are the definitions for Point, SpaceObjType, and SpaceObject, which you should put in spaceObject.h and document! Details about each of the SpaceObject functions are provided below the class definition. const int SCREENWIDTH;const int SCREENHEIGHT;struct Point double x;double y;;enum SpaceObjType SHIP, ASTEROID, PHOTONTORPEDO ; class SpaceObject public:SpaceObject;SpaceObjectSpaceObjType type, double radius, Point location, Point velocity, double angle;mutatorsbool setRadiusdouble radius;bool setLocationdouble x double y;bool setVelocitydouble velocityX, double velocityY;bool setAngledouble angDeg;change angle by given amount.void changeAngledouble deltaDeg;accessorsdouble getRadius const;Point getLocation const;Point getVelocity const;double getAngle const;othersvoid updatePosition;void dumpData const; prints objects data to cout for testingprivate: SpaceObjType type; type of objectPoint location; current location xyPoint velocity; current velocity in pixelsframedouble angleDeg; angle object is facing in degreesdouble radius; gross radius of object for collision detection;The functions should do the following:SpaceObject initialize all member variablestype should be set to ASTEROIDradius should be set to Other member variables should be given some reasonable values.SpaceObject that accepts parameters.Initialize all member variables to the given values, or if values are invalid, use reasonable default values. All Mutators Validate values given and use them to set associated member variables.setRadiusr if given value is negative or screen height, ignore it and return false..setLocationxy if given values are outside screen range defined by constants adjust them if necessary to remain in bounds by addingsubtracting screen size values from them. These corrections make the object reappear back on the opposite side of the window if it goes off the edge.All Accessorsreturn copies of requested dataupdatePositionUpdates the location based on the current velocity. adds the velocity vector values xy to the location Make sure the resulting location is within screen range rather than repeat the validation here, you should call setLocation and pass it the new computed values.You should write and test each function thoroughly before moving to the next function. main should be in spaceObjectTest.cpp and will consist of code that simply tests your class code, calling functions with test values and displaying the results. A beginning of this is below. int mainSpaceObject asteroid;asteroid.dumpData;asteroid.setLocation;asteroid.dumpData;TODO: add more test code. Lots more test code.
Write all the code necessary to implement the SpaceObject class as given in the following section. Note that it makes use of a Point type which youll need to define. A Point should be a struct that contains an x and y coordinate both doubles We use this to store both locations and velocities vectors stored using xy values Your project should be called polygons. well build on this over the next few assignmentsYour class definition and implementation should be in separate files.When complete, you should have the following three files:spaceObject.h class definition also should include Point definitionspaceObjectcpp class implementation spaceObjectTest.cpp includes a main that tests the SpaceObject class codeWhat you will do:Create a project named polygons and add the three files listed above to it in the appropriate locations.Copy the text given below constants struct, SpaceObject enum and SpaceObject class definition into your spaceObject.h file and add appropriate include guards to itAdd documentation to each of the functions in the header file details about the functions are given in the table following the class definition.Implement each function one at a time, and test each function implementation as you go Write the default constructor and dumpData then add a line in main to create an object using that constructor and call dumpData to verify the member variables are all as they should beThen implement the next constructor and test itRepeat with each member function until all have been implemented and tested.Following are the definitions for Point, SpaceObjType, and SpaceObject, which you should put in spaceObject.h and document! Details about each of the SpaceObject functions are provided below the class definition. const int SCREENWIDTH;const int SCREENHEIGHT;struct Point double x;double y;;enum SpaceObjType SHIP, ASTEROID, PHOTONTORPEDO ; class SpaceObject public:SpaceObject;SpaceObjectSpaceObjType type, double radius, Point location, Point velocity, double angle;mutatorsbool setRadiusdouble radius;bool setLocationdouble x double y;bool setVelocitydouble velocityX, double velocityY;bool setAngledouble angDeg;change angle by given amount.void changeAngledouble deltaDeg;accessorsdouble getRadius const;Point getLocation const;Point getVelocity const;double getAngle const;othersvoid updatePosition;void dumpData const; prints objects data to cout for testingprivate: SpaceObjType type; type of objectPoint location; current location xyPoint velocity; current velocity in pixelsframedouble angleDeg; angle object is facing in degreesdouble radius; gross radius of object for collision detection;The functions should do the following:SpaceObject initialize all member variablestype should be set to ASTEROIDradius should be set to Other member variables should be given some reasonable values.SpaceObject that accepts parameters.Initialize all member variables to the given values, or if values are invalid, use reasonable default values. All Mutators Validate values given and use them to set associated member variables.setRadiusr if given value is negative or screen height, ignore it and return false..setLocationxy if given values are outside screen range defined by constants adjust them if necessary to remain in bounds by addingsubtracting screen size values from them. These corrections make the object reappear back on the opposite side of the window if it goes off the edge.All Accessorsreturn copies of requested dataupdatePositionUpdates the location based on the current velocity. adds the velocity vector values xy to the location Make sure the resulting location is within screen range rather than repeat the validation here, you should call setLocation and pass it the new computed values.You should write and test each function thoroughly before moving to the next function. main should be in spaceObjectTest.cpp and will consist of code that simply tests your class code, calling functions with test values and displaying the results. A beginning of this is below. int mainSpaceObject asteroid;asteroid.dumpData;asteroid.setLocation;asteroid.dumpData;TODO: add more test code. Lots more test code.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started