Assignments | Class Photo | Computing Resources | Course Home | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 180
Data Structures

Michael Goldwasser

Fall 2008

Dept. of Math & Computer Science

Programming Assignment 01
GC Content of DNA

Due: Friday, 5 September 2008, 11:59pm

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.

Collaboration Policy

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.


Contents:


Overview

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%.


Advice

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).


Files to Submit


Grading Standards

The assignment is worth 10 points.


Extra Credit

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:


Michael Goldwasser
CSCI 180, Fall 2008
Last modified: Friday, 29 August 2008
Assignments | Class Photo | Computing Resources | Course Home | Lab Hours/Tutoring | Schedule | Submit