summaryrefslogtreecommitdiff
path: root/chapter2/point.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'chapter2/point.cxx')
-rw-r--r--chapter2/point.cxx33
1 files changed, 33 insertions, 0 deletions
diff --git a/chapter2/point.cxx b/chapter2/point.cxx
new file mode 100644
index 0000000..9b56f9e
--- /dev/null
+++ b/chapter2/point.cxx
@@ -0,0 +1,33 @@
+// FILE: point.cxx
+// CLASS IMPLEMENTED: point (See point.h for documentation.)
+
+#include "point.h"
+
+namespace main_savitch_2A
+{
+
+ point::point(double initial_x, double initial_y)
+ {
+ x = initial_x; // Constructor sets the point to a given position.
+ y = initial_y;
+ }
+
+
+ void point::shift(double x_amount, double y_amount)
+ {
+ x += x_amount;
+ y += y_amount;
+ }
+
+
+ void point::rotate90( )
+ {
+ double new_x;
+ double new_y;
+
+ new_x = y; // For a 90 degree clockwise rotation, the new x is the original y,
+ new_y = -x; // and the new y is -1 times the original x.
+ x = new_x;
+ y = new_y;
+ }
+}