Hands On C++: Project 4


Objectives

1. Practice solving problems that involve string objects.
2. Gain familiarity with the remaining string operations.

Introduction

Each of the following projects involves the use of character strings, and can be solved using the string library. In each case, the function you write may be useful someday, so store it in a separately-compiled library for reuseability, and supply a driver program that tests your function. Your instructor will tell you which project you are to do.

Projects

4.1. As written, our Piglatin() function fails to correctly translate words such as yes (esyay) and yellow (ellowyay) in which the first vowel 'y' is actually being used as a consonant. It also fails to correct translate words such as quiet (ietquay) and quack (ackquay), in which the first vowel is a 'u' following a 'q'. Redesign the algorithm used by Piglatin() so that it will correctly translate words like yes, yellow, quiet, and quack, without losing the ability to correctly translate words like style, rhythm, luck, and blue.

4.2. A character string is said to be a palindrome if it reads the same when the order of its characters is reversed. For example, the following are all palindromes:

   madam
   smada bob adams
   able was I ere I saw elba
Write a function that, given a character string, returns true if that string is a palindrome, and returns false otherwise.

4.3. A (very) simple encryption method is to reverse the order of the characters in a word, so that if the characters in the message

   OEMOR OEMOR EROFEREHW TRA UOHT
are reversed word-by-word, then the decoded message reads:
   ROMEO ROMEO WHEREFORE ART THOU
Write a function that, given a character string, returns the reverse of that character string.

4.4. Internet mailers and news-readers often contain a "rot13" function that can be used to "encrypt" words by rotating their characters 13 positions (i.e., A becomes N, B becomes O, C becomes P, ... Z becomes M). This is convenient, because the same function can be used to both "encrypt" and "decrypt" a word:

   rot13("ROMEO") == "EBZRB"
and
   rot13("EBZRB") == "ROMEO"
Write a Rot13() function that, given a string, returns a string whose characters are those of the first string rotated 13 positions. (Hint: You may find the % operator to be useful.)

Turn In: A hard copy of this grade sheet, attached to hard copies of

  1. your design for this project;
  2. all source files you created for this project; and
  3. the output from an execution of your executable program showing that it correctly solves the problem.

Don't forget to remove your binaries when you are all finished...


Back to the Lab Exercise

Back to This Lab's Home Page


Copyright 1998 by Joel C. Adams. All rights reserved.