Complete the code to declare a data member named 'age' of type int inside the class.
class Person { public: [1] age; };
The data member 'age' should be declared as type int to store whole numbers.
Complete the code to define a member function named 'getAge' that returns the age.
class Person { private: int age; public: int [1]() { return age; } };
The member function that returns the age should be named getAge.
Fix the error in the member function definition to correctly set the age.
class Person { private: int age; public: void setAge(int a) { [1] = a; } };
a = a; which does nothing.this-> can cause ambiguity.Use this->age to refer to the data member and avoid confusion with the parameter a.
Fill both blanks to create a member function that increases age by 1 and returns the new age.
class Person { private: int age; public: int [1]() { age [2] 1; return age; } };
The function name should be incrementAge and the operator += adds 1 to age.
Fill all three blanks to define a constructor that sets the age data member using the parameter.
class Person { private: int age; public: Person(int [1]) { [2] = [3]; } };
this-> causes ambiguity.a = a; which does nothing.The constructor parameter is named a. Use this->age = a; to set the data member.