上海交通大学交大密西根 联合学院·一 ◆ 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