The program is a tutorial on a simple class. You can break the sample code up into two parts.
First is the class defintion:
Code:
class Dog {
public:
void setAge(int age);
int getAge();
void setWeight(int weight);
int getWeight();
void speak();
private:
int age;
int weight;
};
Next we have the implementation:
Code:
void Dog::setAge(int age)
{
this->age = age;
}
int Dog::getAge()
{
return age;
}
void Dog::setWeight(int weight)
{
this->weight = weight;
}
int Dog::getWeight()
{
return weight;
}
void Dog::speak()
{
cout << "BARK!!" << endl;
}
The first part describes what functions make up the class, and what variables make up the class. For now, dont worry about the public/private parts.
The next part shows us the implementations of the functions that make up the class.
Here is a sample which shows us how to use that class:
Code:
int main()
{
Dog dog1;
Dog dog2;
dog1.setAge(3);
dog1.setWeight(50);
dog2.setAge(5);
dog2.setWeight(60);
cout << "Dog 1 is " << dog1.getAge() << " years old." << endl;
cout << "Dog 2 is " << dog2.getAge() << " years old." << endl;
return 0;
}