bor

Temperature Version 2

bor
Feb 12th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. // Version 2
  4. class Temperature {
  5. private:
  6.   int revision;
  7.   double inCelsius;
  8. public:
  9.   Temperature() {
  10.     revision = 0;
  11.   }
  12.   double getFarenheit() {
  13.     return inCelsius * 9.0 / 5.0 + 32;
  14.   }
  15.   double getCelsius() {
  16.     return inCelsius;
  17.   }
  18.   void setFarenheit(double inFarenheit) {
  19.     setCelsius((inFarenheit - 32.0) * 5.0 / 9.0);
  20.   }
  21.   void setCelsius(double inCelsius) {
  22.     this->inCelsius = inCelsius;
  23.     ++revision;
  24.   }
  25. };
  26.  
  27. int main() {
  28.   Temperature t;
  29.   t.setCelsius(0.0);
  30.   t.setCelsius(t.getCelsius() + 20);
  31.   printf("%lf\n", t.getFarenheit());
  32.   double f = t.getFarenheit();
  33.   t.setFarenheit(100.0 - f);
  34.   printf("%lf\n", t.getFarenheit());
  35.   return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment