CS2401 Homework 4 Introduction to Templates

$30.00

Download Details:

  • Name: 4HW-fcr6r1.zip
  • Type: zip
  • Size: 26.58 KB

Category:

Description

Rate this product

The goal here is to get an initial feel for creating a template class. I have written a header in a file called tarray.h, which you should copy from my directory to yours:

cp ~jdolan/cs2401/labs/lab8/*  .

There is also a main here. 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 function for the class:

        // Constructor makes an object with a dynamic array of size 5

        Tarray();

 

        // This function 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 the 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 being referenced by cuurent index

        T current()const;

 

        // removes the item at the current index spot

        void remove_current();

    private:

        void resize();

Once you have implemented all the function you will 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 file showing your program interaction to the  Blackboard assignment.