Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- // Version 2
- class Temperature {
- private:
- int revision;
- double inCelsius;
- public:
- Temperature() {
- revision = 0;
- }
- double getFarenheit() {
- return inCelsius * 9.0 / 5.0 + 32;
- }
- double getCelsius() {
- return inCelsius;
- }
- void setFarenheit(double inFarenheit) {
- setCelsius((inFarenheit - 32.0) * 5.0 / 9.0);
- }
- void setCelsius(double inCelsius) {
- this->inCelsius = inCelsius;
- ++revision;
- }
- };
- int main() {
- Temperature t;
- t.setCelsius(0.0);
- t.setCelsius(t.getCelsius() + 20);
- printf("%lf\n", t.getFarenheit());
- double f = t.getFarenheit();
- t.setFarenheit(100.0 - f);
- printf("%lf\n", t.getFarenheit());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment