上海交通大学交大密西根 ·联合学院一 81 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Common Pitfall BE CAREFUL about the difference in English description and program code. if (next()<RAND MAX/6) If you continuously { rolling the dies,the intDieFaceNumber =1; else if next ()RAND MAX 2/6) probability you got for { each fact will NOT be intDieFaceNumber =2; the same as 1/6 Is this right?
Common Pitfall Common Pitfall • BE CAREFUL about the difference in English description and program code. if (next () < RAND_MAX / 6) { intDieFaceNumber = 1; } else if next () < RAND_MAX * 2 / 6) { intDieFaceNumber = 2; } ... Is this right? If you continuously rolling the dies, the probability you got for each fact will NOT be the same as 1/6
上海交通大学交大密西根 ·联合学院一 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Vg101:Introduction to Computer and Programming Simple Graphics Library Introduction to ANSI C++
Vg101:Introduction to Vg101:Introduction to Computer and Programming Computer and Programming Simple Graphics Library Introduction to ANSI C++
上海交通大学交大密西根 ·联合学院一 1811 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University GWindow:the drawing area All drawing occurs in a rectangular graphics window,it is therefore,we need to define a class for graphics windows first Basic characteristics of the class - Size of the window (width and hight)
GWindow GWindow: the drawing area : the drawing area • All drawing occurs in a rectangular graphics window, it is therefore, we need to define a class for graphics windows first • Basic characteristics of the class – Size of the window (width and hight)
上海交通大学交大密西根 联合学院·一 ◆ 81 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Coordinates class PointT Drawing occurs in a rectangular graphics window.The origin of double x,yi the system is in the lower left public: corner.Each point in the window Grap is described by a class PointT yt 为 In the vg101 graphics library,the system coordinates are specified by a Point and measured by inches.As a point moving (,) towards right or up,the x or y coordinates increases. Coordinates could be measured absolutely or relatively. (0.0,0.0)
Coordinates Coordinates • Drawing occurs in a rectangular graphics window. The origin of the system is in the lower left corner. Each point in the window is described by a class PointT • In the vg101 graphics library, the system coordinates are specified by a Point and measured by inches. As a point moving towards right or up, the x or y coordinates increases. • Coordinates could be measured absolutely or relatively
上海交通大学交大密西根 ·联合学院 81 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Classes Supporting Graphics These are the classes GwindowsT wind (w,h) defined by vg101class.h. PointT pt (x,y) There are classes for LineT GraphicsWindows,Pens, and Geometric Item line (pt1,pt2) Points,Lines,Arcs, line (x0,y0,x1,y1) Rectangles and Triangles. ArcT It is common to find arc (r,alpha,theta) these same general RectangleT classes of functions in rect (pt1,pt2) other libraries. rect (x0,y0,x1,y1)
Classes Supporting Graphics Classes Supporting Graphics • These are the classes defined by vg101class.h. • There are classes for GraphicsWindows, Pens, and Geometric Item Points, Lines, Arcs, Rectangles and Triangles. • It is common to find these same general classes of functions in other libraries. • GwindowsT wind (w, h) • PointT pt (x, y) • LineT line (pt1, pt2) line (x0, y0, x1, y1) ArcT arc (r, alpha, theta) • RectangleT rect (pt1, pt2) rect (x0, y0, x1, y1)