Program 4: Sheep, Functions, and Ancient Numerals

From Maryville College CS Wiki
Jump to: navigation, search

Introduction

In the land of Tuscany, before the birth of Romulus and Remus, there lived two shepherds named Reg and Stan. One morning, Reg noticed that something was amiss. "Stan, does it seem like we have fewer sheep today than we did yesterday?", he asked. Stan replied, "I don't know. Tell you what. Let's take this bone and cut a notch into it for each sheep, then we can recount it in the morning and see if there may be a wolf in our midst." That day, they set out doing just that. They took a lamb bone and carved notches:

Corriedale lambs in Tierra del Fuego.JPG
   ||||

The next day, they repeated the same task:

   |||

"Aha!", exclaimed Reg, "We are down by one. Let's stay up tonight and see what's happening to the sheep." That night they found a wolf prowling their fields. They killed the wolf by pelting it with rocks, thus preserving the number of their flock. Now, Reg and Stan became the most successful shepherds in all of Tuscany, and they had also made one of the first steps for building a mechanical computer. Their success, however, turned to dismay after a particularly successful lambing season. Reg returned with the following notches:

   |||||||||||||||||||||

Stan took one look and said "I just can't handle that many notches! It's hard to read at a glance. We'll spend all our time counting notches!" Reg thought it over and then said, "What if we change every 5th mark?" He then carved a new bone:

   ||||/\||||/\||||/\||||/\|

Stan took one look and said, "Ah! So every fifth mark is /\. Now we can count by fives. What if we extend it further, and made every tenth mark be overlapping 5's like this." Stan took the bone and carved:

   ||||/\||||X||||/\||||X|

Reg took one look and liked what he saw. "Now we can see at a glance, that we have 2 10's and 1 left over notch. That's bloody brilliant!" (All 7th century BC Etruscans used British slang. Just roll with it!). They then decided to expand this just a little further. They made a symbol for every 5th X and for every 2nd 50. Thus the Etruscan counting bone system was:

   Number  Symbol
   ------  ------
    
     1       |
      
     5       /\

     10      X
            /|\ 
     50      | 
 
     100    >|<

They didn't go above 100, because that was more sheep than they had ever seen in their lives. It's easy to see that this is a method that can be used for counting large numbers efficiently. Thus the Etruscan counting bone became one of the world's first manual computers!

In time, Reg and Stan decided they wanted to chart their business over long periods of time. Now that they had over 50 sheep, they were going through a lot of bones. One day as Stan was recording a year's worth of sheep he started to get tired. He had carved:

                                                              /|\
   ||||/\||||X||||/\||||X||||/\||||X||||/\||||/\||||X||||/\||||| 

As Stan was massaging his swollen wrist it hit him. "Oy! These notches are brilliant for adding, but they are rubbish for recording data." After a little thinking he said, "I have it! We can just take everything prior to the largest symbol as read, so I could just carve:

   /|\
    |

"and we'll know that those exhausting marks came before it. I could also just do groups of those, for instance, I could do XX for 20 sheep." Reg liked the idea, but there was just one small problem. "What about when you have one less than the big one?" "Oh yeah..." Almost at the same instant, a bolt of genius hit them. "What if we put the notch just before the big group. Like |X would mean 9 and we'd just understand that the 3 others are there. You know, they'd have to build up to it anyway." So they practiced and found that this worked well. |X for 9, |/\ for 4... and all was well.

Then came the rise of Populous Romanus. They liked Reg and Stan's counting method. They especially liked how it work for both counting and recording, but they thought the symbols looked like something that a shepherd would come up with. So, they decided to use letters. | became I, /\ became V, and so on. This made it easy for Roman stone carvers to carve numbers into Roman walls. They also extended the system a bit, so the total table of symbols became:

   Decimal  Symbol
   -------  ------
       1      I
       5      V
      10      X
      50      L
     100      C
     500      D
    1000      M

They also decided to call these things "Roman Numerals." Our Etruscan friends were none too pleased by this. "Bloody Romans!" they muttered, "What have they ever done for us?"

