Assignment 04

The user, after making any choice (except to quit), should be presented with the menu again. If Quit is chosen, the program terminates (after a pleasant sign off message, of course). No option should be acted upon if the required information has not been entered. For example, upon running the program, if the user chooses option 4 before option 1 has been chosen, your program should give them some kind of "warning" or error message and then return to the menu.

Details: For the options in the menu, follow these instructions:

  • For option 1: Your code should accept input no greater than 5 digits in length. Re-prompt if this requirement is not met. Likewise, negative values are not to be accepted. If these requirements are not met within 3 attempts, return to the menu.

  • For option 2: Similarly, your code should only accept the prescribed input. Again, give them 3 attempts at proper input.

  • For option 3: Given that options 1 and 2 have indeed been successfully chosen and satisfied, your code is to verify that x entered in option 1 is indeed a number of base n. [Hints: if you are not familiar with different bases, read this. A number x can be a base n value only if the digits of x are less than n. E.G. x = 110011001 can be base 2 or larger since only 1s and 0s are the digits of x; likewise, x = 326343 can be of base 7 or greater since all the digits are less than 7.

  • For option 4, display the base 10 (decimal base) equivalent of the base n value x. If this is troubling to you, again consult this and/or read on...Here's some math that will help you understand. The subscript represents the base.

      • 45710 = 4 × 102 + 5 × 101 + 7 × 100 = 4 × 100 + 5 × 10 + 7 × 1

      • 2236 = 2 × 62 + 2 × 61 + 3 × 60 = 2 × 36 + 2 × 6 + 3 × 1

Due: Monday, Sept 24, 2018 at noon 100 pts

For this assignment, you will submit a single C++ compilable file containing a program written in C++. Remember, to submit a file for this course electronically, from the directory in which the file resides type in at the UNIX prompt the command: cssubmit 1570 section_letter assignment_number. Be sure that only the file you want to submit is in that directory - make a directory for every assignment! The submit system will deliver every .cpp file in the current directory to me. 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 for the submit script.

Background: Krusty has been very successful as a business man selling barely-identifiable-as-food hamburgers to unsuspecting saps who enter his establishment, but what the heck. He recognizes that his scam will probably come home to bite him some day, so he wants to study the very rudiments of math and science so that maybe some day he can attend a prestigious institution of higher learning. So he figures he'd better start with mathematics. To that end, you are tasked with writing him a program that will help him understand numbering systems.

Specifications: Your program is to greet the user with a menu of options. It should look like this:

Options

-----------

1. Enter a non-negative integer, x [5-digit or less]

2. Enter an integer base, n. [ 2 <= n < 10 ]

3. Verify x is a valid base n number

4. Convert x to base 10

5. Quit

When you submit, as usual your code will be compiled and run during submission. You become the user. You will do the following:

  1. choose option 4

  2. choose option 1 and enter -34

  3. try to enter 222222

  4. try to enter -5

  5. choose option 1 and enter 732

  6. choose option 2 and enter -4

  7. try to enter 4

  8. choose option 3

  9. choose option 2 again and enter 9

  10. choose option 4

  11. choose option 2 again and enter 8

  12. choose option 3

  13. choose option 4

  14. quit

As always, if you have questions, be sure to ask your instructor or your cat. If you don't have a cat, visit your nearest animal shelter. If any cat answers you in English, let me know.

Note: In coding this problem, you are welcome to use the pow function that is part of <cmath> library. You will need to #include <cmath>. So, for example, pow(4,5) is 45.

... and one more ...1001102 = 1 × 25 + 0 × 24 + 0 × 23 + 1 × 22 + 1 × 21 + 0 × 20 = 1 × 32 + 0 × 16 + 0 × 8 + 1 × 4 + 1 × 2 + 0 × 1

With these examples of how bases work, you should be able to figure out how to compute a base 10 equivalent of any number in another base.

Be sure to make your output "user friendly". You are required to use the switch-case statement to handle the options of the main menu.