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

上海交通大学交大密西根 联合学院·一 ◆ 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);
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Array and its Applications.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_20 Looking Ahead.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_19 Recursion 1.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_16 MATLAB environment short.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_15 Introduction to matlab.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》教学资源_Chapter 1 Introduction.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》教学资源_第二章习题与答案(第三版).doc
- 上海交通大学:《数据库系统原理 The principle of Database System》教学资源_第三章习题与答案(第三版).doc
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)chapter8 Views, Indexes.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)Chapter7 Constraints and Triggers.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)Chapter6 The database Language SQL –as a tutorial.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)Chapter5 Algebraic and Logic Query languages.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)chapter4 High-level Database Models.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)chapter3 Design Theory for Relational Databases.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)chapter11 The semi-structured data model Structured data.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)Chapter1 Introduction.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》教学资源_intro.pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第二章 8086系统结构.pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第一章 绪论(毛义梅).pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第四章 汇编语言程序设计_习题及解答.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Expressions and Statements.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_files_DataBase Design.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Function.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Introduction to Computer and Programming.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Introduction to Vg101.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_objects and classes.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_programming style guide for C plusplus.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Random Number_Graphics.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Start with C plusplus.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_vector_string.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation 1.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_recitation 13.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation IX.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation V.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation VII.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation VIII.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation X.ppt
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第十四章 MCS-51单片机(1/2).pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第十四章 MCS-51单片机(2/2).pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第一章 微机原理与接口技术绪论(朱兰娟).pdf