11/23/05 Classes: Classes have a public part and a private part. The public part typically includes "member functions" The private part typically includes "data members". A class defintion is similar to a struct defintion but it includes two important ideas: * information hiding The private parts of your class are only available to member functions. Users of the class cannot directly touch or read the private data members. * encapsulation Data members AND the functions all live inside the same "construct" (i.e. inside the class definition). class ChristmasList_C { public: ChristmasList_C (const char * const theStoreName, const char * const anItemName, const double thePrice, const int numItems); void print(); double getPrice(); void setPrice(const double newPrice); int getNumItems(); void setNumItems(const int newNumItems); private: char *storeName; char *itemName; double price; int numberOfItems; } Together with two other ideas: * inheritance * polymorphism These four concepts make up what is known as Object Oriented Programming. Comparison of a struct definition with a class definition: // struct Receiver_S // { // char *name; // stuff on heap // char *team; // stuff on heap // int catches; // double YAC; // yards after catch // }; class Receiver_C { public: Receiver_C(char *aName, char *aTeam, int howManyCatches, double theYACValue); int getCatches(); void setCatches(int howManyCatches); void print(); private: char *name; // stuff on heap char *team; // stuff on heap int catches; double YAC; // yards after catch };