\n\n1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt><\/pre>\n<\/td>\n\n\n<\/tt>#include<\/span> <iostream><\/span>\n<\/tt>#include<\/span> <cmath><\/span>\n<\/tt>\n<\/tt>#define<\/span> PI 3<\/span>.14159<\/span>\n<\/tt>or\n<\/tt>const<\/span> double<\/span> PI = 3<\/span>.14159<\/span>;\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\nDefining the Coordinate Class<\/h2>\nFor the coordinate<\/b> class we need 2 private variables x<\/i><\/b> and y<\/i><\/b>, 3 constructors<\/b>, and 11 member functions<\/b>.<\/p>\n The way you do the constructors and member functions can be done 2 different ways. You can either do them inside the class, or you can define them inside the class, like you do prototypes, and then have the actual functions at the bottom of your code. I like to define them and then put the functions at the bottom, making the code a little bit easier to read so that is the way that I'll show you, but if you want to do it the other way then just do it how you normally would with a regular function.<\/p>\n So here is what your class should look like (keep in mind that this all goes at the top before the main function<\/b>):<\/p>\n\n\n\n1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt>20<\/strong>\n<\/tt>21\n<\/tt>22\n<\/tt>23\n<\/tt>24\n<\/tt><\/pre>\n<\/td>\n\n\n<\/tt>class coordinate\n<\/tt>{\n<\/tt> private:<\/span>\n<\/tt> double<\/span> x; \/\/ x value of the coordinate point<\/span>\n<\/tt> double<\/span> y; \/\/ y value of the coordinate point<\/span>\n<\/tt> public:<\/span>\n<\/tt> coordinate(); \/\/ 1st constructor requiring that no arguments are passed<\/span>\n<\/tt> coordinate(double<\/span> ); \/\/ 2nd constructor requiring that only 1 argument is passed<\/span>\n<\/tt> coordinate(double<\/span> , double<\/span> ); \/\/ 3rd constructor requiring that 2 arguments are passed<\/span>\n<\/tt>\n<\/tt> void<\/span> set(double<\/span> , double<\/span> ); \/\/ sets both values and requires 2 arguments to be passed<\/span>\n<\/tt> void<\/span> setx(double<\/span> ); \/\/ sets x value and requires 1 argument to be passed<\/span>\n<\/tt> void<\/span> sety(double<\/span> ); \/\/ sets y value and requires 1 argument to be passed<\/span>\n<\/tt> void<\/span> read(); \/\/ allows user to input both x and y values <\/span>\n<\/tt> void<\/span> print(); \/\/ prints out the coordinate point in "(x, y)" form<\/span>\n<\/tt> double<\/span> distancezero(); \/\/ calculates distance of point from zero and returns the value<\/span>\n<\/tt> double<\/span> distancetwo(coordinate ); \/\/ calculates distance between 2 points (current instance and coordinate value passed) and returns the value<\/span>\n<\/tt> double<\/span> ranglezero(); \/\/ calculates the angle of the coordinate in radians and returns the value<\/span>\n<\/tt> double<\/span> danglezero(); \/\/ calculates the angle of the coordinate in degrees and returns the value<\/span>\n<\/tt> int<\/span> quadrant(); \/\/ find what quadrant the coordinate is in and returns the value<\/span>\n<\/tt> void<\/span> midpoint(coordinate ); \/\/ calculates the midpoint between 2 points (current instance and coordinate value passed) and prints the value as a coordinate<\/span>\n<\/tt>};\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\nWriting the Actual Functions for the Coordinate Class<\/h2>\nSince we are not actually writing the functions in the same place we are doing the class we will write them at the bottom after the main function<\/b>. However, to do this we will need a little more than what we would with regular functions. For member functions<\/b> we have to define what class the function is actually a member of. To do this we have to do coordinate::[function]()<\/b>.<\/p>\n For example, here are the 3 constructors for the coordinate<\/i><\/b> class:<\/p>\n\n\n\n1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt><\/pre>\n<\/td>\n\n\n<\/tt>\/\/ takes no arguments and sets x and y to 0<\/span>\n<\/tt>coordinate::coordinate()\n<\/tt>{\n<\/tt> x = y = 0<\/span>;\n<\/tt>} \n<\/tt>\/\/ takes 1 argument and sets x and y to that value<\/span>\n<\/tt>coordinate::coordinate(double<\/span> a)\n<\/tt>{\n<\/tt> x = y = a;\n<\/tt>} \n<\/tt>\/\/ takes 2 arguments and sets the corresponding x and y to those values<\/span>\n<\/tt>coordinate::coordinate(double<\/span> a, double<\/span> b)\n<\/tt>{\n<\/tt> x = a;\n<\/tt> y = b;\n<\/tt>}\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\nNext, we have the member functions<\/b>. The first 3 are the set functions. These allow the user to set the values of either the x<\/i<\/b> or the y<\/i><\/b> or both together.<\/p>\n\n\n\n1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt><\/pre>\n<\/td>\n\n\n<\/tt>\/\/ take 2 arguments and sets the corresponding x and y to those values<\/span>\n<\/tt>void<\/span> coordinate::set(double<\/span> a, double<\/span> b)\n<\/tt>{\n<\/tt> x = a;\n<\/tt> y = b;\n<\/tt>}\n<\/tt>\/\/ takes 1 argument and sets the x to that value<\/span>\n<\/tt>void<\/span> coordinate::setx(double<\/span> a)\n<\/tt>{\n<\/tt> x = a;\n<\/tt>}\n<\/tt>\/\/ takes 1 argument and sets the y to that value<\/span>\n<\/tt>void<\/span> coordinate::sety(double<\/span> b)\n<\/tt>{\n<\/tt> y = b;\n<\/tt>}\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\nNext, is the read<\/b> and print<\/b> functions. All we want the read to do is to do a cin<\/b> of the 2 values (x<\/i><\/b> and y<\/i><\/b>). The print<\/b> is just the opposite. All it does is do a cout<\/b> of the x<\/i><\/b> and y<\/i><\/b> values in the (x<\/i>, y<\/i>)<\/b> format.<\/p>\n | | | | | | | |