CSE110 Spring 2001

Homework #2

Due Friday, February 9th at 5pm

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


  1. [25 points] Squirrel farmers are so lazy, they need to be told thirteen times to feed their damn squirrels before they'll get around to it. Thirteen times! Their wives don't have the time to go through that every day, so they need you to write a program to administer the requisite nagging. Your program should only contain the line "Feed your damn squirrels!" once, inside a for loop that iterates thirteen times.

    Example:

    % a.out
    Feed your damn squirrels!
    Feed your damn squirrels!
    Feed your damn squirrels!
    Feed your damn squirrels!
    Feed your damn squirrels!
    Feed your damn squirrels!
    Feed your damn squirrels!
    Feed your damn squirrels!
    Feed your damn squirrels!
    Feed your damn squirrels!
    Feed your damn squirrels!
    Feed your damn squirrels!
    Feed your damn squirrels!
    
  2. [30 points] Your new scheme is to breed squirrels for fun and profit. You can find them in the park, you don't have to remember to feed them (your spouse can remind you), and they double their population every month. Write a program that keeps track of your damn squirrels by printing out monthly projections of the size of your horde, assuming you start with one (which reproduces through mitosis), and you find another one at the end of every month. Your program should prompt you for a maximum number of months to project, and should run by multiplying and incrementing a variable runningTotal within a for loop.

    Example:

    % a.out
    How many months before you get sick of this squirrel stuff? 6
    End of month 1: You bred 2 squirrels and found 1, for a total of 3.
    End of month 2: You bred 6 squirrels and found 1, for a total of 7.
    End of month 3: You bred 14 squirrels and found 1, for a total of 15.
    End of month 4: You bred 30 squirrels and found 1, for a total of 31.
    End of month 5: You bred 62 squirrels and found 1, for a total of 63.
    End of month 6: You bred 126 squirrels and found 1, for a total of 127.
    Congratulations on a successful harvest!  Too bad squirrels are worthless.
    
  3. [30 points] Your squirrel farming scheme may have been a bust, but you can still make some dosh by selling your population projecting software to other skiourophiles. Of course, you'll need to clean up the output a little, first. Have your program align the columns in each row of output to look as in the example below, and calculate the cash value of the each month's crop of squirrels at the federally guaranteed rate of seven cents apiece.

    Example:

    % a.out
    For how many months would you like quality professional-grade projections? 7
    Month 1:    2 squirrels bred + 1 found  =    3 squirrels.  Cash value: $  0.21
    Month 2:    6 squirrels bred + 1 found  =    7 squirrels.  Cash value: $  0.49
    Month 3:   14 squirrels bred + 1 found  =   15 squirrels.  Cash value: $  1.05
    Month 4:   30 squirrels bred + 1 found  =   31 squirrels.  Cash value: $  2.17
    Month 5:   62 squirrels bred + 1 found  =   63 squirrels.  Cash value: $  4.41
    Month 6:  126 squirrels bred + 1 found  =  127 squirrels.  Cash value: $  8.89
    Month 7:  254 squirrels bred + 1 found  =  255 squirrels.  Cash value: $ 17.85