Question: C++ Write definitions for all functions for the TOC class in the separate TOC.cpp file and implement driver using menu provided in the source.cpp file.

C++

Write definitions for all functions for the TOC class in the separate TOC.cpp file and implement driver using menu provided in the source.cpp file.

#ifndef _TOCpoiner_header

#define _TOCpoiner_header

using namespace std;

template < class T >

class TOC

{

private:

int numUsed; // current number of elements in the array

int capacity; // max number of items allowed

T* myArray; // pointed to dynamic array

public:

TOC(int size = 10);

bool full();

bool ifEmpty();

int getCapacity();

int getNumUsed(); // returns current number of elements in the array

T get(int index); // returns an item at given index

void add(T x); // add item to the array at the next available position

int getPosition(T x); // returns an index of the item x

void insertAt(T x, int index); // insert item x at the given index: bounds for index [0 - numUsed]

void remove(int index); // remove an item from the given index

void display(); // display all elements in the array

void resize(); // double the size of your array

~TOC(); // release memory for the array

};

#endif

menu

cout << "What would you like to do with your myArray? Enter the corresponding number. Enter 0 to exit." << endl << endl; cout << "1. Fill the myArray or add an element" << endl; cout << "2. Display elements in the myArray" << endl; cout << "3. Check if the myArray is full" << endl; cout << "4. Check if the myArray is empty" << endl; cout << "5. Insert the element in the myArray." << endl; cout << "6. Remove the element from the myArray" << endl; cout << "7. Check the position of the chosen element in the myArray" << endl; cout << "8. Change chosen element in the myArray" << endl; cout << "9. Check the capacity of the myArray " << endl; cout << "10. Check how many elements are currently in the myArray" << endl; cout << "11. Print the element from the chosen position in the myArray" << endl; 

I want to write the c++ code for this question. Could I get the c++ code for this program all the function definitions TOC.cpp , TOC.h and

source.cpp and the output. I want to write that menu in the main by using switch statement.

this is what I have so far.(my code )

#include "TOC.h"

#include "TOC.cpp"

#include

using namespace std;

int main()

{

int input;

TOC myArray;

int choose = 0;

while (choose != 12)

{

cout << "What would you like to do with your myArray? Enter the corresponding number. Enter 0 to exit." << endl << endl;

cout << "1. Fill the myArray or add an element" << endl;

cout << "2. Display elements in the myArray" << endl;

cout << "3. Check if the myArray is full" << endl;

cout << "4. Check if the myArray is empty" << endl;

cout << "5. Insert the element in the myArray." << endl;

cout << "6. Remove the element from the myArray" << endl;

cout << "7. Check the position of the chosen element in the myArray" << endl;

cout << "8. Change chosen element in the myArray" << endl;

cout << "9. Check the capacity of the myArray " << endl;

cout << "10. Check how many elements are currently in the myArray" << endl;

cout << "11. Print the element from the chosen position in the myArray" << endl;

cout << "12. exit" << endl;

cin >> choose;

}

switch (choose)

{

case 1:

cout << "The case 1 is Fill the myArray or add an element " << endl;

cout << "Please enter the numbers that you want to fill my array" << endl;

cin >> input;

myArray.add(input);

myArray.display();

default:

break;

}

}

TOC.h is my header file and i have to write my TOC.cpp (all the function definitions) and the main.cpp.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!