We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
classPerson{private:intage;public:Person(intinitialAge);voidamIOld();voidyearPasses();};Person::Person(intinitialAge){if(initialAge<0){age=0;cout<<"Age is not valid, setting age to 0."<<endl;}else{age=initialAge;}}voidPerson::amIOld(){if(age<13){cout<<"You are young."<<endl;}elseif(age<18){cout<<"You are a teenager."<<endl;}else{cout<<"You are old."<<endl;}}voidPerson::yearPasses(){age++;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 4: Class vs. Instance
You are viewing a single comment's thread. Return to all comments →
C++14 Solution: