Programming for Scientists and Engineers

Problem A: String Overlap (30 points)
In this problem you will design and implement C++ code that identies overlap in strings.
Specically, design and implement a C++ program that does the following:
1. Asks a user to input a lename and then opens that le. If the le open fails, then
print the message “Unable to open le” and terminate the program using exit(1).
2. Reads the le contents, in order, into an array of strings. (See the le format expla-
nation below.)
3. Computes the string overlapping order described below, and then prints the strings
out, one per line, in that order.
4. Closes the le.
File Format: The data le consists of a number of strings, each on its own line. You do
not know in advance how many strings will be in the le, other than there will be no more
than 30 strings. Assume (i) there is at least one string in the le, (ii) the strings do not have
any whitespace in their interior, and (iii) the strings consist entirely of alphabetic, upper
case characters.
Here is an example of a data le containing four strings:
Overlapping Order: Here is the explanation of the string overlapping your program is
to nd in Step (3) above. Suppose we have the strings above read, in order, into an array
of strings. We start with the rst string in the array, AGGTGTGGA. What we want to
determine is which of the other strings’ beginning overlaps the most with the end of the
this rst string. Note this is a nontrivial problem since we do not know without further
analysis what the size of the overlapping substring will be. For example, if we just look
at the last character of AGGTGTGGA, the A, there are two other strings that begin with
A. If we look at the last two characters, GA, there are no strings starting with GA.

Leave a Reply

Your email address will not be published. Required fields are marked *