Skip to content

Space Age

Intro

Given an age in seconds, calculate how old someone would be on:

  • Mercury: orbital period 0.2408467 Earth years
  • Venus: orbital period 0.61519726 Earth years
  • Earth: orbital period 1.0 Earth years, 365.25 Earth days, or 31557600 seconds
  • Mars: orbital period 1.8808158 Earth years
  • Jupiter: orbital period 11.862615 Earth years
  • Saturn: orbital period 29.447498 Earth years
  • Uranus: orbital period 84.016846 Earth years
  • Neptune: orbital period 164.79132 Earth years

So if you were told someone were 1,000,000,000 seconds old, you should be able to say that they're 31.69 Earth-years old.

If you're wondering why Pluto didn't make the cut, go watch thisyoutube video.

Task

See above

The Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include "space_age.h"
#include <bits/stdint-uintn.h>

namespace space_age {
space_age::space_age(long _age) { age = _age; }

double space_age::seconds() const { return age; }
double space_age::on_earth() const { return age / 31557600.0; }
double space_age::on_mercury() const { return age / (0.2408467 * 31557600.0); }
double space_age::on_venus() const { return age / (0.61519726 * 31557600.0); }
double space_age::on_mars() const { return age / (1.8808158 * 31557600.0); }
double space_age::on_jupiter() const { return age / (11.862615 * 31557600.0); }
double space_age::on_saturn() const { return age / (29.447498 * 31557600.0); }
double space_age::on_uranus() const { return age / (84.016846 * 31557600.0); }
double space_age::on_neptune() const { return age / (164.79132 * 31557600.0); }

} // namespace space_age
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdint-uintn.h>
#if !defined(SPACE_AGE_H)
#define SPACE_AGE_H

namespace space_age {
class space_age{
    public:
    double age;
    space_age(long);
    double seconds() const;
    double on_earth() const;
    double on_mercury() const;
    double on_venus() const;
    double on_mars() const;
    double on_jupiter() const;
    double on_saturn() const;
    double on_uranus() const;
    double on_neptune() const;
};
} // namespace space_age

#endif // SPACE_AGE_H

Last update: February 10, 2021

Comments