CS260

MP6


Please see program documentation requirement. Also see BONUS POINTS.


Problem 1

Write a program that simulates the rolling of two dice. The program should use rand to roll the first die, and should use rand again to roll the second die. The sum of the two values should then be calculated. Since each die can show an integer value from 1 to 6, then the sum of the two values will vary from 2 to 12 with 7 being the most frequent sum and 2 and 12 being the most infrequent sums. Your program should roll the two dice 36,000 times. Use a single subscripted array to tally the number of times each possible sum appears. Print the results in a tabular form.

When performing a simulation such as this, you should always do a sanity check on the results the simulation generates. There are six ways to roll a seven using two fair die, so approximately 1/6 * 36,000 of the rolls should be a 7.

Save your program as mp06a.cpp.


Problem 2

A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data is transmitted as four-digit integers. They have asked you to write a program that will encrypt their data so that it may be transmitted more securely. Your program should read a four-digit integer and encrypt it as follows: Replace each digit by (the sum of that digit plus 5) modulus 10. Then, swap the first digit with the second, and swap the third digit with the fourth. Then print the encrypted integer.

Here is the beginning of a sample dialogue (user input is in bold):

Please enter a number to be encrypted: 1234
The encrypted value is: ????

Save your program as mp06b.cpp.


Problem 3

Write a separate program than inputs an encrypted 4-digit number (encrypted using mp6b.cpp), and decrypts it to its original form.

Here is the beginning of a sample dialogue (user input is in bold):

Please enter a number to be decrypted: ????

The decrypted value is: 1234

Save your program as mp06c.cpp.


What You'll Turn In:

Submit the files mp06a.cpp, mp06b.cpp and mp06c.cpp to the homework web site. For mp06c.cpp indicate in your comment when you submit if you have implemented the bonus point portion.


Bonus Points (Optional)

You can receive 25 bonus points for implementing the following:

You've received a handout that explains the use of the argv and argc parameters that may be used with the main function. argv and argc allow the user to specify information to an executable file (.exe file) from the DOS command line.

Take your implementations of mp6b and mp6c and allow the user to specify the values to be encrypted on the command line. The interaction would look as follows (as viewed from the DOS command line (C:\ prompt). User input is in bold:

mp6b 1234
The encrypted number is ????

mp6c ????

The decrypted value is 1234

Hint: You will need to use the atoi function in stdlib.h to accomplish this.