Basic C++ OOP .. Intimidating?

Yesterday night I continued to read my C++ Book, “Sams teach yourself C++ in 21 days”. This book is very good and I recommend it to anyone that wants to learn C++. In chapter 6 they start talking about OOP ( Object Oriented Programming ). C++ has a new feature called “Classes”. This is a very important feature because it gives you the ability to program like if the objects where real. This is a code I wrote with c++ / classes.

#include <iostream>

using std::cout;

class Pet
int getAge();
void setAge(int age);
int getFood();
void setFood(int food);
int itsAge;
int itsFood;

int Pet::getAge()
return itsAge;

void Pet::setAge(int age)
itsAge = age;

int Pet::getFood()
return itsFood;

void Pet::setFood(int food)
itsFood = food;

int main()
Pet Patrick;


cout << “\n\nPatrick is a pet that is ” << Patrick.getAge() << ” Year old.\n\n”;


cout << “15 years later patrick is ” << Patrick.getAge() << ” Years old.\n\n”;

return 0;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: