SHARE
TWEET

Reduction

a guest Jan 20th, 2020 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. const MyString Measure::unitStrings[] =
  3.     { "dram", "tsp", "tbsp", "oz", "cup", "pint",
  4.      "qt", "gal", "peck", "bushel", "barrel", "acre_ft" };
  5.  
  6. const Fraction Measure::conversionTable[] =
  7.     { Fraction(4,3), 3, 2, 8, 2, 2, 4, 2, 4, Fraction(55,7), 6000 };
  8.  
  9. void Measure::simplify()
  10.     {
  11.         // make the amount bigger if it is less than 1, unless the unit is already
  12.         //"dram" (in which case the amount can't be made any bigger).
  13.         Measure temp;
  14.         while (unit!=0 && amount < 1) {
  15.             temp.amount = conversionTable[unit - 1];
  16.             amount = amount *temp.amount;
  17.                 unit--;
  18.         }
  19.         //make the amount smaller if it can be made smaller without making it
  20.          //less than 1, unless the unit is already acre_ft (in which case the
  21.         //amount can't be made any smaller)
  22.         while (unit!=11 && amount > 1 ) {
  23.            
  24.             temp.amount = conversionTable[unit];
  25.             amount *= (1 / temp.amount);
  26.                 unit++;
  27.         }
  28.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top