CS201 – Spring 2001

Prof. Hartman

Homework #4

Due Friday, February 16th by 5:00 pm

 

Recommended Self-Review problems in Chapter 3, pp223-226 3.4, 3.5, 3.6, 3.7

 

Homework to be turned in (remember that all programs must follow the guidelines from handout #3.

Written:

1)      For each of the following sets of integers, write a single statement that will print a number at random from the set:

a.       1,2,3,4,5

b.      3,6,9,12,15

c.       4,7,10,13,16

d.      7,13,19,25,31

Programming:

2)      You are working for a very strange boss who has decided he is afraid of the * character. Create your own multiplication function that will return the product of two integers, without using * (the multiply operator). Put your function in a test program to show how it works.

3)      Write the standard “guessing game” program.  Have the program select (at random) a number from 1 to 1,000 and have the user make guesses at what it is. After each guess, the program should tell the user whether they were too high or too low, and the game should continue until the user guesses the number. (How many guesses should the user take, at worst? If you know the answer to this question, you can insult the user if they take more than that many guesses.)

4)      You and a friend are looking for a quick and easy code so that you can send secret messages to each other.  You decided to send each other the ASCII number for each letter in your message.  Fortunately, this is exactly how C++ converts characters to integers and vice versa, so it won’t be very hard to do.  (Unfortunately, it’s not very secure, either, so don’t be sending anything you don’t want others to figure out!) Write a program that you can use for this job. It should begin by asking you whether you want to encode or decode a message. Once you have chosen, it should either input one character at a time (encoding) or one integer at a time (decoding) and output the equivalent. For a sample run, encode the “word” SuperSekrit and then decode the result.

5)      Create a program that will randomly create passwords for you.  The passwords are to be eight characters long. The first six characters are to be alphabetic characters A-Z and a-z. The last two characters are to be numbers in the range of 0-9.