Point Class User Example
/* * This is a fairly silly program to exercise the Point class. (Silly, * but not Point-less) * * (Boooooooooo!) */ #include <iostream> #include <string> #include "point.h" using namespace std; int main() { // Declare some point objects. Note that each of these // calls the constructor, including the last two. Point v(3.7, 6.8), w(4.5, 9.1), x(1.3), y = 2.4, z; // Print them. cout << "All the points: " << v.tos() << " " << w.tos() << "\n " << x.tos() << " " << y.tos() << " " << z.tos() << endl; // Some random arithmetic. z = w.plus(y).minus(v); cout << w.tos() << " + " << y.tos() << " - " << v.tos() << " =\n " << z.tos() << endl; // And let's try out move. Point start(452.12, 99.38); Point me(start); cout << "Road trip." << endl; cout << " " << me.tos() << endl; for(int i = 1; i <= 5; ++i) { me.move(2.1*i, 4.3*i); cout << " " << me.tos() << endl; } for(int i = 5; i > 0; --i) { me.move(3.5*i, 2.7*i); cout << " " << me.tos() << endl; } cout << "Net distance: " << start.distance(me) << endl; cout << "Area crossed: " << start.area(me) << endl; }

This uses the class defined in the file point_h. Notice the #include directive with the file name in quotes. The directive is effectively replaced by the contents of the file, as though it were typed there instead of the #include directive.