COMS W3101-2
Homework 2: Control Flow, Containers, & Random Numbers
Worth: 20% of total homework grade.

Goals:

The goal of this homework is to help you become comfortable utilizing conditional execution, while loops, vectors, generalized algorithms, and random numbers.

Assignment:

  1. hw2a.cc (25%)
    A program to count the number of 's' characters in an input string
    Hint: C++ string is a container. Consequently a string can be accessed and manipulated just like other containers such as vectors.

  2. hw2b.cc (25%)
    Random Die: make a program that prints out the results from 20 rolls of a fair 9-sided die, one roll per line.

  3. hw2c.cc (25%)
    A program that asks for a secret password (the password is "open-seasame") and prints "authenticated" if the input matches, "invalid" otherwise. Three tries are allowed.

  4. hw2d.cc (25%)
    A program that accepts one string per line. When input is stopped with an END-OF-FILE character, EOF the program prints out the input lines in alphabetical order. EOF is automatically appended by the Operating System (OS) to the end of almost all files. When using the keyboard for input, the key combination ctrl-d will generate an EOF character on most UNIX or LINUX systems (ctrl-z for Windows Systems).

    on input:
    Charles Manson
    Jennifer Connely
    Igor Vladmir Vladovitch

    the output:
    Charles Manson
    Igor Vladmir Vladovitch
    Jennifer Connely
    should be produced.
    Hint: use getline() for input

Files to be submitted:

Remember, all source code files should be clearly commented. Code should be clean and easily readable. Errors should be checked or handled according to your current knowledge-base.

If your files are not named according the above conventions, they will not be graded and you will receieve NO CREDIT.

For README and typescript requirements, look in the "How To" section.

How To:

Make your submission
Write a README
Make a typescript
Use CUNIX



Joshua Reich reich@cs.columbia.edu
Last Modified: March 20, 2006