Untitled document

advertisement
COP 3530 Fall 2013
Data Structures and Algorithms
Assignment 2 Due: Sep 13, 2010
The purpose of this assignment is to get you deeper into C++ (under the hood) as well as test
your understanding of the course material covered in class so far.
The main points we shall be covering are:
● Implementing Array based Linear Lists
● Re-enforcement of the usage and advantages of makefiles / make utility in UNIX/Linux
● Usage of templates and generics in C++
● Usage of header files and libraries
A header file or library is basically a normal C++ source file with one important difference from
your cpp files. A header file as we learned contains no main() function and hence cannot be
compiled into an executable program. Its sole purpose is to provide a tailored library (like
stdio.h) for other programs to use so that programmers do not have to reinvent the wheel and
write code from scratch.
In this assignment you are required to first create your own header file “ArrayLinearList.h” which
shall contain the class and methods for the “ArrayLinearList” class. In this you shall declare an
Array based Linear List of integers that shall allow the creation of a Linear List with an upper
limit of 10000 elements(Only integer type). The implementation of this shall be done in the cpp
file “main.cpp”
The class must implement the following functionality (methods) in “ArrayLinearList.h”:
Methods to:
1) I...[I]nsert an element at any desired location y in the list where y <=Size of List
2) D...[D]elete an element from any desired location y in the list where y <=Size of List
3) P...[P]rint out the entire List
4) E...Print any [E]lement at location y in the list where y<=Size of the List
5) S...Print the Current [S]ize (Number of Elements in the List) of the List.
6) M...*NEW FUNCTION NOT FROM CLASS* Print the [M]aximum and the [M]inimum
elements in the list
7) Also you MUST use a template definition for this class so that it can hold elements of
arbitrary data types (even though we are using integers.)
(Note the lecture slides contain the basics structure of these methods; however just copying and
pasting them will give you compile errors on Thunder that you have to work through in order to
correct).
Your program main.cpp must include your header file. Use main.cpp to test functionality. It
must create and initialize an ArrayLinearList with integers 1 to 10. (it could take up to 10000).
Then it should wait on Input. Based on input it must call one of the various methods to insert(“I”)
an element at a desired location, delete(”D”) the element at the required location, print (“P”) the
entire list, print (“E”) a single element from desired location, print the size (“S”) of the list, print
the maximum and minimum (“M”) values, and then quit (“Q”) the program.
The input shall be of the following form where the program will prompt the user for a command.
Based on the command the user might have to input more data such as index or value to feed
into the methods. For example:
I 5 10 => Insert an element 5 at 10th position (this will be replacement)
D 5 => Delete the element at 5th position
S => Print entire List
P 6 => Print the element at 6th position
N => Print Size of List
Q => Quit/Halt the program
You must also write a Makefile to compile your program.
Your submission tarball should be named <your name>_UFID.tar and must contain the
following files:
1) ArrayLinearList.h
2) main.cpp
3) Makefile
A sample output is as follows:
thunder:29% ./main
S
1 2 3 4 5 6 7 8 9 10
I03
N
11
S
1 2 0 3 4 5 6 7 8 9 10
P5
4
D5
P5
5
N
10
S
1 2 0 3 5 6 7 8 9 10
Q
thunder:30%
• Your submission should be portable to unix machines, (thunder is recommended).
• There should be no remaining errors after issuing the “make” command.
• A softcopy of the source code (.cpp file, NOT .o file) needs to be submitted in the tar file via
Sakai.
The simplest syntax of the tar command is as follows.
Use the Makefile to create the tarfile. It can also be done via command line: perform these
steps:
tar cvf (tar file name) (file 1) (file 2) (file 3)...
To extract the contents of a tar file:
tar xvf (tar file name)
Note: You can verify that your submission was successful by downloading your submission from
Sakai and successfully un-tarring it.
Download