上海交通大学交大密西根 8 联合学院·一 ◆ 1811 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Data Manipulation Methods Constructors Used for initialize defined objects ● Accessors - Used to access private data members ● Mutators - Used to change/set private data members Other Method Functions Used for other functions of the objects
Data Manipulation Methods Data Manipulation Methods • Constructors – Used for initialize defined objects • Accessors – Used to access private data members • Mutators – Used to change/set private data members • Other Method Functions – Used for other functions of the objects
上海交通大学交大密西根 联合学院·一 ◆ 81T UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Constructors When we define regular variables,we can define it without initialization or define it and get it initialized at the same time. We wish the classes we defined has the same property.It is therefore,we normally define two kinds of constructors Constructor with no specified initial values Constructor with specified initial values
Constructors Constructors • When we define regular variables, we can define it without initialization or define it and get it initialized at the same time. • We wish the classes we defined has the same property. It is therefore, we normally define two kinds of constructors – Constructor with no specified initial values – Constructor with specified initial values
上海交通大学交大密西根 联合学院·一 ◆ 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Constructors of PointT class PointT double x,y; public; PointT O); /PointT pt; PointT (double x,double y);//PointT pt (3,5.4); PointT (const PointT &p);//PointT point(pt);
Constructors of Constructors of PointT class PointT { double x, y; public: PointT (); // PointT pt; PointT (double x, double y);// PointT pt (3, 5.4); PointT (const PointT &p); // PointT point (pt); ……
上海交通大学交大密西根 联合学院·一 ◆] 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Constructors of PenT class PenT { public: PenT O; /PenT pen; PenT (double x,double y,const string clr); /∥PenT(3,5.4,“Red")
Constructors of Constructors of PenT class PenT { public: PenT (); // PenT pen ; PenT (double x, double y, const string clr); // PenT (3, 5.4, “Red”) ……
上海交通大学交大密西根 联合学院·一 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Constructors of GwindowsT class GwindowsT:public ConsoleT protected: double width,height; /size of a window object string title; /title of a window object string color; /color of a window object public: static PenT pen; /pen of the window class static MouseT mouse; /mouse of the window class GwindowsTO; I∥GwindowsT window; GwindowsT const double width,const double height,string color "White",string title ="") ∥GwindowsT window(12.0,6.0,“Red",“Bouncing Ball"); ∥GwindowsT window(12.0,6.0,“Red"); /∥GwindowsT window(12.0,6.0);
Constructors of Constructors of GwindowsT GwindowsT class GwindowsT: public ConsoleT { protected: double width, height; // size of a window object string title; // title of a window object string color; // color of a window object public: static PenT pen; // pen of the window class static MouseT mouse; // mouse of the window class GwindowsT (); // GwindowsT window; GwindowsT ( const double width, const double height, string color = "White", string title = ""); // GwindowsT window (12.0, 6.0, “Red”, “Bouncing Ball”); // GwindowsT window (12.0, 6.0, “Red”); // GwindowsT window (12.0, 6.0);