/* * C++ Program based on examples in Sams Teach Yourself C++ in 21 Days by Jesse Liberty * Tyler "Tristor" Duzan May 17th, 2005 * * This program is meant to demonstrate how to define classes, use public and private members, use accessor functions, * create objects, and define parts of objects as well as other ways to manipulate objects. Let's see if I can do this * OOP thing. * * Naming Conventions: * * Note: These follow the Mozilla development guidelines for naming style * * Members = m * Arguments = a * Static = s * Global = g * * For variables with a hybrid Hungarian/Camel style * * Global functions start with NS_ and are all CAPS * Classes start with ns * Functions are in InterCaps * * This will help me to learn to program following these naming conventions. */ #include class nsCat { public: int GetAge(); void SetAge(int aAge); int GetWeight(); void SetWeight(int aWeight); void Meow(); private: int mAge; int mWeight; } // We need to define all the public functions from the class // GetAge, SetAge, GetWeight, SetWeight, and Meow. int Cat::GetAge() { return mAge; } void Cat::SetAge(int aAge) { mAge = aAge; } int Cat::GetWeight() { return mWeight; } void Cat::SetWeight(int aWeight) { mWeight = aWeight; } void Cat::Meow() { std::cout << "Meow.\n"; } // We will now create a cat and define its properties. // After that, we will report its properties back to the console // and make it meow. int main() { using std::cout; Cat Inky; // Now we manipulate the object. Inky.SetAge(4); Inky.SetWeight(12); Inky.Meow(); cout << "Inky is a cat and he is " << Inky.GetAge() << " years old.\n"; cout << "Inky is " << Inky.GetWeight() << " lbs.\n"; Inky.Meow(); //Return and exit the program. return 0; }