CSE110 Spring 2001

Homework #4

Due Friday, February 23rd at 5pm

Note: bold text in the examples is input from the user.


  1. [30 points] If you had a big enough diamond, you could hock it and spend all day at the hog fights. Write a program that prints diamonds of any integer radius r given by the user, using pixels of pound (`#') and space (` ') characters, as shown below. Since the complete diamond must have an odd width, let the width be equal to 2r+1.

    Example:

    % a.out
    How big a diamond do you want? 4
    Here you go:
        #
       ###
      #####
     #######
    #########
     #######
      #####
       ###
        #
    
  2. [30 points] You didn't really think a diamond like that would get you into a high-stakes hog fight, did you? Look at the roughly hewn edges -- even an amateur could tell it's a fake. Write a program to print more convincing diamonds using the slash (`/') and backslash (`\') characters, given a radius by the user.

    Example:

    % a.out
    How big a diamond do you want? 4
    Here you go:
       /\
      /  \
     /    \
    /      \
    \      /
     \    /
      \  /
       \/
    
  3. [25 points] Your diamonds may be good enough to get you into the game, but without a sure-fire way of picking winners, you might as well just be playing penny-ante factoring games with your shoe all day, like you did last week. Luckily, you happen to know that hogs with lots of vowels in their names (`a's, `e's, `i's, `o's, or `u's) tend to have better kung fu. Write a program that reads in the name of a high-stakes combat hog one character at a time until a newline character is encountered (`\n'), keeping track of the number of (upper or lower case) vowels and consonants that the name contains. If the name contains more vowels than consonants, the program should predict the hog will win the next bout, and if the name contains more consonants than vowels or the same number of consonants as vowels, it should predict that the hog will lose.

    Example:

    % a.out
    Hog name: Abagail
    This one will win.
    % a.out
    Hog name: Balthazar
    This one will lose.