中国高校课件下载中心 》 教学资源 》 大学文库

上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation V

文档信息
资源类别:文库
文档格式:PPT
文档页数:24
文件大小:712.5KB
团购合买:点击进入团购
内容简介
上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation V
刷新页面文档预览

VG101 RECITATION 5 By TAs

VG101 RECITATION 5 By TAs

CONTENTS o How to read Vg101Class.h o Samples about graphics o About assignment 5 o Array

CONTENTS  How to read Vg101Class.h  Samples about graphics  About assignment 5  Array

HOW TO READ VG101CLASS.H o This file defines the following classes: o ConsoleT GwindowsT:represent the graphics window oGObjectT:base class for all geometric classes ·LineT ·TriangleT ·RectangleT ArcT:a circle is an arc with an angle of 360 degrees

HOW TO READ VG101CLASS.H  This file defines the following classes:  ConsoleT  GwindowsT: represent the graphics window  GObjectT: base class for all geometric classes  LineT  TriangleT  RectangleT  ArcT: a circle is an arc with an angle of 360 degrees

HOW TO READ VG101CLASS.H o RandomT:random numbers and colors o PointT:represent a point using (x,y) o PenT:record the current location and color of the pen o MouseT:detect the click event of the mouse,get mouse current location TextT:set text color,style,font...when printing a message to the graphics window (not console window)

HOW TO READ VG101CLASS.H  RandomT: random numbers and colors  PointT: represent a point using (x, y)  PenT: record the current location and color of the pen  MouseT: detect the click event of the mouse, get mouse current location  TextT: set text color, style, font… when printing a message to the graphics window (not console window)

HOW TO READ VG101CLASS.H o Let's see what's the general structure of a class definition

HOW TO READ VG101CLASS.H  Let’s see what’s the general structure of a class definition

class RectangleT:public GObjectT Base class { PointT llp,urp; Data members Private void drawRect ( member constructor public: RectangleT(const double x0=0,const double y0=0, const double x1=0,const double y1=0, const string clr ="Blue",const double fill =0); RectangleT (const PointT &p0,const PointT &p1, const string clr ="Blue",const double fill=0); const PointT &getLocation ()freturn llp; double getWidth const; Public double getHeight const; Get Set member double getArea const; void setLocation(const double x,const double y); void setLocation(const PointT p); void setWidth(const double w); void setHeight(const double h); Function void draw 0; members void draw (const string clr,const double density =0);

class RectangleT : public GObjectT { PointT llp, urp; void drawRect (); public: RectangleT (const double x0 = 0, const double y0 = 0, const double x1 = 0, const double y1 = 0, const string clr = "Blue", const double fill = 0); RectangleT (const PointT &p0, const PointT &p1, const string clr = "Blue", const double fill = 0); const PointT &getLocation () {return llp;} double getWidth () const; double getHeight () const; double getArea () const; void setLocation (const double x, const double y); void setLocation (const PointT p); void setWidth (const double w); void setHeight (const double h); void draw (); void draw (const string clr, const double density = 0); }; Base class Private member Public member constructor Get & Set Data members Function members

HOW TO READ VG101CLASS.H o About constructors Rectangle'T (const double x0=0,const double y0=0, const double x1=0,const double y1=0, const string clr ="Blue",const double fill =0); RectangleT(const PointT &p0,const PointT &p1, const string clr ="Blue",const double fill=0); o Note: 1.No return type,function name is just its class name. 2.You should declare an object using one of its constructors:

HOW TO READ VG101CLASS.H  About constructors RectangleT (const double x0 = 0, const double y0 = 0, const double x1 = 0, const double y1 = 0, const string clr = "Blue" , const double fill = 0); RectangleT (const PointT &p0, const PointT &p1, const string clr = "Blue" , const double fill = 0);  Note:  1. No return type, function name is just its class name.  2. You should declare an object using one of its constructors:

HOW TO READ VG101CLASS.H o If the constructor gives the default value of a parameter,then you don't need to give that parameter. use RectangleT myRecO;/default position,color,fill or RectangleT myRec(1,1,2,3);/default color,fill or RectangleT myRece(1,l,2,3,“red”,0.5); /p1,p2 are two known PointT object or RectangleT myRec(p1,p2);/default color,fill or RectangleT myRec(pl,p2,“green”,0.8);

HOW TO READ VG101CLASS.H  If the constructor gives the default value of a parameter, then you don’t need to give that parameter. use RectangleT myRec(); // default position, color, fill or RectangleT myRec(1, 1, 2, 3); // default color, fill or RectangleT myRec(1, 1, 2, 3, “red” , 0.5); // p1, p2 are two known PointT object or RectangleT myRec(p1, p2); // default color, fill or RectangleT myRec(p1, p2, “green” , 0.8);

HOW TO READ VG101CLASS.H o What are useful to us ·Get and Set functions double getWidth 0 const; void setWidth(const double w); Other public functions void draw 0; void draw (const string clr,const double density =0);/overloaded function Note: 1.You can't access private/protected data or use private/protected functions directly. 2.The get set functions offer you access to some private data. 3.Read function comment carefully

HOW TO READ VG101CLASS.H  What are useful to us  Get and Set functions double getWidth () const; void setWidth (const double w);  Other public functions void draw (); void draw (const string clr, const double density = 0); // overloaded function Note: 1. You can’t access private/protected data or use private/protected functions directly. 2. The get & set functions offer you access to some private data. 3. Read function comment carefully

SAMPLES ABOUT GRAPHICS o Draw a line from (2,1)to (5,3)in red #include #ing' usir 日vo1c d): t}

SAMPLES ABOUT GRAPHICS  Draw a line from (2,1) to (5,3) in red

共24页,试读已结束,阅读完整版请下载
刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档