Saint Louis University |
Computer Science 180
|
Dept. of Math & Computer Science |
Please see the general programming webpage for details about the programming environment for this course, guidelines for programming style, and details on electronic submission of assignments.
For this assignment, you must work individually in regard to the design and implementation of your project.
Please make sure you adhere to the policies on academic integrity in this regard.
In Python, the str class supports a convenient count method that can be used to compute the number of occurrences of a character within a string. The C++ string class does not offer such a behavior. Given that we are not the authors of the string class, one alternative is for us to write our own function to compute such a count.
For this assignment you should develop a function named count that takes a string and a character as parameters, and returns the number of times the given character occurs within the given string. You are to then demonstrate the use of that function with the following application.
DNA can be represented as a string over the limited alphabet 'A', 'C', 'G', 'T'. One significant measure in molecular biology is the "GC content" of a DNA strand, namely, the percentage of characters that are either C or G (as opposed to A or T). Use your count function to compute the GC content of a DNA strand given by the user. Your main program should precisely match the following user interface:
Please enter the DNA: CGTTGCACGACCA The GC content of that string is 61.54%.
To complete this assignment, you will need knowledge covered in Sections 1 through 4 of the transition guide. For the string class you do not need to master the full menu of behaviors yet; minimally, you need to know that syntax dna[i] can be used to access the character at index i of that string, and that dna.size() returns the overall length of the string. In order to get the percentage displayed with the desired precision, you will need to read about the <iomanip> library, covered in Section 4.2 of the Transition Guide (and in more detail in Chapter 9 of the Koffman/Wolfgang textbook).
Source Code
Please submit a single file named dna.cpp containing
your source code.
Readme File
For each assignment, you are to submit a separate "readme" file as
specified in the general programming webpage.
The assignment is worth 10 points.
The count method in Python did more than check for the number of occurrence of a character within a string. It would report the number of occurrences of a larger substr with another string. For example, it could determine that the number of occurrences of is within Mississippi is two.
For 1 point of extra credit, write and submit a second program named extra.cpp that has a new version of a count function, this one accepting two string parameters: the first being the full string and the second being the desired pattern. Provide a simple main routine that can be used for testing this functionality using the following user interface:
Please enter a string: Mississippi Please enter a pattern: is There are 2 occurrences.
Notes:
For simlicity in gathering input, you may assume that whitespaces are disallowed in both the string and the pattern.
To accurately mimic Python's behavior, reported occurrences of the pattern must be disjoint to be counted. For example, with a string banana and a pattern ana, Python would report a count of one (although such a pattern can begin at the second or fourth characater, it is not possible to have two disjoint occurrences).