Having invented a way to track sheep, Reg and Stan have become fabulously wealthy. (Really it wasn't the sheep that did it. They won a massive patent infringement suit against the Romans for "Roman Numerals"). They, of course, had a problem. They had more sestertii than they knew what to do with.

"Did you ever see so much silver?" Stan said, his eyes gaping wide at the large budget of coins brought by the centurion.

"No." Reg replied. Reg looked very introspective, as shepherds are want to do. "I suppose we'd better expand our fields!"

"Brilliant idea!," Stan replied. They then set about buying all of the adjoining land to theirs. This, in turn, produced a runaway recursive problem. "You know, Reg. If we keep buying all the land that touches our ever expanding borders, we'll end up trying to buy the whole continent?!" Reg replied "Oh yeah. Maybe we should start buying some more sheep then." And that is precisely what they did. Unfortunately, they had bought so much land, that all the sheep in the Roman Empire would not fill their fields.

A Trip to India

"I guess we'll have to travel long and far looking for more sheep." Stan said one day. So the two set out into the world. They went to India first. They discovered that the Indian sheep were tagged with prices which were in some strange alphabet. "What is this?" Stan said pointing at the marks "123". The Indian merchant replied "That's One Hundred and Twenty Three Rupees." Stan quickly realized that there was more than one way to count numbers. This first number system they encountered was the Indian numeral system, which we incorrectly call "Arabic Numerals" thanks to a misunderstanding

by an 11th century English cleric.
Muhammad Ibn Musa al-Khwarizmi, the 9th century Persian cleric who wrote a book about Indian numerals, which is why we now call them arabic numerals.
The World's Oldest Zero
Me touching the world's oldest zero. 26 hours flying time & 17 hours of train travel, totally worth it!

The reader should already be familiar with these numbers, as they are the number system used the whole world over in the modern era.

"Well, the Indian number system is very nice! I especially liked the 0." Reg said as they were leaving. "Eh, it will never catch on" replied Stan.

A Quick Stop in Judea

After buying all the sheep in India, and making broad swaths through Arabia, Reg and Stan encountered yet another way of printing prices. They found a Jewish Shepard named Jethro. Jethro had a very nice ram which was labeled with (transliterated) "DTs". "Stan, what do you suppose that strange mark is?" Jethro explained, "Those are Hebrew letters, but here they are showing a number. This ram is worth 94 Shekels." "94 Shekels, that's quite a deal!", exclaimed Stan. They handed over the appropriate amount of silver, and the ram was theirs. Not missing an opportunity to learn something new, Reg asked Jethro about the Hebrew number system. Jethro explained the Hebrew alphabet, and how they had a system where each letter represented a number. He went on to show them how Hebrew is read from right to left. Stan took notes, however, given that Stan was not adept at forming the Hebrew letters, he wrote down their names, inventing a Romanized transliteration for each, and also wrote down their numeric values. Stan's notes are as follows:

     Name    Sound       Value
     ----    ---------   -----
     Aleph    * (none)       1
     Bet      B              2    
     Gimel    G              3
     Dalet    D              4
     Hei      H              5
     Vav      V              6
     Zayin    Z              7
     Het      Ch             8
     Tet      T              9
     Yud      Y             10
     Kaf      K             20
     Lamed    L             30
     Mem      M             40
     Nun      N             50
     Samech   S             60
     Ayin     ^ (none)      70
     Pei      P             80
     Tsadi    Ts            90
     Kuf      Q            100
     Resh     R            200
     Shin     Sh           300
     Tav      Ta           400
 

NOTE: If you are interested in the shape of these letters, just google "Hebrew Alphabet" and you'll find it. There are some wonderful coincidences in the Hebrew number system. For instance, the word for father is "Ab", the word for mother is "Haim" and the word for child is "Yaled". If we use our transliterated Hebrew numbers, we have B*=3, M*=41, DLY = 44. Thus "Mother + Father = Child".

They thanked Jethro, and they departed from the land of Judea and made their way back to Latinum. They were a bit puzzled by the silent letters, but they decided they could distinguish between them in Roman characters by using * for aleph and ^ for ayin.

A Grecian Odyssey

Along the way back to their peninsula, they passed through Greece. While in Greece they encounter a beautiful ewe. The ram they bought in Judea agreed that the ewe was beautiful, and before they could stop him, the ram expressed his admiration for the ewe in the way which sheep generally do! "You have spoiled my purebred sheep!" Screamed Aristophanes the Shepherd. "I am terribly sorry, but he got out of our hands." Reg said, in his most placating tone. "Since she is ruined for pure breeding, I think it only fair that we buy her from you.", said Stan. Aristophanes ignored Reg, but Stan's offer made sense.

"How much?" asked Reg. Like all sheep, this ewe had a price tag. The price tag read "TA". "How much is that?" Stan asked. "301 Drachmas" replied Aristophanes. "301 Drachmas! That's almost 5 times what we paid for the ram." shouted Reg, kicking the beast. "She is of a very rare breed, a fine line of sheep." Replied Aristophanes. They both sighed and paid for the sheep. In exchange, Aristophanes showed them the Greek Number system. Once again, being not at all used to printing out the strange characters of Greece, Stan wrote out their names, sound, and value.

   Name        Sound      Value
   ----        -----      -----
   Alpha         A            1
   Beta          B            2
   Gamma         G            3
   Delta         D            4
   Epsilon       Eh           5
   Vau           Va           6
   Zeta          Zd           7
   Eta           Ee           8
   Theta         Th           9
   Iota          Ey          10
   Kappa         K           20
   Lambda        L           30
   Mu            M           40
   Nu            N           50
   Ksi           X           60
   Omicron       O           70
   Pi            P           80
   Koppa         Ku          90
   Rho           R          100
   Sigma         S          200
   Tau           T          300
   Upsilon       Iy         400
   Phi           F          500
   Chi           Ch         600
   Psi           Ps         700
   Omega         Aw         800
   Sampi         Sa         900

Note: The astute reader will note the presence of a few extra letters. These letters are Vau, Koppa, and Sampi. These letters are alternate forms of Greek letters, basically indicating a different kind of stop for the consonants they represent. These letters were considered obsolete by about 403BC when Athens adopted the Ionian local variant of Greek spelling. They were still used for numbering though, otherwise the decades wouldn't work out!

Also, I have taken a few liberties. Originally, Greek was written right to left, as was Phoenician (from which it descends.) I have opted to use left to right, however, so that only the Hebrew section will be truly difficult. However, given the apparent time frame of our story, Greece would still have been writing from right to left. Sorry for the anachronism!

Now armed with a Judean ram, a Greecean ewe, and several soon to be Greco-Jewish lambs, Reg and Stan returned to the land of Tuscani where they put their new herds to pasture and passed on knowledge of the foreign number systems to their countrymen.

The Group Project

The task that is now before us is to help Reg and Stan carry out international commerce in the ancient world. We will suppose that they have a computer, one which can print only Latin characters, and they wish to trade with their neighboring countries. We want to be able to readily convert from any number system to any other number system. For Hebrew and Greek, we will use Stan's phonetic representations for our characters. That is, anytime you want an "Aleph" your program is going to print "*" and anytime you want a "Beta" your program will print "B". For the Greek letters this will almost work correctly anyway. The Romans, being ever jealous of the Greeks, stole a significant portion of the Latin alphabet from the Greek alphabet. (Even the name "alphabet" derives from the first two letters in Greek.)

An example run of this system can be found below:

 Welcome to Reg and Stan's Number Writer 500(BC)
 
 What number system would you like to start with?
   1.)  Roman/Etruscan
   2.)  Indian
   3.)  Hebrew
   4.)  Greek
 Choice?  1
 
 Roman Number: CCXII
 
 
 What number system would you like to convert to?
   1.)  Roman/Etruscan
   2.)  Indian
   3.)  Hebrew
   4.)  Greek
 Choice?  4
  
 Greek Number: SEyB

