Challenge 1: Rearranging a Class

In this challenge, you'll be splitting up a class into .h and .cpp files.

Problem Statement

We have provided you the implementation for the Planet class. Your task is to ensure abstraction by splitting up the code into header and .cpp files.

In the code below, Planet.h and Planet.cpp are empty, whereas main.cpp contains the full implementation. The class contains three variables:

  1. radius - The distance from the center of the planet.

  2. mass - The mass of the planet.

  3. G - The gravitational constant.

The getMass() function simply returns the mass of the planet and calculateGravity() calculates the gravitational strength of the planet.

The end goal is to remove all the implementation of the Planet class from main.cpp.

Good luck!

Get hands-on with 1200+ tech skills courses.