Replacing Placeholders using a string class - Assignment


Your Task

You must rewrite the placeholders assignment to use a class for the type of strings (rather than arrays of characters).

You must create 2 new versions of that program. In both versions, you should replace arrays of characters with string objects whenever possible. You may not use any library functions from string.h in your main programs! As a result, you should solve the problem as follows...

As you read in words from the paragraph (making substitutions for placeholders) you should build up one long string that stores the altered paragraph (remembering to wrap lines). Once the original paragraph has been completely read, you can then print out the string that holds the new paragraph.

Below are the differences between the 2 versions of the program you will write.

Using your "String" class

This first version will use the String class that you created in lab. For this solution, you must create files named mystring.h and mystring.cpp for the String class module and subtext1.cpp for the main program.

The only time you will have to use arrays of characters in this version is when reading in strings. It is necessary in that case since your String class has no method to read in a string. For this reason, you may assume that no placeholder, placeholder value, or word in the paragraph is more than 30 characters. Also, you may assume that no more than 10 placeholders are entered by the user. You may not assume that the paragraph has any particular length or number of words (see above-mentioned strategy for processing the paragraph).

Using C++'s built-in "string" class

This version will use the built-in string class that comes with newer C++ compilers. You must submit this version as a file named exactly subtext2.cpp. See p. 894 of your text book for examples on how to use the built-in string class. Basically, you have to include:
#include <string>
(Note there is no ".h".) The built-in class has methods very similar to the String class you wrote, but also responds to input/output operators, e.g.,
string foo;

cin >> foo;  // read in value separated by whitespace
cout << foo;  // write out value

Thus, in this version, there is no need to use arrays of characters at all (thus, you are not allowed). As a consequence, you may not make any assumptions about the length of placeholders, their values or words in the paragraph. Also, like the first version, you may not assume that the paragraph has any particular length or number of words. The only assumption you may make is that at most 10 placeholders will be entered by the user.


Prepare these programs, adding all appropriate comments and using attractive and readable formatting conventions. Call the files subtext1.cpp, mystring.h, mystring.cpp, and subtext2.cpp.

The version with your own String class will count for a larger portion of your grade.


BU CAS CS - Replacing Placeholders using a string class - Assignment
Copyright © 1993-2000 by Robert I. Pitts <rip@bu.edu> All Rights Reserved.