Question: tarray.h #include template class Tarray{ public: // Constructor makes an object with a dynamic array of size 5 Tarray(); // This function puts the item

tarray.h
#include
template
// 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(); T *data; // pointer to the dynamic array std::size_t capacity; std::size_t used; std::size_t current_index; };
// This is how we hook this to the implementation file for templates: #include "tarray.template"
main.cc
#include
int main(){ Tarray
nums.add(rand()); nums.add(rand()); nums.add(rand()); nums.add(rand()); for(nums.start(); nums.is_item(); nums.advance()) cout
words.add("CS"); words.add("is"); words.add("the"); words.add("bestest"); words.add("major"); words.add("at"); words.add("Ohio"); words.add("University");
words.start(); while(words.is_item() && words.current() != "major") words.advance();
words.remove_current(); for(words.start(); words.is_item(); words.advance()) cout
return 0; }
Introduction to Templates 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, 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 Tarray0, This function puts the item into the next available spot in the array. ll If the array is full, resize is called. void add item), iterator functions places the current index at the beginning of the array void start 0 returns true if the current index is less than used bool is item const, +J moves current index to the next array location void advance0, returns the array item being referenced by current index T currento const, removes the item at the current index spot void remove curstento, 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
