Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are asked to implement the following C++ strings class Here is the class interface and an example main program: #include #include using namespace std;

You are asked to implement the following C++ strings class
Here is the class interface and an example main program:
#include
#include
using namespace std;
class StringList
{
public:
StringList();
// Creates a new, empty, list
StringList(string init[], int size);
// Creates a new list, initialized from the given values
StringList(const StringList& other);
// Copy constructor
void addEntry(string str);
// Adds a string to the list
void displayAllEntry () const;
// Diaplay all strings from the list
int countEntry() const;
// Returns the number of strings in the list
string get(int idx) const;
// Returns the string at the given index
void set(int idx, string str);
// Sets the string at the given index
~StringList();
// Destroys the list, releasing any allocated memory
void operator=(const StringList& right_side);
// Assignment operator
private:
string *list;
int size;
};
int main()
{
// Make an array and put some names in it
int init_names_size = 5;
string init_names[init_names_size];
init_names[0] = "Ahmad";
init_names[1] = "Wiggum";
init_names[2] = "Natasha";
init_names[3] = "Layla";
// Make two lists, one with each constructor
StringList names(init_names, 5), list;
cout << "Initial list:" << endl;
names.displayAllEntry();
// Add and remove some names
names.addEntry("Iyad");
cout << "After adding a name:" << endl;
names.displayAllEntry();
names.addEntry("Muntz");
cout << "After adding another name:" << endl;
names.displayAllEntry();
names.addEntry("Burns");
names.addEntry("Sameer");
cout << "After adding three names:" << endl;
names.displayAllEntry();
cout << endl << "An empty list created with the default constructor:"
<< endl;
list.displayAllEntry();
list.addEntry("Milhouse");
list.addEntry("Hind");
cout << "After adding two entries:" << endl;
list.displayAllEntry();
list.set(0, "Jimbo");
cout << "After changing the first entry:" << endl;
list.displayAllEntry();
cout << endl << "After assigning first list to the second list: " << endl;
list = names;
list.displayAllEntry();
cout << "First list (again): " << endl;
names.displayAllEntry();
cout << endl << "A third list, created with the copy constructor: " << endl;
StringList list_copy(list);
list_copy.displayAllEntry();
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions