Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const MyString Measure::unitStrings[] =
- { "dram", "tsp", "tbsp", "oz", "cup", "pint",
- "qt", "gal", "peck", "bushel", "barrel", "acre_ft" };
- const Fraction Measure::conversionTable[] =
- { Fraction(4,3), 3, 2, 8, 2, 2, 4, 2, 4, Fraction(55,7), 6000 };
- void Measure::simplify()
- {
- // make the amount bigger if it is less than 1, unless the unit is already
- //"dram" (in which case the amount can't be made any bigger).
- Measure temp;
- while (unit!=0 && amount < 1) {
- temp.amount = conversionTable[unit - 1];
- amount = amount *temp.amount;
- unit--;
- }
- //make the amount smaller if it can be made smaller without making it
- //less than 1, unless the unit is already acre_ft (in which case the
- //amount can't be made any smaller)
- while (unit!=11 && amount > 1 ) {
- temp.amount = conversionTable[unit];
- amount *= (1 / temp.amount);
- unit++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement