data_t
objectsdata_t
object, read a file, and add
data_t
objects to a list (std::vector
).
data_t
class
(object) that will hold the following two data members:
std::string name
int id
data.h
that holds the object interface
and data.cpp
that holds the object implemantation.
main.cpp
test driver program (see below) reads a data
file (redirected from std::cin
), creates a
data_t
object from each pair of string and numbers,
and adds them to a list. It then prints them out and deletes
the list. Once your program successfully compiles (using
the Makefile
provided below), you should be
able to test the program by executing this command on the
command line:
./main < listdata.txt
data_t
object should provide the following:
data_t(std::string iname="",int iid=-1);
data_t(const data_t& rhs);
)
~data_t();
), default ok (can comment this out)
const data_t& operator=(const data_t& rhs);
)
friend istream& operator>>(istream& s, data_t& rhs);
friend ostream& operator<<(ostream& s, const data_t& rhs);
main()
routine such that it now uses a list of pointers
to data_t
(std::vector<data_t* >
).
listdata.txt
file used to test the above program is:
Mike 1234
Bill 3212
Sarah 1321
John 1021
Carol 3223
Debbie 4231
Gary 9321
Ann 1231
Dale 7231
Lynn 8133
Patty 9999
Mike 1234
Bill 3212
Sarah 1321
John 1021
Carol 3223
Debbie 4231
Gary 9321
Ann 1231
Dale 7231
Lynn 8133
Patty 9999
*** printing records
Mike 1234
Bill 3212
Sarah 1321
John 1021
Carol 3223
Debbie 4231
Gary 9321
Ann 1231
Dale 7231
Lynn 8133
Patty 9999
*** printing records again
Mike 1234
Bill 3212
Sarah 1321
John 1021
Carol 3223
Debbie 4231
Gary 9321
Ann 1231
Dale 7231
Lynn 8133
Patty 9999
*** deleting records
*** initializing new records
*** deleting records 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 = \
data.o
main : $(OBJECTS) main.o
$(CC) -o $@ $(INCDIR) $(COPTS) $(OBJECTS) $@.o $(LIBDIR) $(LIBS)
data.o: data.h data.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