CS 107 - Lab 9

Creating the Class Point

A C++ class allows a program to take advantage of the object-oriented features of the language. A class has both data members and methods. The data members are the values that define the instance of the class. The methods are operations (functions) that use the class. Most often, the data members are private (can only be accessed inside of the class) while the members are public (can be accessed either inside or outside of the class).

During lecture, we have been creating a class Complex. Refer to this class and the discussion from lecture to complete this lab.

Lab Assignment

Due: By your Lab Time during the eleventh week of the semester (the week of 3/31/2003).

You may turn in the assignment to your TA during lab or place it in his mailbox in 905 SEO. It is suggested that you place it in his mailbox just in case you are unable to attend lab. You are to hand in a print out of your program to do the following to your TA.

The following is the code in the file lab9.cpp. The file is also available from the ~troy directory on icarus. To copy the file from the ~troy directory on icarus to your current directory on icarus type "cp ~troy/lab9.cpp .".

#include <iostream>

// put your Point class here

int main()
{
 Point pt1, pt2, pt3, origin;

 pt1.setX(5);
 pt1.setY(7);

 cout << "Point pt1 is: (" << pt1.getX() << "," pt1.getY() << ")" << endl;
 cout << "Point pt1 is in quadrant " << pt1.getQuadrant() << endl;

 pt2.setXY (-2, -4);
 pt3.setXY (-8, 9);
 origin.setXY (0, 0);

 cout << "Point pt2 is: ";
 pt2.printPoint();
 cout << endl;
 cout << "Point pt2 is in quadrant " << pt2.getQuadrant() << endl;

 cout << "Point pt3 is: ";
 pt3.printPoint();
 cout << endl;
 cout << "Point pt3 is in quadrant " << pt3.getQuadrant() << endl;

 cout << "Point origin is: ";
 origin.printPoint();
 cout << endl;
 cout << "Point origin is in quadrant " << origin.getQuadrant() << endl;

 cout << "The distance between pt1 and pt2 is " << pt1.distanceFrom (pt2)
      << endl;
 cout << "The distance between pt2 and pt1 is " << pt2.distanceFrom (pt1)
      << endl;
 cout << "The distance between pt3 and the origin is " 
      << pt3.distanceFrom (origin) << endl;
 cout << "The distance between the origin and pt3 is " 
      << origin.distanceFrom (pt3) << endl;
}

Hand in a print out of your program to your TA.