[MSOE Homepage]

Dr. Taylor's MSOE Homepage

Unix is a Four
Letter Word

My Photo Album

My Personal Homepage

CS-285 Main page

CS-285 -- Lab 3: Generic Algorithm Implementation

Winter Quarter 1999-2000



Electrical Engineering and Computer Science Department
Dr. Christopher C. Taylor

CC-27C, 277-7339

www.msoe.edu/~taylor/

Purpose

The purpose of this lab assignment is to provide exposure to iterators and generic algorithms. This is accomplished by designing and implementing a generic algorithm the same functionality as the STL's generic algorithm replace_if().

Assignment

The heavy emphasis on iterators in STL makes it possible to implement generic algorithms that can be used on multiple container types (provided that the correct type of iterator is available). These generic algorithms alleviate the need to write unique member functions for each container type. Not only does it reduce the amount of code that needs to written, debugged, and maintained, it also provides a common interface for all container classes that have the correct type of iterator needed by the generic algorithm.

In this lab, you are to do the following:

  1. Design and implement a generic algorithm called rpl_if() that has the same functionality as the STL generic algorithm replace_if() on the string class. You are not allowed to use replace_if() in your implementation of rpl_if() (hopefully this is obvious).

    The generic algorithm should be called as follows:

    rpl_if(cont.begin(), cont.end(), pred, new_val)

    For every element in the container, cont, for which the predicate, pred, returns true, the element is replaced with new_val.

  2. Design and implement the following boolean functions:

    • isvowel() -- returns true if the character is a vowel (assume y is a vowel). (See note below.)
    • isconsonant() -- returns true if the character is a consonant. (See note below.)
  3. Write a program that will use your implementation of the above functions and the cctype library to replace all vowels with v, all consonants with c, all whitespace with w, and all punctuation with p in the course syllabus.

Note: You may alternatively decide to make your predicate a function object in which case you are not required to implement isconsonant() and isvowel() as boolean functions. You are still required to implement the functionality required in step 3.

Lab report (due 11:00pm, the day prior to week 7 lab)

The lab report should be self-contained. That is, it should be possible for someone to understand what you did and why without seeing anything other than your report. Your report should include:

  • Purpose
  • Problem Statement
  • Procedure -- what approach you used to solve the problem
  • Documented source code (you may wish to include this at the end of your report)
  • Discussion (include your program output and any problems you encountered, etc...)
  • A summary of your activity log indicating how much time you spent on each phase of the assignment. Please report the time in the following categories:
    • Design
    • Coding
    • Debug (before you think it's working)
    • Test (after you think it's working)
    • Documentation
    • Other
  • Conclusions (what you learned, suggestions of how the lab could be improved, things you would have done differently, etc.)

As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic Submission Guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost. It may be wise to keep a diskette backup as well.

If you have any questions, consult the instructor.


This page was created by Dr. Christopher C. Taylor, copyright 1998-2000.