Please send questions to
st10@humboldt.edu .
#ifndef string_list_H
#define string_list_H
/*-----------------------------------------------------------
a string_list is a class:
string_list
...representing a list with:
a size,
the strings it currently contains
template for a function involving a string_list:
ret_type process_string_list(string_list a_string_list)
{
return ...a_string_list.get_length()...
...a_string_list.get_element(i)...
}
-------------------------------------------------------------*/
#include <string>
using namespace std;
class string_list
{
public:
// constructor
string_list();
// destructor
~string_list();
// copy constructor
string_list(const string_list& a_string_list);
// selectors
int get_length() const;
// signature: string_list::get_element: int -> string
// purpose: expects the "index" (starting with 0, like an
// array) of the list element desired, and produces
// the string at that position in this string_list
// examples: for:
// string_list greetings;
// greetings.add("hi");
// greetings.add("hello");
// greetings.add("howdy");
//
// greetings.get_element(0) == "hi"
// greetings.get_element(2) == "howdy"
string get_element(int index) const;
// modifiers
// signature: string_list::add: string -> void
// purpose: expects a string, and produces nothing, but
// has the side-effect of adding the given string
// to the end of the list (making it its last element)
// examples: after:
// string_list greetings;
// greetings.add("hi");
//
// now:
// greetings.get_size() == 1
// greetings.get_element(0) == "hi"
//
// and then after:
// greetings.add("hello");
//
// now:
// greetings.get_size() == 2
// greetings.get_element(1) == "hello"
void add(string new_string);
// signature: string_list::remove: string -> bool
// purpose: expects a string, and tries to remove its
// first instance from the calling string_list,
// producing true if it finds it and removes it,
// and producing false if the string is not in the
// string_list
// examples: after:
// string_list greetings;
// greetings.add("hi");
// greetings.add("howdy");
// greetings.add("hi");
// greetings.add("hello");
//
// greetings.remove("hi") == true
// and after:
// greetings.get_size() == 3
// greetings.get_element(0) == "howdy"
// (and greetings contains "howdy", "hi", "hello")
//
// greetings.remove("bonjour") == false
// greetings.get_size() == 3
// greetings.get_element(0) == "howdy"
// (and greetings contains "howdy", "hi", "hello")
bool remove(string a_string);
// overloaded operator =
string_list& operator =(const string_list& right_side);
private:
// data fields
string *element_array;
int curr_capacity; // size of element_array, currently
int curr_size; // number of strings actually in
// element_array, currently
// static: inside of a class definition, it means there
// is EXACTLY ONE COPY of that thing no matter
// HOW many instances of that class are created
static const int INITIAL_CAP = 10;
};
#endif