**List.cpp (class definitions)**

I have been working on code that is suppose to help familiarize with classes. My code currently has a function that displays a menu of options for the users. Option [1] is suppose to add a string, option [2] is suppose to remove a string from the list, option [3] prints the string list, option [4] exits. My option [1] seems to work okay as the user is able to input one string at a time but I am having a hard time with the removal of a string. The strings are currently stored in an array of 10 elements. I believe the function I wrote for the string removal is okay as I have debugged it and it seems successful, however, I am not seeing results on my console window. 

My array is located in a private class in my class: string items[MAX\_ITEMS]; along with another variable called: int totalItems;

The class is then called in my main function using a switch case:

```
//This code snippet below is located in a separate cpp file with main
cout << "Please enter the text you want to remove: " << endl;
cin >> userInput;
list1.remove(userInput);
////////////////////////////////////////////////////////////////////

//preprocessor directives
#include <iostream>
#include <string>

//header files
#include "list.h"

using namespace std;

List::List()
{
    //clear array prior to starting (set everything to NULL)
    for (int i = 0; i < MAX_ITEMS; i++)
    {
        items[i] = " ";
    }

    totalItems = 0;
}

//void List::init()
//{
//  string items[MAX_ITEMS];
//  totalItems = 0;
//}

bool List::insert(const string& data)
{

    //verifies that string is not empty, not in the list, and not full
    if (data.empty() == true || inList(data) == true || isFull() == true)
    {
        return false;
    }
    else
    {
        //      items[isFull)] = data;
        //      totalItems++;
        items[totalItems++] = data;
        return true;
    }
}

bool List::isEmpty() const
{
    //runs through loop to verify array is empty
    for (int i = 0; i < MAX_ITEMS; i++)
    {
        if (items[i].empty() != true)
        {
            return false;
        }
    }
    return true;
}

//identifies whether the string is full or not
bool List::isFull() const
{
    if (totalItems == MAX_ITEMS)
    {
        return true;
    }
    else
    {
        return false;
    }
}

//identifies whether the string is already in the list or not
bool List::inList(const string& theList)
{
    for (int i = 0; i < MAX_ITEMS; i++)
    {
        if (items[i] == theList)
        {
            return true;
        }
    }
    return false;
}

bool List::remove(const string& data)
{
    if (inList(data) == true || data.empty() == true)
    {
        return false;
    }

    for (int i = 0; i < MAX_ITEMS; i++)
    {
        if (items[i] == data)
        {
            items[i] == " ";
            for (int j = i; j < MAX_ITEMS; j++)
            {
                items[j] = items[j + 1];
                items[MAX_ITEMS - 1] == " ";
                break;
            }
        }
    }
    totalItems--;
    return true;
}

//prints list
void List::printList()
{
    for (int i = 0; i < MAX_ITEMS; i++)
    {
        cout << i << items[i] << '\t';
    }
}

```

**list\_test.cpp (main.cpp)**

```
#include <iostream>
#include <string>

//header files
#include "list.h"

using namespace std;

//function prototypes
int showSelection();

int main()
{
    List list1;

    string userInput = "";
    int userChoice;

//  list1.init();

    userChoice = showSelection();

    while (userChoice != 4)
    {
        switch(userChoice)
        {
            case 1:
                cout << "Please enter the text you want to add: " << endl;
                cin >> userInput;
                list1.insert(userInput);

                /*if (list1.inList(userInput) == false)
                {
                    cout << "Text is already entered in the list!" << endl;
                }*/

                if (list1.isFull() == true)
                {
                    cout << "You have entered the MAXIMUM amount of elements!" << endl;
                }
                break;
            case 2:
                cout << "Please enter the text you want to remove: " << endl;
                cin >> userInput;
                list1.remove(userInput);
                break;
            case 3:
                cout << "Printed list: " << endl;
                list1.printList();
                break;
        }
        userChoice = showSelection();
    }

    cout << "Goodbye. Please press enter to exit." << endl;
    //TESTING PURPOSES FOR FUNCTIONS
    cout << list1.insert(userInput) << endl;
    cout << list1.isEmpty() << endl;
    cout << list1.isFull() << endl;
    cout << list1.inList(userInput) << endl;

    return 0;
}

/* ===========================================
Name: showSelection
Desc: displays menu for user to choose options
      for their inputted string(s).
Args: none
Retn: none
=========================================== */
int showSelection() 
{
    int userChoice;
    bool exit = false;

    while (exit == false)
    {
        cout << "\nTo select an option, please enter the corresponding number: " << endl;
        cout << "[1] to add a string" << endl;
        cout << "[2] to remove a string" << endl;
        cout << "[3] to print a string" << endl;
        cout << "[4] to exit" << endl << endl;
        cin >> userChoice;

        cout << "You entered option: " << userChoice << endl;
        cout << '\n';

        if (userChoice == 1 || userChoice == 2 || userChoice == 3 || userChoice == 4)
        {
            exit = true;
        }
        else
        {
            cout << "Invalid selection" << endl;
        }
    }`enter code here`
    return userChoice;
}

```