Additionally, your program should provide error checking for the menus. Extra credit will be awarded for programs which perform error checking on the number entry screens.

Group and Decomposition Details

You will be working in groups of 3-4. If you can't find a group to join, let me know and I will assign you to one. You will need to create a set of files to work together. Each group member will be responsible for some set of functions. The breakdown of files in my sample version of the program are as follows:

  • roman.h
  • roman.cpp
  • hebrew.h
  • hebrew.cpp
  • greek.h
  • greek.cpp
  • menu.h
  • menu.cpp
  • main.cpp

Each of the files representing different number systems have functions which have this type of signature:

 string indianToRoman(int n);
 int romanToIndian(string s);

We will be covering strings in more detail in the next lecture. For now, read up on them in your textbook! The words it contains will guide you on your path to wisdom.

Additionally, I wrote unit test files for each of the sub systems, so I had "romanTest.cpp", hebrewTest.cpp", "greekTest.cpp", "menuTest.cpp". I would recommend that each person in the group be assigned one of the subsystems and that they develop their files and their test files.


Submission Requirements

You will be using a separate github repository for this project. Your team leader will get the repository, and will invite you to the group. You will then want to clone this into your shell account, but not in your cs1 folder. You will be using github as your primary means of collaboration, and I will view your submissions from there.

As this is a group effort, only one program will be submitted per group. The top of each file, however, should indicate who wroked on the file. The format that I want to see is:

 //File: filename
 //Purpose: What the file does
 //Authors: List of people who worked on the file

If your name does not appear at the top of one of the files, you won't get any credit for the program, so make sure to label the stuff that you work on!

Major Extra Credit Opportunity! (10 points on the Midterm Exam)

Reg and Stan are merchants, really. They would be very interested in being able to convert currency as well as numbers. The currency in the ancient world was based on weights of precious metals. The currencies mentioned in the story are:

  • Roman: Sestersii
  • Greek: Drachma
  • Indian: Rupee
  • Hebrew: Shekel

Note that some of these coins exist now, but they are no longer made of silver or gold. Instead, they are now "fiat money". If you do a little bit of research, you can establish a base price in ounces of silver for all of the ancient values. Then you can convert money from one denomination to another. If you alter your program so it also shows the money conversion, I will reward you richly. Not with silver or gold, but something far rarer and more sought after. Points on your exam!

Example

Suppose I choose Greek in the first menu. The number I enter will be assumed to be in Drachmas. Then suppose I choose roman in the second menu. This will still change the number, but it will also show me the value in Sestertii, but the value will be printed in Roman numerals.