Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions 30 Days of Code/Day 04/Class vs. Instance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Person{
public:
int age;
Person(int initialAge);
void amIOld();
void yearPasses();
};

Person::Person(int initialAge){

//code to run some checks on initialAge
if(initialAge<0) {cout<<"Age is not valid, setting age to 0."<<endl;age=0;}
else age = initialAge;

}

void Person::amIOld(){

// code to determine if this person's age is old and print the correct statement:
if(this->age<13) cout<<"You are young."<<endl;
else if(this->age>=18) cout<<"You are old."<<endl;
else cout<<"You are a teenager."<<endl;

}

void Person::yearPasses(){

// Increment this person's age by 1.
age++;
}