Create a program for converting between units.
First, you will have to determine a set of units you will use, as you will have to recognize them.
For example, this may include the SI units:
| Name | Symbol |
|---|---|
| meter | m |
| gram | g |
| second | s |
| ampere | A |
| kelvin | K |
| candela | cd |
| mole | mol |
| volt | V |
| ohm | Omega |
| tesla | T |
| weber | Wb |
| farad | F |
| henry | H |
| siemens | S |
| coulomb | C |
| watt | W |
| newton | N |
| joule | J |
| pascal | Pa |
| liter | L |
Each of these can have a prefix:
| Prefix | Symbol | Factor |
|---|---|---|
| yotta | Y | $10^{24}$ |
| zetta | Z | $10^{21}$ |
| exa | E | $10^{18}$ |
| peta | P | $10^{15}$ |
| tera | T | $10^{12}$ |
| giga | G | $10^{9}$ |
| mega | M | $10^{6}$ |
| kilo | k | $10^{3}$ |
| hecto | h | $10^{2}$ |
| deca | da | $10^{1}$ |
| deci | d | $10^{-1}$ |
| centi | c | $10^{-2}$ |
| milli | m | $10^{-3}$ |
| micro | u | $10^{-6}$ |
| nano | n | $10^{-9}$ |
| pico | p | $10^{-12}$ |
| femto | f | $10^{-15}$ |
| atto | a | $10^{-18}$ |
| zepto | z | $10^{-21}$ |
| yocto | y | $10^{-24}$ |
Your first project should be to write a function that recognizes the symbol and a possible prefix. Thus, you should recognize kg as 1000 grams, and dm as one-tenth of a meter.
There may also be non-SI units:
| Name | Symbol |
|---|---|
| foot | ft |
| yard | yd |
| mile | mi |
| gallon | gal |
| pint | pt |
| ounce | oz |
| fluid ounce | fl oz |
| grain | gr |
Your program may then work as follows:
Enter a quantity: 3.25 m Enter a unit to convert to: yd 3.25 m = 3.55424321959755 yd Enter a quantity: 3 pt Enter a unit to convert to: L 3 pt = 1.419529419 L