Assignment 02

Due: Wednesday, Feb. 10, 2021, at noon, 100 points.

Background: Business is now booming with Bart’s gambling scheme. But recently there’s been too many lucky ... maybe too lucky and too many ... gamblers who seem to be cheating. Bart thinks that there are some who are counting cards at the blackjack tables. Bart sets up cameras all over the casino and his associates watch the area. Not knowing how advanced the enemy actually is, Bart sets up a cipher system among his workers. Because he's cheap and doesn’t want to buy anybody cell phones, he steals Homer’s set of pagers (those he bought 20 years ago when Homer thought he could resell them for millions). If you don’t know what a pager is…ask your parents ... uhh, grandparents. Pagers can’t exactly “text”, instead a computer has to send a message to the pager, and the pager can only receive messages. To encode his transmission and to act quick, Bart develops a code that consists of only numbers that will be sent to all the pagers. The pagers will then translate the numbers into text. Your job is to write a program that will translate Bart’s code into text.

Specifications: Your program is to prompt for and read in from the user the five-digit code that we will sometimes refer to as the Action Number (AN). You will use the following guide to translate Bart’s cipher into text:

Suppose we think of the 5-digit AN being formatted abcde, where e is units, d is the number in the tens place, c in the hundred place, etc.

  • If the AN is even, the card counter (the "bad" guy) is still “at the table”.

  • If the AN is even and c is 3, the card counter is “under the table”.

  • If the AN is odd and b is 4, the card counter is “on the run”.

  • If the AN is odd and b+c is 4, the card counter “drank too much Duff Soda and is throwing up in the bathroom”.

  • If AN is odd and (a + c + e - (b + d))is divisible by 11, then “Lisa is trying to report Bart”.

For this assignment, you will submit a single C++ compilable file containing a program written in C++. We suggest (strongly) that you make a directory for every assignment! Name your file a meaningful name and give it a .cpp extension since you will be compiling it. Also, make sure that you compile and run your program using the GNU (g++) compiler before submitting to make sure that it will work.

Remember: When writing your code, be sure to:

  • Use meaningful variable names.

  • Use proper spacing for indentations.

  • Use constant variable declarations where appropriate.

  • Include the comment block at the head of your file.

  • Comment code that needs it.

  • Be literate in your welcoming/signing-off messages and prompts and output.

  • NOT use the switch-case statement. Besides, we haven't covered it yet.

And, as always, if you have questions about this assignment, ask your instructor.

Any other case “we don’t know” where the car-counter is.

Once your program has determined what the code means, it should echo the inputted code (the AN) and output exactly the message that it translates to. After that, it should prompt the user of the program if he/she desires to input another code for translation. If so, the routine is repeated. Otherwise, a sign-off message is displayed and the program terminates. Now, because Bart prefers skateboarding around town with his buddy, Milhouse, he wants to limit the number of bad guys he might have to deal with. So, the repeating nature of this message sending routine will be limited to 4 times so that Bart can feel good about being irresponsible. In other words, a maximum of 4 messages (excluding invalid input, i.e. don't count re-prompts for valid codes) can be sent to the pagers before your program signs off.

A sample run might look like this:

Bart's Security Service Analyzer

Enter code: 15344

The code 15344 means: card counter is under the table at the table

Translate another code (y/n)? _ y

Enter code: 4255

The code 4255 is invalid; try again: 73843

The code 73843 means: Lisa is trying to report Bart

Translate another code (y/n)? _ n

..........signing off.....ciao for now

Notes:

  • the code is to be read in from the user as an integer (type).

  • you can assume that the entered value will be positive.

  • you can not assume the entered value will be five-digit, so you must ensure that the user enters a 5-digit integer (thus, a cannot be zero) before proceeding.

  • your output should reflect any and all conditions above that fit the input.