


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



You can find below information that can help with the implementation of your project. Some of them might be familiar from your Object Oriented Programming course as well.
1. Structure
In C++ code is divided into two types of files: header files (with the extension .h) and code files (with the extension .cpp). In the .h file we have the declarations while the actual implementation goes in the .cpp file.
Normally, for the ADT implementation your project should contain the following files:
The next section is valid only for those projects, where there is an iterator class as well.
Normally, Container.h should have an include for Iterator.h, because your container class will have an operation called iterator which returns an element of type Iterator.
However, Iterator.h should also include Container.h, because you will keep a variable of type container as an attribute in the Iterator.
If you have both includes, it will lead to a circular dependency and a lot of compile time errors. The solution for this problem is the following:
You will include the Container.h file in the Iterator.h, but you will NOT include the Iterator.h file in the Container.h file. This leads to a compile error in Container.h, where the compiler complains that it does not know the Iterator type returned by the iterator operation. To avoid this, you should add
a forward declaration to class Iterator. This means that before the container class, you will simply write: class Iterator; without any further implementation for the class (obviously it will be implemented in the Iterator.h file). This forward declaration is enough for C++ to know that there will be a class called Iterator.
Obs. : in the .cpp files however you can include everything circular dependencies are not a problem in those files.
3. Private/Public
The representation (attributes) of your container and iterator MUST be private. It must be hidden. The operations of both classes are public, but only those operations that exist in the interface of the ADT (the operations you are going to put in the project stage). You are allowed to add other operations in the container and/or iterator, but they must be private. They can be helper functions used for implementing the other ones, but they are not allowed to be visible from outside of the class. More precisely, you are not allowed to have getters and setters for your attributes. Representation is hidden (private) and this means that you are not allowed to return them!
4. Friend classes
The representation of your container and iterator will be private. But the iterator needs access to the representation of the container, in order to access the elements. But you are not allowed to make the representation public. The solution for such situations is to use the friend class mechanism. If in your container class you add friend class Iterator;
should return NULL_TVALUE. What NULL_TVALUE actually is, depends on your application (and on the type of the values). It could be the number 0 or -1, it could be an empty string, etc. Your code will be more readable if, instead of hardcoding this special value in your implementation, you just define it:
#define NULL_TVALUE -
Now you can use NULL_TVALUE in your implementation