Gavilan

CSIS054: Perl Programming

Homework set 2

 

1. Write a script that will compute the area of a geometric shape (triangle, square, etc). Ask the user how many sides the shape has, and how long a side is. Respond with the area of the shape. Be sure to document any limitations or assumptions that your script makes in the comments.

2. Write a script that asks the user for the radius of a circle. Using the radius, compute and report back to the user:

  • the circumference of a circle,
  • the area of a circle, and the
  • volume of a sphere of the given radius.

3. Write a script that asks the user these two questions:

  • Q1: Did you get up before 7am today?
  • Q2: Were you born before 1980?

and respond with the appropriate string from this table:

 
Q1
    Yes No
Q2 Yes You sound very mature. Shouldn't you be working harder?
No Relax! There's plenty of time What are you, some kind of slacker?

 

4. Modify the script guess.pl so that it keeps track of how many guesses it takes the user to get the right number. Report this number back to the user. Be sure to congratulate them if it is 4 guesses or fewer, and admonish them if it is 8 guesses or more.
5. Write a script, guess2.pl which plays the game from the opposite point of view. In other words, the user will choose a number (without saying what it is) and the computer will try to guess it. The user will tell the computer if it has guessed 'too high', 'too low', or correctly.

 

 

 



Address of this page is http://hhh.gavilan.edu/phowell/csis054/02problems.html
Please contact Peter Howell at phowell@gavilan.edu for questions or comments.
Last updated January 10, 2010.