$29.99
CS 2401
Lab 8: Introduction to Templates
The goal here is to get an initial feel for creating a template class. I have provided a header in a
file called tarray.h and a main. Notice that at the bottom of the tarray.h there is a line
that says:
#include “tarray.template”
You are to write the tarray.template file which will implement the following functions for
the class:
// makes an object with a dynamic array of size 5
Tarray();
// puts the item into the next available spot in the
// array. If the array is full, resize is called.
void add(T item);
// iterator functions
// places current_index at the beginning of the array
void start();
// returns true if the current index is less than used
bool is_item()const;
// moves current index to the next array location
void advance();
// returns the array item referenced by current index
T current()const;
// removes the item at the current index
void remove_current();
private:
void resize();
Once you have implemented all the functions, compile this with the command g++ *.cc (even
though there is only one .cc file) and then run the program, saving your second running of the
program to a script file.
Please submit your source code and a script file (or screenshots of the output if you do not have
the script command) on Blackboard.