point_t
object, read a file, and add points
to a list (std::vector
).
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);
~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 +
(z1-z2)2)
point_t
class should store the x-
and y-coordinates in a private
std::vector<double>
container.
main()
routine should be similar to those of
Assignment 01
and
Assignment 02.
delete
ing each point pointer as you erase each one
from the list
pointdata.txt
file used to test the above program is:
1.0 -1.0 1.0
-1.0 -1.0 1.0
-1.0 -1.0 -1.0
1.0 -1.0 -1.0
*** printing list
1.00, -1.00, 1.00
-1.00, -1.00, 1.00
-1.00, -1.00, -1.00
1.00, -1.00, -1.00
*** printing list again
1.00, -1.00, 1.00
-1.00, -1.00, 1.00
-1.00, -1.00, -1.00
1.00, -1.00, -1.00
p_i[0] = 1.00 p_i[1] = -1.00 p_i[2] = 1.00
p_i[0] = -1.00 p_i[1] = -1.00 p_i[2] = 1.00
p_i[0] = -1.00 p_i[1] = -1.00 p_i[2] = -1.00
p_i[0] = 1.00 p_i[1] = -1.00 p_i[2] = -1.00
|p_0 - p_1| = 2.00
*** 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