project5 - Template SparseVector due November 28th(note...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Template SparseVector due November 28th (note last project will be available before Thanksgiving and due the end of semester) The goal of this project is to get familiar with namespaces, writing template classes, template functions, subclassing template classes, and using simple patterns to achieve the desired functionality. Project is split into 3 main goals: Goal 1. Generalize existing SparseVector class to a template class that supports at least numeric built-in types. To make it simpler the interface is minimal: template <typename T> class SparseVector { public: //ctors, dtor, assignment void SetDimension(unsigned long d); unsigned long GetDimension() const; ElementProxy<T> operator[](unsigned long pos); const ElementProxy<T> operator[](unsigned long pos) const; struct ElementNode { ElementNode() : data(0), pos(0), next(0) {} T data; unsigned long pos; struct ElementNode *next; }; const ElementNode* GETLLLHEAD() const; protected: //some protected stuff ElementNode* pHead; unsigned long dimension; }; ElementProxy interface is template <typename T> class ElementProxy { public: ElementProxy(SparseVector<T>& v, unsigned long pos); ElementProxy& operator=(const ElementProxy & new_val); ElementProxy& operator=(T new_val); ElementProxy& operator*=(T new_val); ElementProxy& operator+=(T new_val); ElementProxy& operator-=(T new_val); operator T() const; private: SparseVector<T> &v; unsigned long pos; }; Once you implement this classes you may try tests 1-4 from the driver.cpp. Notes: 1. Since most compilers do not properly implement the separation model of template compilation, the implementation for the templated classes must be included in all files that need to instantiate the template. For this assignment, you must include your templated .cpp files at the end of your .h files with an #include directive: (consult the notes for more examples) 2. All code must be in the CS225 namespace. 3. Since the SparseVector class is essentially a linked list, you will need to have some kind of Node struct or class. This is provided in SparseVector. You shouldn't need to modify it. 4.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

project5 - Template SparseVector due November 28th(note...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online