Answered step by step
Verified Expert Solution
Link Copied!

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 x,y values) Your project should be called polygons. (well build on this over the next few assignments)Your 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 definition)spaceObject.cpp - class implementation spaceObjectTest.cpp (includes a main that tests the SpaceObject class code)What 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 it.Add 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 be.Then implement the next constructor and test it.Repeat 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 SCREEN_WIDTH=400;const int SCREEN_HEIGHT=400;struct Point {double x;double y;};enum SpaceObjType { SHIP, ASTEROID, PHOTON_TORPEDO }; class SpaceObject {public:SpaceObject();SpaceObject(SpaceObjType type, double radius, Point location, Point velocity, double angle);//=============================================//mutatorsbool setRadius(double radius);bool setLocation(double x, double y);bool setVelocity(double velocityX, double velocityY);bool setAngle(double angDeg);//change angle by given amount.void changeAngle(double deltaDeg);//============================================//accessorsdouble getRadius() const;Point getLocation() const;Point getVelocity() const;double getAngle() const;//============================================//othersvoid updatePosition();void dumpData() const; //prints objects data to cout (for testing)private: SpaceObjType type; //type of objectPoint location; //current location (x,y)Point velocity; //current velocity (in pixels/frame)double angleDeg; //angle object is facing (in degrees)double 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 20.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.setRadius(r)- if given value is negative or >(1)/(2) screen height, ignore it and return false..setLocation(x,y)- if given values are outside screen range (defined by constants), adjust them if necessary to remain in bounds by adding/subtracting 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 dataupdatePosition()Updates the location based on the current velocity. (adds the velocity vector values (x,y) 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 main(){SpaceObject asteroid;asteroid.dumpData();asteroid.setLocation(100,200);asteroid.dumpData();//TODO: add more test code. Lots more test code.}

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

Students also viewed these Databases questions