CMSI 284
Homework #2

Print the sources to the following problems and turn them in, in the order listed below, at the beginning of class on the due date. Also place your solutions in your CVS repository as follows:

    /homework/cmsi284/src/main/c/apps/piano_keys.c
    /homework/cmsi284/src/main/c/apps/piano_scales.c
    /homework/cmsi284/src/main/c/utils/max_string.c
    /homework/cmsi284/src/main/c/utils/rotate_string.c
    /homework/cmsi284/src/test/c/max_string_test.c
    /homework/cmsi284/src/test/c/rotate_string_test.c

Make sure that you have run the setup-class script so that I can checkout and run your code from CVS while grading.

  1. Write a C program that writes, to standard output, the names of the 88 piano keys and their frequencies. The program needs to actually compute the values; you cannot hardcode them.
    $ piano_keys
    A          27.5000
    A#         29.1352
    B          30.8677
    C          32.7032
    C#         34.6478
    D          36.7081
    D#         38.8909
    .
    .
    .
    A#       3729.3101
    B        3951.0664
    C        4186.0090
    
  2. Write a C program that takes a command line argument which is the name of a piano key, and writes to standard output the major and minor scales for that key.
    $ piano_scales F#
    F# major: F# G# A#  B C# D#  F F#
    F# minor: F# G#  A  B C#  D  E F#
    
  3. Write a C function which takes in two "strings" (pointers to bytes in memory with a zero at the end), and returns a new string containing, in each position i, the maximum of the two characters at corresponding positions of the two input strings. If the two strings have different lengths, your result should have the length of the longer string, and all of the extra characters in the longer string will simply appear in the result at their original position.
  4. Write a C function that takes in a string s and an int k and returns a newly allocated string which is the k-fold left rotation of s. For example, perfoming this operation on "doghouse" and 3 will return "housedog". More examples:

        rotate("doghouse", 0)  ===>  "doghouse"
        rotate("doghouse", 1)  ===>  "oghoused"
        rotate("doghouse", 2)  ===>  "ghousedo"
        rotate("doghouse", 3)  ===>  "housedog"
        rotate("doghouse", 4)  ===>  "ousedogh"
        rotate("doghouse", 5)  ===>  "usedogho"