上海交通大学交大密西根 联合学院·一 ◆ 81T UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Mutators (Examples) GwindowsT: - void setWidth(const double w){width w;); void setHeight(const double h)height h;} - void setTitle (const string title); void setColor (const string clr)const; 。 Those functions could also be declared only and defined somewhere else like GwindowsT::setTitle(const string newT){title newT;} GwindowsT::setColor (const string clr){color clr;}
Mutators Mutators (Examples) (Examples) • GwindowsT: – void setWidth (const double w) {width = w;}; – void setHeight (const double h) {height = h;} – void setTitle (const string title); – void setColor (const string clr) const; • Those functions could also be declared only and defined somewhere else like – GwindowsT::setTitle (const string newT) { title = newT;} – GwindowsT::setColor (const string clr) {color = clr;}
上海交通大学交大密西根 联合学院·一 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Other Methods (Funtional Purpose) Many objects/class we defined has functions which are primarily used to manipulate the data defined in the objects/class in a way could be used by other objects or functions.These functons are called methods in OOP. They are declared in the *.h file and Implemented in a corresponding *.cpp file
Other Methods ( Other Methods (Funtional Funtional Purpose) Purpose) • Many objects/class we defined has functions which are primarily used to manipulate the data defined in the objects/class in a way could be used by other objects or functions. These functons are called methods in OOP. – They are declared in the *.h file and – Implemented in a corresponding *.cpp file
Methods (Examples) ouseT: /to test if the mouse button is down bool buttonDown O; /as the name suggest,it will wait for button down or up void waitForButtonDown O); void waitForButtonUp () GwindowsT: /the first function called to initialize a graphics window void initGraphics O; /clean the graphics window with filled color void draw const;
Methods (Examples) Methods (Examples) • MouseT: // to test if the mouse button is down – bool buttonDown (); // as the name suggest, it will wait for button down or up – void waitForButtonDown (); – void waitForButtonUp (); • GwindowsT: // the first function called to initialize a graphics window – void initGraphics (); // clean the graphics window with filled color – void draw () const;