24LAB EXERCISE - STRINGS

 Background:

 Use the following format to test the string abstraction provided by the apstring class.  For example testing the class constructors could go something like this:

void testConstructors()

{

      apstring word1;

      apstring word2 ("Hello world\0");

      apstring word3 ("Hello world\n");

      cout << "Testing constructors" << endl << endl;

      cout << word1;

      cout << word2;

      cout << word3;

}

Assignment:

1.   Write testing functions using the format demonstrated above.  Test the following sections of the apstring ADT:

constructors

assignment operator

string accessors

indexing

modifiers

getline function

Boolean comparisons (test a few, you do not have to be comprehensive)

concatenation

2.   As you develop each testing function, document out all the other testing function calls and test one function at a time.  You do not need to turn in a run output for these sections.

3.   To test the function to convert an apstring to a C-style string, you will need to #include <stdio.h> to declare a C-style string using char*.  The tool to output a C-style string is puts(stringName).

4.   Write a test function which does the following:

      a.   reads a list of 5 names from a text file on disk, storing them as a array of strings.

      b.   prints the array of strings in the same order as the source text file.

      c.   sorts the names in ascending order using selectionSort.

      d.   prints the strings in ascending order.

e.   Choose the first names of 5 friends and save them in random order.  Use this as sample data for this part of the lab.

5.   Write a new function called extractFirstWord.  The function prototype is:

      apstring  extractFirstWord (const apstring &s);

      This function will extract the first word from apstring s.  The possible delimiters which terminate the first word are the blank space or the end of the string character.  You are to solve this function only by using the functions available in the string class.  Remember that each string function has a precondition which must be satisfied.

6.   The main function should consist of function calls only.    It should look something like this:

main()

{

      testConstructors();

      // testAssignment();

      // testAccessors();

      // testIndexing();

      // testModifiers();

      // testgetline();

      // testComparisons();

      // testConcat();

      // testSort();

      // testExtract();

      return 0;

}

7.   With each algorithm, make sure you test the general cases and the boundary cases. 

8.   Turn in your source code and run output.  Your run output should consist of two sections, the unsorted and sorted list of names and sample extractions of first words.  Use these 3 inputs as sample tests for the extractFirstWord function:

      hello world

      hello

      programming is fun