This program will provide you the chance to show your mastery of functions and decision making — and perhaps a bit of modulo! (Of course, you'll continue to make elegant use of character input's amazing properties.) There are also options for making a library and using repetition.
During the first few weeks of the semester (ANY semester), students are so lost that simple reasoning flies out the window. Between 5 and 10 people a day come to most teachers and staff and ask: "Where's H131?". Unfortunately, most of them are on the second floor when they ask this...*sigh*
Administration has commissioned an automatic service which we are to prototype (HA! And you thought we'd just made up that word! *phbbt*). The user will enter their room and the system will tell them which floor it is on. (Future versions will also allow the system to tell the user to head left, right, etc. ...or perhaps to simply turn around.)
You'll need to read rooms of the form 'H131' and print output such as "That's on the 1st floor of the H building!" (Just to make things easier, we'll assume that all floors can have at most 100 rooms numbered 00 to 99 — this seems fairly standard, anyway.)
Use separate functions to:
read their building and room number (one function; two results; no 'inputs')
determine the floor (one result; one input)
determine the suffix characters/string (st, nd, rd, or th) for the floor (one input; one or two results)
As an example, you might have the program interaction look something like (the parts in this color are typed by the user):
$ ./floor.out Welcome to the Floor Determining Program!!! Which room are you looking for? d221 Thank you!! Calculating... Done. Your room is on the 2nd floor of the D building. Do you have another class/office to find? y Which room are you looking for? J109 Thank you!! Calculating... Done. Your room is on the 1st floor of the J building. Do you have another class/office to find? Y Which room are you looking for? n390 Thank you!! Calculating... Done. Your room is on the 3rd floor of the N building. Do you have another class/office to find? n Thank you for using the FDP!! Endeavor to have a localized day... $
How do you separate the user's building letter from their actual room number? (Hint: How did you read die-rolls or times of day or even initials with periods?)
How can you allow the user to enter either upper or lowercase letters for the yes/no question?! (It's amazing!)
How can you decide which floor their room is on from the room number?
Given a value like 4 or 11 or 23, how can you tell what suffix to print (st, nd, rd, or th)? Is there a pattern?
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th 26th 27th 28th 29th 30th 31st 32nd 33rd 34th 35th ... . . . 100th 101st 102nd 103rd 104th 105th ... 110th 111th 112th 113th 114th 115th ... 120th 121st 122nd 123rd 124th 125th ... . . .
How can a function input a number (note: function input!) and 'return' as output 2 letters!? A char can store only a single value at a time and the return value can only be one thing. How can we possibly do this? (Hint: There are two ways...)
This assignment is (Level 4).
Add (Level 1) credit for placing your suffix determining function in a library. In fact, add another (Level 0.5) to re-use the suffix library you created in the analogous lab.
Add (Level 1.5) credit for allowing the user to type the word 'yes' or the word 'no' instead of limiting them to 'y' or 'n' (or 'Y' or 'N') on your yes/no question(s). (Hint: You don't have to use more than the first character, you just need to let them type more. Perhaps an ignore or even a peek/ignore loop? Which do you think is better here?)
Add (Level 3) credit for placing a building set-up phase in the execution.
Before asking for the room, ask for building info: is there a basement; does the basement count as 0-hundred or 1-hundred (this is something that changes from region to region and culture to culture); how many floors; what is the building's letter? Then proceed to the loop outlined above for each room they enter — but you are only processing for the building whose info the set-up-er just entered. I.E. if they enter J102 and you are working with building I, tell them it isn't in this building and move on.
When they are done with that building (i.e. they have no more rooms in that building), ask if they also have another building. If so, loop back to the set-up phase. If not, you are done.
Add (Level 3) credit for adding the number of rooms per floor to the set-up phase information. If they ask for room 842 and you were told this building only has 30 rooms per floor, tell them it doesn't exist.
When calculating floors, use the 100-rooms-per-floor rule unless they've told you a floor can hold more than 100 rooms, then use an n-rooms-per-floor rule where n is calculated as the smallest multiple of 100 greater than the number of rooms they said a floor can hold. So 243 will be on floor 2 unless the number of rooms per floor is over 100.
If they've stated there are even 101 rooms per floor, room 243 would be on floor 1 — well, except that room 243 wouldn't exist. You know, since floor 1 would hold rooms 100-200 and floor 2 would hold 300-400 so there wouldn't actually be a 243. (Weird, no? Now do you see why folks start lettering rooms rather than have more than 100 room numbers per floor?)
If you did all above options, this project could be worth as much as (Level 13).