Topical Information

This program gives you practice with integer arithmetic, string building, branching, and looping.

Program Information

Make a program that translates Arabic numbers into Roman numerals.

SPECIAL NOTE
Don't display your Roman numeral conversion directly on the screen. Instead, store the Roman version of the user's number into a string variable. Then, after the conversion is complete, display the string to the screen.

Hint: Start by converting a one-digit number (between 1 and 9). Since each digit follows the same basic pattern, it should then just be a matter of extracting the correct digit and following the same conversion pattern.


As an example, you might have the program interaction look something like (the parts in this color are typed by the user):

$ ./roman.out

                 Welcome to the Roman Numeral Program!!!

Will you be converting numbers to Roman form with us today?  yes

Excellent!  Glad to have you along!

Enter your number:  4330

Oh, I'm sorry, that value is too large for Roman civilization.

Please try again with a number [strictly] less than 4000, thank you...

Enter your number:  0

Oh, I'm sorry, that value is too small for Roman civilization.

Please try again with a number [strictly] greater than 0, thank you...

Enter your number:  1330

Ah, I believe that would be MCCCXXX, right?

Would you like to convert another number?  y

Enter your number:  132

Hmm...I think that is CXXXII, right?

Would you like to convert another number?  nah...


Thank you for using the RNP!!

Endeavor to have a plebeian day!

$

Did you notice how the response text changed for each valid entry? Pretty spiffy, eh?

Thought Provoking Questions

  1. Is there a simple repeating pattern here that might help you extract commonality and save coding time?

               V      X         XC      XCV      C
       I       VI     XI   ...  XCI     XCVI     ...
       II      VII    XII  ...  XCII    XCVII    ...
       III     VIII   XIII ...  XCIII   XCVIII   ...
       IV      IX     XIV  ...  XCIV    XCIX     ...
    

    And similarly:

               L                   D
       X       LX     ...   C      DC     ...   M
       XX      LXX    ...   CC     DCC    ...   MM
       XXX     LXXX   ...   CCC    DCCC   ...   MMM
       XL      XC     ...   CD     CM     ...
    

    (Hint: complete this chart yourself and it might clarify the pattern.)

  2. How does modulo fit into this scheme? (Hint: Look, for instance, at 2 and 7... or 1 and 6... or 3 and 8...)

  3. Why will your program only work for values in the (integral) range [1..3999]? (Hint: What's the Roman numeral representation of 5000? How did Romans represent zero?)

  4. For the conversion of each digit to Roman form (except maybe the thousands digit), you should have four branches. How many are cascaded from one another?

    How many of these branches are nested aside from cascading?

    (For you worriers: it can certainly be done with more branches, but it can be done with just four branches.)

  5. What is the purpose of each of the three loops in your program? (Okay, so you actually should have six loops, but four of them are pretty much doing the same thing, now aren't they?)

  6. How many tests would be required to completely test this program? (Shockingly, it is far less than 3999!)

  7. Why does Jason want us to convert numbers from a dead civilization, anyway? (I.E. What are Roman numerals typically used for in our society?)

  8. How can your program allow the user to type both y and yes for their again response? (Hint: This does NOT involve strings!!!)

  9. How can your program allow the user to type both y and Y for their again response? (Hint: There are two ways, but one is far easier. You know, since it's mostly done for you in that library fun... Whoa! I almost let that one slip, eh? *chuckle*)

  10. How can you have your program print different response text before (and after?) the Roman numeral result? (Hint: Think of it as a randomly chosen message...or a pair of randomly selected leaders and trailers...)

Other Helpful Resources

You might find the following resources handy, as well:

(For those of you paying attention: NO, you do NOT have to represent any of the 'barred' forms, alternative forms, or fractions...but see the options if you are desperate for such...*smile*)

This assignment is (Level 3).

Options


Total Level Possible

If you did all above options, this lab could be worth as much as (Level 21).