当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_examples on class design

资源类别:文库,文档格式:PDF,文档页数:53,文件大小:209.92KB,团购合买
点击下载完整版文档(PDF)

上海交通大学交大密西根 联合学院·一 ◆ 181 UM-SJTU Joint Institute ■ University of Michigan Shanghal Jiao Tong University Vg101 Introduction to Computer and Programming Example on Objects and Classes

Vg101 Introduction to Computer and Introduction to Computer and Programming Programming Example on Objects and Classes

上海交通大学交大密西根 联合学院·一 ◆ 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Bouncing Ball Problem:Implement bounding ball using more object oriented version First of all,let's think how many objects or classes will be associated with this applications. -A window with rectangular boundary and -A Ball

Bouncing Ball Bouncing Ball • Problem: Implement bounding ball using more object oriented version • First of all, let’s think how many objects or classes will be associated with this applications. – A window with rectangular boundary and – A Ball

上海交通大学交大密西根 B 联合学院·一 ◆ 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Characteristics of a Window Attributes - size(width,height):double colar:string title:string ● Since it is primarily for graphics,it also has - pen:PenT mouse:MouseT

Characteristics of a Window Characteristics of a Window • Attributes – size(width, height): double – colar: string – title: string • Since it is primarily for graphics, it also has – pen: PenT – mouse: MouseT

上海交通大学交大密西根 联合学院·一 ■ 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Data Members of GwindowsT class GwindowsT:public ConsoleT//inherit from ConsoleT { /data members of the class protected: /∥another attributes 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

Data Members of Data Members of GwindowsT GwindowsT class GwindowsT: public ConsoleT// inherit from ConsoleT { // data members of the class protected: // another attributes 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

上海交通大学交大密西根 联合学院一 ◆ 181 UM-SJTU Joint Institute ■ University of Michigan Shanghal Jiao Tong University PenT and MouseT Characteristics of MouseT -Location (x,y):double Characteristics of a PenT; -location:PointT color:string Characteristics of a PointT - location (x,y):double

PenT and MouseT • Characteristics of MouseT – Location (x, y): double • Characteristics of a PenT: – location: PointT – color: string • Characteristics of a PointT – location (x, y): double

上海交通大学交大密西根 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);

点击下载完整版文档(PDF)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共53页,可试读18页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有