point_t
object, read a file, and add points
to a list of pointers to point_t
(std::vector
).
point_t
objects are
stored on a std::vector<point_t* >
list
(vector) of pointers.
point_t
object should provide the following:
point_t(double x=0.0, double y=0.0, double z=0.0);
point_t(std::vector<double> c);
point_t(const point_t& rhs);
point_t(point_t* rhs);
NEW
~point_t();
), default ok (can comment this out)
point_t operator=(const point_t& rhs);
)
friend istream& operator>>(istream& s, point_t& rhs);
friend ostream& operator<<(ostream& s, const point_t& rhs);
[ ]
subscript operator.
double distance(point_t& rhs);
and
double distance(point_t* rhs);
)
that computes and returns the Euclidean distance between
this
point and the rhs
point:
sqrt((x1-x2)2 +
(y1-y2)2)
point_t
class should store the x-
and y-coordinates in a private
std::vector<double>
container.
main()
routine from
Assignment 01
should largely be unchanged, except for the following:
point_t point;
to read in each point,
you should now declare a pointer to the point_t
class (its name should have a p
at the end
following the convention that variables with a p
at the end signify they are pointers)
operator<<
, operator>>
can both accept pointers to point_t
as
arguments
vector
and not the objects like before
->
pointer instead of the .
new
point_t*
each
time data is read in (this gets added to the list)
delete
ing each point pointer as you erase each one
from the list
pointdata.txt
file used to test the above program is:
15 14 13
600 320 140
104 29 23
19 78 83
450 321 33
*** printing list
15.00, 14.00, 13.00
600.00, 320.00, 140.00
104.00, 29.00, 23.00
19.00, 78.00, 83.00
450.00, 321.00, 33.00
*** printing list again
15.00, 14.00, 13.00
600.00, 320.00, 140.00
104.00, 29.00, 23.00
19.00, 78.00, 83.00
450.00, 321.00, 33.00
*** printing point coords
p_i[0] = 15.00 p_i[1] = 14.00 p_i[2] = 13.00
p_i[0] = 600.00 p_i[1] = 320.00 p_i[2] = 140.00
p_i[0] = 104.00 p_i[1] = 29.00 p_i[2] = 23.00
p_i[0] = 19.00 p_i[1] = 78.00 p_i[2] = 83.00
p_i[0] = 450.00 p_i[1] = 321.00 p_i[2] = 33.00
*** checking distance function
|p_0 - p_1| = 672.30
*** deleting list
*** deleting list again
*** done
Makefile
that you can use to compile the project:
.SUFFIXES: .c .o .cpp .cc .cxx .C
UNAME = $(shell uname)
PLATFORM = $(shell uname -p)
CC = g++
COPTS = -g -Wall
INCDIR =
LIBDIR =
ifeq ("$(shell uname)", "Linux")
LIBS = -lm
else
ifeq ("$(shell uname)", "Darwin")
LIBS = -framework Foundation -lstdc++
endif
endif
.c.o:
$(CC) -c $(INCDIR) $(COPTS) -o $@ $<
.cpp.o:
$(CC) -c $(INCDIR) $(COPTS) -o $@ $<
all : main
OBJECTS = \
point.o
main : $(OBJECTS) main.o
$(CC) -o $@ $(INCDIR) $(COPTS) $(OBJECTS) $@.o $(LIBDIR) $(LIBS)
point.o: point.h point.cpp
clean :
rm -f *.o
rm -rf main main.app
tar.gz
archive of your asg##/ directory, including:
README
file containing
Makefile
.h
headers and .cpp
source)
make clean
before tar
)
handin
notes