Lesson 3: Classes
Activity 7: Information Hiding Through Getters and Setters
Define a class named Coordinates with its members under a private access specifier:
class Coordinates { private: float latitude; float longitude; };
Add the four operations as specified above and make them publicly accessible by preceding their declaration with the public access specifier. The setters (set_latitude and set_longitude) should take an int as a parameter and return void, while the getters do not take any parameter and return a float:
class Coordinates { private: float latitude; float longitude; public: void set_latitude(float value){} void set_longitude(float value){} float get_latitude(){} float get_longitude(){} };
The four methods should now be implemented. The setters assign the given value to the corresponding members they are supposed to set; the getters return the values that are stored.
class Coordinates { private: float latitude; float longitude; ...