For this part you will use overloaded member functions and make overloaded operators to get a simple plotting program to work. You will be working with three ADT's in this lab: Point2D, Vector2D, and Plot.
The plotting program uses the terminal text plotting package curses wrapped up in the Plot ADT. The Plot ADT uses the Point2D and Vector2D ADTs to simplify the job of moving the cursor and drawing lines. The following is an example of the interface for the program.:
0 1 2 3 4 5 6 7
012345678901234567890123456789012345678901234567890123456789012345678901234
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
What do you wish to do? (d: draw line, m: move point, q: quit) _
To use the program follow the prompts at the bottom. There are three commands: d, m and q. Use q to quit. d draws a line. You supply x and y displacements which are added to the current cursor to make the other end point of the line and all the characters on that line segment are filled in with a #. m moves the cursor by a displacement vector you supply but nothing is drawn. When the program starts the cursor is at (0,0)
The following sequence of commands:
d 10 10 m 5 0 d 10 10will produce this result:
0 1 2 3 4 5 6 7
012345678901234567890123456789012345678901234567890123456789012345678901234
0# #
1 # #
2 # #
3 # #
4 # #
5 # #
6 # #
7 # #
8 # #
9 # #
10 # #
11
12
13
14
15
16
17
18
19
What do you wish to do? (d: draw line, m: move point, q: quit) _
Cursor: 25.00 0.00
To complete the exercise you need to implement some overloaded operators
that take points and vectors as arguments. The missing operators are vector
division vector/scalar
and scalar vector comparison scalar<vector
. You will also need to use point vector addition point + vector
.
Vector division consists of dividing the components of a vector by some value to make a new vector from the resulting component values. For example dividing the vector (4,2) by 2 produces the vector (4/2,2/2) = (2,1). Vector division is used in Plot to create a vector the right size to incrementally draw lines — one of unit length in the dominant axis.
Vector comparison compares the magnitude or length of a vector to a Euclidean distance. The Euclidean length of a two dimensional vector is defined as . The result of a comparison should be a boolean variable. The specific comparison you will implement is less than, <. It should return true if the left hand side length is smaller than the right hand side and false otherwise. Vector comparison is used in Plot to see whether a point that is being incremented to draw a line is close enough to the endpoint to stop being drawn.
To move a point to new coordinates you need to add a vector to it. Point2D supports a point vector addition operator. You will need to use the provided operator correctly where indicated. This operation is used in Plot to move points and to draw lines.
cp /net/data/ftp/pub/class/170/ftp/cpp/overload.zip overload.zip unzip overload.zip
operator/
 Vector2d.h:30 and Vector2d.cpp:34
operator<
 Vector2d.h:12 and Vector2d.cpp:15
< /
and 
in plot.cpp:36,45
Point2d::operator+(Vector2d)
 plot.cpp:20 Mx gotolinecommand to get to a line. If you use a more advanced editor I trust you already know how to find a specific line.
make ./pplot < VectorMessageIf you did everything right you should see some familiar text mode graphics. :) You can run pplot by itself to try things out. Just follow the prompts at the bottom.
Thursday, 06Oct2011 12:13:32 CST 


