Exercise: Simple Method (Users Age By n Years)

Description

Objects of type class User are initialized once in their lifetime,

User joerg("Joerg", "Faschingbauer", 55);

Currently, there is no way to celebrate birthdays, for example. User joerg remains 55 years old, indefinitely. While this is not a bad idea in general, lets implement a way to let users age. Like so,

#include "user.h"
#include <iostream>
#include <cassert>

using namespace std;



int main()
{
    User joerg("Joerg Trittsicher", "Faschingbauer", 55);

    joerg.age_by_n_years(10);
    assert(joerg.age == 65);

    return 0;
}

Essentially: add to class User a method, void age_by_n_years(unsigned int);

Dependencies

cluster_cxx03 C++ 03 cluster_cxx03_exercises_userdb Exercises: User Database cluster_cxx03_standard_library_miscellanea The Standard Library: Miscellaneous Topics cluster_cxx03_data_encapsulation Data Encapsulation cluster_cxx03_functions_and_methods Functions and Methods cluster_c The C Programming Language cluster_c_introduction Introduction cxx03_introduction Introduction c_introduction_installation Installation cxx03_introduction->c_introduction_installation cxx03_exercises_userdb_user_ctor Exercise: Transform struct User Into A Class cxx03_standard_library_miscellanea_string std::string cxx03_exercises_userdb_user_ctor->cxx03_standard_library_miscellanea_string cxx03_data_encapsulation_ctor_basics Constructor: Basics cxx03_exercises_userdb_user_ctor->cxx03_data_encapsulation_ctor_basics cxx03_exercises_userdb_user_simple_method Exercise: Simple Method (Users Age By n Years) cxx03_exercises_userdb_user_const_members Exercise: const Members cxx03_exercises_userdb_user_simple_method->cxx03_exercises_userdb_user_const_members cxx03_functions_and_methods_methods Methods cxx03_exercises_userdb_user_simple_method->cxx03_functions_and_methods_methods cxx03_exercises_userdb_user_const_members->cxx03_exercises_userdb_user_ctor cxx03_data_encapsulation_ctor_dtor More Constructors, Destructors cxx03_exercises_userdb_user_const_members->cxx03_data_encapsulation_ctor_dtor cxx03_data_encapsulation_ctor_dtor->cxx03_data_encapsulation_ctor_basics cxx03_data_encapsulation_introduction Introduction: Classes and Objects cxx03_data_encapsulation_ctor_basics->cxx03_data_encapsulation_introduction cxx03_data_encapsulation_object_copy Object Copy cxx03_data_encapsulation_object_copy->cxx03_data_encapsulation_ctor_dtor cxx03_data_encapsulation_introduction->cxx03_introduction cxx03_functions_and_methods_overloading Overloading cxx03_functions_and_methods_methods->cxx03_functions_and_methods_overloading cxx03_functions_and_methods_overloading->cxx03_data_encapsulation_object_copy