Topical Information

This program gives you continued practice with branching, looping, and even a little bit of string play...well, storing and printing them, anyway...*shrug* (But perhaps more importantly, you'll also get to work with integer math again!) (And not just within the context of random number generation...)

Program Information

Write an algorithm which can store into a string variable the two letters which are the proper suffix of a particular integer as typically used for printing.

To test your algorithm, embed it in a program which reads an integer from the user and then displays it and its suffix form.

For example, if the user entered the value 1, you would place 's' and 't' into the string and display their number and your string (because 'first' is also represented as '1st' -- and since we can't exactly do 1st -- i.e. superscripting -- without more font control than a terminal window typically allows).

To refresh your memory, the pattern for suffices (suffixes?) is:

   1st   2nd   3rd   4th   5th   ...  10th
  11th  12th  13th  14th  15th   ...  20th
  21st  22nd  23rd  24th  25th   ...  30th
  31st  32nd  33rd  34th  35th   ...  40th
  ...
 101st 102nd 103rd 104th 105th   ... 110th
 111th 112th 113th 114th 115th   ... 120th
 121st 122nd 123rd 124th 125th   ... 130th
  ...
 201st 202nd 203rd 204th 205th   ... 210th
 211th 212th 213th 214th 215th   ... 220th
 221st 222nd 223rd 224th 225th   ... 230th
  ...

To test your program, ensconce it within a yes/no style loop to allow ease of testing.


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

$ suffix_test.out

                 Welcome to the Suffix Testing Program!!!

Enter a value: 1

That would be the 1st.

Test another value?  You bet!

Enter a value: 11

I'd have to say the 11th.

Test another value?  yes

Enter a value: 534252

That sounds like it could be the 534252nd.

Test another value?  nyeah

Thank you for using the STP!!

Endeavor to have a purple-textured day!

$

Thought Provoking Questions

  1. What two digits of the integer determine which suffix it should have? (Hint: One is typical and one is special/exceptional...)
  2. As mentioned in the hint, only one of these digits is used most of the time, what is the special 'condition' that happens only 'rarely' to make us use the other digit?
  3. How do you extract these digits from the user's whole number? (Yes, it is supposed to be an integer -- not a string! Note the integer math in the topic list above...)
  4. How many branches does it take to differentiate the five cases from one another? ("One case for the exceptional rule; three cases for the regular rules; and one case for everyone else!") How many conditions must be tested in this branching? Are any of these branches cascaded from/on/with one another?
  5. How can your program allow the user to type both 'y' and 'yes' for their again response? (Hint: This part of the program does NOT involve strings!!!)
  6. 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...)
  7. Are there any loops besides your yes/no loop? (Hint: there needn't/shouldn't be...)
  8. How many tests would be needed to thoroughly test your suffix generation algorithm? (You can ignore the yes/no loop around it for this calculation...)
  9. You hear a fellow student in the I mega-lab saying of this lab, "This is silly! In a real interface I'd be able to use fonts to make this thing look nice! Why are we wasting our time with this?!" The person is obviously distraught and disturbed... Calm them with a sensible defense of this lab's usefulness.

    ......Go on, I'll wait......

    Okay, so what did you tell them? (They seem much more focused now. *grin*)
  10. BTW, how can you have your program print different response text before the suffix'ed number result? (You did notice that in the sample run above, didn't you? You've got a good eye for detail!) (Hint: Think of it as a random message...)

This assignment is (Level 2).

Options


Total Level Possible

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