CS 117, Winter 2000

Strings, due Friday, 2/25/00

You may work with a partner for this assignment. No groups of three or more, please.

When you are done with this assignment, please submit your code using the Homework Submission Program. Name your code capstring.cpp. Do not submit a main program.

Overview

In this project, you will add several member functions to the apstring class, which was developed for the computer science Advanced Placement exam, and which we have discussed in class.

I have modified the interface (in apstring.h) and implementation (in apstring.cpp) of the apstring class. I have put the modified versions in capstring.h and capstring.cpp ("Carleton's apstring"? "Corrupted apstring"?).

To get started, download the capstring files to your account. Prototypes of the new member functions have been added to the declaration of the capstring class in capstring.h. You will need to add implementations of these member functions to capstring.cpp, and write a main program (in main.cpp, for example) to test the new functions. To compile your program, you'll do something like this:

g++ -g -Wall -o capstringtest main.cpp capstring.cpp

The New Member Functions

The member functions you will add to the capstring class are:
  1. void capstring::makeupper(). This function changes all lowercase letters in the string to uppercase, and leaves all other characters in the string alone.

  2. int capstring::rfind( char ch ). This function returns the index of the last occurrence of the character ch in the string. If ch does not occur in the string, rfind returns the defined constant "npos". For example, if the string is "banana" and ch is 'n', then rfind returns 4.

  3. int capstring::rfind( const capstring& s ). This function returns the index of the first character in the last occurrence of s in the string. For example, if the string is "banana" and s is "ana", rfind returns 3.

  4. void capstring::reverse(). This function reverses the order of the letters in the string. For example, if the string starts out as "redivider", it is "redivider" after reverse is called. (Or, as an alternative example, if the string starts out as "god", it ends up as "dog".)

  5. void capstring::operator-=( char ch ). This function removes the last occurrence, if any, of the character ch from the string. For example, if the string is "brain" and ch is 'i', the string becomes "bran". (I'm sure there's a message there somewhere.) For a more helpful example, if the string is "inimitable", it becomes "inimtable".

That's it. Hand in your copy of capstring.cpp, but not your main.cpp.

Start early, keep in touch, and have fun.



Jeff Ondich, Department of Mathematics and Computer Science, Carleton College, Northfield, MN 55057
(507) 646-4364, jondich@carleton.edu