Source

toybox / c++ / learning / temperature.cpp

Full commit
#include <iostream>

using namespace std;
#define TRIPLE_POINT 273.15

class Temperature {
  double k;
public:
  double getC();
  double getF();
  void setC (double);
  void setF (double);
};

void Temperature::setC (double c) {
  k = c + TRIPLE_POINT;
}

void Temperature::setF (double f) {
  k = (5.0 / 9.0) * (f - 32.0) + TRIPLE_POINT;
}

double Temperature::getC () {
  return (k - TRIPLE_POINT);
}

double Temperature::getF () {
  return ((9.0 / 5.0) * (k - TRIPLE_POINT) + 32.0);
}

int main (int argc, char *argv[]) {
  double f = 85.0;
  Temperature t;
  t.setF(f);
  cout << t.getC() << "\n";
  return 0;
}