Vous êtes sur la page 1sur 3

CSE 202

Description

Assignment #4 - Vector Class


Due date: Mar. 29 - 20:00

Spring 2012

This project deals with a vector, implemented as non-circular singly linked lists and an iterator to traverse the SLL. 1. container class - a class that can store a large amount of data and has operations to access, insert and remove items from the container. 2. vector - a data structure that has the ability to grow and shrink dynamically and allows direct access to elements using indexing 3. iterator - a pointer-like object that accesses the elements in a vector 4. forward iterator - can only move in the forward direction. For this project you will be required, among other things, to write the code for 3 classes: 1. Node 2. Vector 3. Iterator In /home/cse202/assign4 you can nd the header les for the classes. You may NOT change the public methods in the header les but may add private methods as needed. You may NOT add private, public or protected data members. After copying the header les Node.h, Vector.h, and Iterator.h into your assign4 directory, you should create the corresponding Node.cpp, Vector.cpp, and Iterator.cpp les and write the code that implements the member functions for these classes. In each header le you will nd the class with its member variables and member functions. There is a comment before/around each member function describing what it should do. You are to implement the member function so that it does what the comment states that it should do and nothing more. Next you should write 3 unit test les to test each of your classes: 1. testNode.cpp 2. testVector.cpp 3. testIterator.cpp Each unit test le should have a main() for a particular class that calls and tests each public method. It also tests the private methods which are called from public methods. Note that when developing/writing code you should do so in parts/modules and test each as you create it (keeping backup copies!). So for example, when writing Node, you also write a testNode.cpp that is the main() for Node.cpp. It should call all public functions and include appropriate output to test that all Node.cpp code works correctly. And nally you should test your code with the main supplied: main.cpp

Figure 1: v.size() returns 1

Figure 2: v.size() returns 2

Example
Figure 1 shows a vector v after pushing the element we onto the empty vector: Figure 2 shows the vector v after pushing the element are onto the vector: Vector v after popping o all elements:

1. v is NULL 2. v.begin() and v.end() do not exist. Note: v.end() (the dummy node) only exists if there is at least one valid element in the vector. Iterator arguments indicate a range [x, y) where x is included in the range and we go up to but do not include y. So for example if you were executing erase(v.begin(),v.begin()+2) and the vector was v = we are here END the resulting vector would be: v = here END

Implementation
1. Create assign4 directory under your home directory in uni01 server. $ mkdir assign4 2. Change your current directory to assign4 directory.

$ cd assign4 3. Copy provided les from cse202/assign4 $ cp ~cse202/assign4/* ~/assign4

4. Implement all the member functions in Node.cpp, Iterator.cpp, and Vector.cpp. 5. In order to compile, simply type make in the shell prompt as follows: $ make make command will create an executable a.out le in your current directory. 6. In order to test, you may change main.cpp, but don not put any required class implementation inside main.cpp, because I will overwrite the main.cpp in order to test your classes with other test cases. 7. Test and debug your algorithm with lots of examples.

Submitting Your Code


You should submit tgz compressed le. Turn in your project using the submit command as follows: 1. Tar up all necessary .cpp les, all .h les, and your Makele. $ cd ~/assign4 $ tar czvf assign4.tgz *.cpp *.h Makefile 2. Submit the compressed tar le. $ submit assign4 assign4.tgz

Style Guide
Students are expected to write clear and legible code. Please review the Style Guide at http://dicl.unist.ac.kr/class/spring2012/cse202/styleguide.txt which species how you are expected to lay out the code. If you do not follow the guideline, you may lose some points.

Vous aimerez peut-être aussi