bor

Temperature Version 1

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