Skip to main content

Section 17.8 Modifying the Contained Members

The same logic applies if want to add functions to change the location of a Circle - it does directly control the data (x and y) that needs to be changed. So any function that needs to modify those values will need to rely on calling methods on m_center.
This is demonstrated in the sample below. Note that setRadius can directly do the needed work as the m_radius variable is โ€œownedโ€ directly by the Circle. However setX() and setY() need to ask m_center to make the needed changes:
Listing 17.8.1.

Checkpoint 17.8.1.

Class Address has a m_streetAddress, m_city, and m_zip. Class Contact is shown below. If a Contact is asked to do the following tasks, which ones sound like they should be handed off to the m_address to do?
class Contact {
  public:
      ...
  
  private:
      string m_name;
      string m_email;
      Address m_address;
  };
  • Check if the contact is in a particular city.
  • Update the contactโ€™s street address.
  • Get the address of the contact in the format โ€œ123 Main, Town 12345โ€.
  • Get the contactโ€™s name
  • Update the contactโ€™s email
You have attempted of activities on this page.