524555562面向对象程序设计报告基本图形处理软件课程设计报告.doc

上传人:仙人指路1688 文档编号:2385622 上传时间:2023-02-17 格式:DOC 页数:45 大小:196.50KB
返回 下载 相关 举报
524555562面向对象程序设计报告基本图形处理软件课程设计报告.doc_第1页
第1页 / 共45页
524555562面向对象程序设计报告基本图形处理软件课程设计报告.doc_第2页
第2页 / 共45页
524555562面向对象程序设计报告基本图形处理软件课程设计报告.doc_第3页
第3页 / 共45页
524555562面向对象程序设计报告基本图形处理软件课程设计报告.doc_第4页
第4页 / 共45页
524555562面向对象程序设计报告基本图形处理软件课程设计报告.doc_第5页
第5页 / 共45页
点击查看更多>>
资源描述

《524555562面向对象程序设计报告基本图形处理软件课程设计报告.doc》由会员分享,可在线阅读,更多相关《524555562面向对象程序设计报告基本图形处理软件课程设计报告.doc(45页珍藏版)》请在三一办公上搜索。

1、面向对象程序设计报告一设计要求设计圆(包含椭圆)、矩形(包含正方形)、三角形、直线等基本图形类,基于这些基本图形类构造、编辑复杂图形,基本功能包括: 图形的创建:以圆(包含椭圆)、矩形(包含正方形)、三角形、直线等基本图形为元素构建复杂图形。 图形的编辑:增加图形元素(基本图形)、删除图形元素(基本图形) 图形放大、缩小 图形保存二概述 本次程序设计为基于C+的面向对象的程序设计。用C+各种基本图形(例如,圆、矩形、三角形、直线、点等)的类原型,通过继承图形这一个公共基类来实现图形的增删改以及保存等操作。通过此次实习,我对类的相关操作以及类的作用有了更深一步的认识。对面向对象程序设计有了进一步

2、的理解。特别是进一步熟悉并使用面向对象的继承、多态等机制。该系统中,定义了一个鼠标类和窗口类,窗口类又继承了鼠标类,使得所有的操作变得简单明了,代码可移植性也很强。整体操作方式与windows中画图的操作方式相似,而且可以随时更改以前画过的图形,该系统实现了各类基本图形的产生,放大,缩小,删除、移动、改变颜色、改变线型与保存等功能。采用汉字库,实现了中文显示,为该系统的使用者提供了便利。而且界面上操作很方便,可以使用快捷键,可以直接点击鼠标来轻松绘制图片。使用了Turboc+编译器,编译器下载地址: 。三主要类说明1各基本图形类的基类:FIGURE该类归纳了各种图形类的共同数据以及共同操作,声

3、明了几个纯虚函数:virtual void show()=0;virtual void hide()=0;virtual void expand(int delta)=0;virtual void save()=0;实现了同一函数在各个不同的图形类中有不同的实现。增大了程序的灵活性。其中show()函数的作用是显示图形,hide()函数是用来隐藏图形,expand()函数是用来放大选中的图形。save()函数将对应图形的相关数据以文件的形式保存。此外,此基类中还包含了一个move_to()函数,该函数实现了图形在选定方向上的移动。包含的数据成员有:整型数据x_pos,y_pos,用来记录坐标。

4、/图形类 基类/class FIGUREpublic:FIGURE(int x,int y,int lstyle,int lcolor);virtual void show()=0;virtual void hide(int bkcolor)=0;virtual void expand(int bkcolor,int delta)=0;virtual void save()=0;void move_to(int bkcolor,int direction,int speed);void contract(int bkcolor,int delta);int color,style;protec

5、ted: int x_pos,y_pos; ;2直线类:MYLINE该类中的数据成员有:整型数据x_pos2,y_pos2用来记录坐标。/直线类/class MYLINE:public FIGUREpublic: MYLINE(int x1,int y1,int x2,int y2,int style,int color); virtual void show(); virtual void hide(int bkcolor); virtual void expand(int bkcolor,int delta); virtual void save(); virtual void move_

6、to(int bkcolor,int direction,int speed); protected: int x_pos2,y_pos2;3三角形类:TRIANGLE该类的功能是实现以三角形为对象的各种操作。该系统中只是简单的处理了三角形的绘制,只能画等腰三角形,所以只用了一个私有数据length来记录三角形的腰长。/三角形类/class TRIANGLE:public FIGUREpublic: TRIANGLE(int x,int y,int length,int style,int color); virtual void show(); virtual void hide(int b

7、kcolor); virtual void expand(int bkcolor,int delte); virtual void save(); protected: int length;4长方形类:RECTANGLE该类的所有函数均由基类继承而来,包含的数据为:受保护整型数据length,width,记录长方形的长和宽。/矩形类/class RECTANGLE:public FIGUREpublic: RECTANGLE(int x,int y,int len,int wid,int style,int color); virtual void show(); virtual void

8、hide(int bkcolor); virtual void expand(int bkcolor,int delta); virtual void save(); protected: int length,width;5椭圆类:ELLIPSE该类的功能是实现以椭圆为对象的各种操作,当然也可以处理圆的操作。自身含有受保护整型数据:lenx,leny,arcstart,arcend。/椭圆类 包括圆/class ELLIPSE:public FIGUREpublic: ELLIPSE(int x,int y,int astart,int aend,int lx,int ly,int styl

9、e,int color); virtual void show(); virtual void hide(int bkcolor); virtual void expand(int bkcolor,int delta); virtual void save(); protected: int lenx,leny; int arcstart,arcend;6. 鼠标类:MOUSE集成鼠标的基本操作,有初始化,变换形状,显示和隐藏等。/鼠标类定义/class MOUSEpublic: MOUSE(); int MouseInit(); int MouseRead(); void MouseMath

10、(); void MouseOn(); void MouseOff(); void MouseChange(); int MouseInbox(int x1,int y1,int x2,int y2); int mousex,mousey,mousez; int mousekind; / 鼠标是手1还是箭头0 protected: union REGS regs; int up1616,down1616; int mouse_draw1616; int pixel_save1616; / 保存被鼠标覆盖的区域颜色 int edgecolor; / 鼠标边缘颜色 int fillcolor; /

11、 鼠标中心颜色;7. 窗口类:WINDOW继承了鼠标类,集成了菜单显示及相应处理,显示友好窗口界面。/窗口类定义/class WINDOW:public MOUSEpublic: WINDOW();void CreatWindow(char *text,int x,int y,int length,int width,int color,int type); void InButton(int x,int y,int len,int hig,int col,int typ); void OutButton(int x,int y,int len,int hig,int col,int typ)

12、; void MinBar(int x,int y,int col); void MaxBar(int x,int y,int col); void CloseBar(int x,int y,int col); int windowprocess(); protected: int winx,winy; int winlength,winwidth; int wintype; int menuposion4; char wintext50; char menutext45; static int graphmode;8. 图形列表类:graphlist将所有所作图形都用链表的形式连接起来,对它

13、进行统一的各类操作,例如,移动,保存,放大等等。它还记录当前作图信息,例如当前画图颜色,背景颜色,线条粗细等等。/记录已画图形/templateclass graphlistpublic: graphlist(); void show(); void show(GRAPH *g); void hide(); void hide(GRAPH *g); void move_to(int derection,int step); void move_to(int derection,int step,GRAPH *g); void expand(int delta); /放大 void expand

14、(int delat,GRAPH *g); void contract(int delta); /缩小 void contract(int delat,GRAPH *g); void save(); void load(); void save(GRAPH *g); void del(); void del(GRAPH *g); void add(GRAPH *g,int gkind); void curnext(); / 将当前作图的指针移到下一个 void shake(); / 图形振动 void hide_process(int x_record,int y_record,int xte

15、mp,int ytemp); / 隐藏画图中的多余轨迹 struct NODE GRAPH *graph; int graphkind; NODE *next; *head,*CurNode; int backgroundcolor; / 当前作图背景颜色 int paintorder; / 当前选中的Tools int ispainting; / 是否是画图状态 int paintcolor; / 当前作图颜色 int linestyle; / 当前作图线宽 int paintlen; / 当前窗口长 int paintwide; / 当前窗口宽 int windowmove; / 当前作图

16、窗口移动方式;四类的关系描述 类的关系描述如图1所示。MYLINEELLIPSERECTANGLETRIANGLEFIGURE图1 类的继承关系五使用说明 四个方向键控制单个当前编辑图形的左右上下移动, a,d,w,s键控制所有图形的左右上下移动;+,-控制当前图形 的放大与缩小,b,c控制所有图形的放大缩小; 可以使用 PageUp键调整当前编辑图形(会有跳动提示),按Home键使当前编辑图形跳至最后所作的图形;Delete键和Ctrl+z删除当前 的编辑单个图形,Ctrl+a键和界面上的“空”按钮删除所有图形;Alt+s保存,Alt+l导入,Esc退出。 使用鼠标点击画布边缘的标记区域,可

17、以改边画布的大小和移动画布的位置,可以点击状态栏的前景与背景颜色框,然后可以修改当前画图颜色和,背景颜色。 其中还有画“贝赛耳曲线”、画点、填充功能没写好,所以屏蔽了这些功能。六程序清单:/程序名: Graph.cpp/功 能: 基本图形的处理/作 者: 0501xql QQ:527274766 2007.7.8/#include iostream.h#include graphics.h#include process.h#include stdlib.h#include string.h#include conio.h#include stdio.h#include stdio.h#inc

18、lude bios.h#include math.h#include dos.h#define ESC 283#define ALLLEFT 29440 /Ctrl #define ALLLEFTA 7777 /a#define ALLRIGHTD 8292 /d#define ALLUPW 4471 /w#define ALLDOWNS 8051 /s#define ALLBIGB 12386 /b#define ALLSMALLC 11875 /c #define LEFT 19200#define RIGHT 19712#define UP 18432#define DOWN 20480

19、#define DELETE 21248#define HOME 18176#define PAGEUP 18688#define BIG 20011 /+#define SMALL 18989 /-#define SAVE 7936 /Alt S#define LOAD 9728 /Alt L#define ALLDEL 7681 /Ctrl A#define UNDO 11290 #define false 0#define ture 1#define MS_LCLICK 1 / 鼠标按键#define MS_RCLICK 2#define MS_DCLICK 3int PAINTX=80

20、;int PAINTY=50;/-/ 自定义类型/-enum TOOLEXIT,PENC,LINE,BEZI,RECT,ELLI,CIRC,TRIA,FILL,BTNSAVE=11,BTNLOAD,EREA,CLEANALL,LINE1,LINE3,SETBKCOLOR,SETCURCOLOR;struct Position int x,y; int length,wide;Tool1+7*2+4+8*2;/-/ 全局变量/-int tools_visible=1; / 默认显示工具按钮int up_setcolor=SETCURCOLOR;/ 默认是设置画线的颜色/-/ 函数声明/-int

21、Bezier(float,float);int ReadyPaint(int,int,int);int GetOrder(int,int,int);int MenuFace(int);void Filling(int,int,int,int);int triangle(int,int,int);int Putiamge(int x_record,int y_record,int xtemp,int ytemp);int OutText(char *string,int x,int y,int color);/文件名: graphclass.hpp/功 能: 图形类的类声明/作 者: 0501x

22、ql QQ:527274766 2007.7.8/-/ 所有类的声明/-/图形类 基类/class FIGUREpublic:FIGURE(int x,int y,int lstyle,int lcolor);virtual void show()=0;virtual void hide(int bkcolor)=0;virtual void expand(int bkcolor,int delta)=0;virtual void save()=0;void move_to(int bkcolor,int direction,int speed);void contract(int bkcol

23、or,int delta);int color,style;protected: int x_pos,y_pos; ;/直线类/class MYLINE:public FIGUREpublic: MYLINE(int x1,int y1,int x2,int y2,int style,int color); virtual void show(); virtual void hide(int bkcolor); virtual void expand(int bkcolor,int delta); virtual void save(); virtual void move_to(int bk

24、color,int direction,int speed); protected: int x_pos2,y_pos2;/三角形类/class TRIANGLE:public FIGUREpublic: TRIANGLE(int x,int y,int length,int style,int color); virtual void show(); virtual void hide(int bkcolor); virtual void expand(int bkcolor,int delte); virtual void save(); protected: int length;/矩形

25、类/class RECTANGLE:public FIGUREpublic: RECTANGLE(int x,int y,int len,int wid,int style,int color); virtual void show(); virtual void hide(int bkcolor); virtual void expand(int bkcolor,int delta); virtual void save(); protected: int length,width;/椭圆类 包括圆/class ELLIPSE:public FIGUREpublic: ELLIPSE(int

26、 x,int y,int astart,int aend,int lx,int ly,int style,int color); virtual void show(); virtual void hide(int bkcolor); virtual void expand(int bkcolor,int delta); virtual void save(); protected: int lenx,leny; int arcstart,arcend;/记录已画图形/templateclass graphlistpublic: graphlist(); void show(); void s

27、how(GRAPH *g); void hide(); void hide(GRAPH *g); void move_to(int derection,int step); void move_to(int derection,int step,GRAPH *g); void expand(int delta); /放大 void expand(int delat,GRAPH *g); void contract(int delta); /缩小 void contract(int delat,GRAPH *g); void save(); void load(); void save(GRAP

28、H *g); void del(); void del(GRAPH *g); void add(GRAPH *g,int gkind); void curnext(); / 将当前作图的指针移到下一个 void shake(); / 图形振动 void hide_process(int x_record,int y_record,int xtemp,int ytemp); / 隐藏画图中的多余轨迹 struct NODE GRAPH *graph; int graphkind; NODE *next; *head,*CurNode; int backgroundcolor; / 当前作图背景颜

29、色 int paintorder; / 当前选中的Tools int ispainting; / 是否是画图状态 int paintcolor; / 当前作图颜色 int linestyle; / 当前作图线宽 int paintlen; / 当前窗口长 int paintwide; / 当前窗口宽 int windowmove; / 当前作图窗口移动方式;/graphlist Glist;/鼠标类定义/class MOUSEpublic: MOUSE(); int MouseInit(); int MouseRead(); void MouseMath(); void MouseOn();

30、void MouseOff(); void MouseChange(); int MouseInbox(int x1,int y1,int x2,int y2); int mousex,mousey,mousez; int mousekind; / 鼠标是手1还是箭头0 protected: union REGS regs; int up1616,down1616; int mouse_draw1616; int pixel_save1616; / 保存被鼠标覆盖的区域颜色 int edgecolor; / 鼠标边缘颜色 int fillcolor; / 鼠标中心颜色;/窗口类定义/class

31、 WINDOW:public MOUSEpublic: WINDOW(); void CreatWindow(char *text,int x,int y,int length,int width,int color,int type); void InButton(int x,int y,int len,int hig,int col,int typ); void OutButton(int x,int y,int len,int hig,int col,int typ); void MinBar(int x,int y,int col); void MaxBar(int x,int y,i

32、nt col); void CloseBar(int x,int y,int col); int windowprocess(); protected: int winx,winy; int winlength,winwidth; int wintype;int menuposion4; char wintext50; char menutext45; static int graphmode;wnd;int WINDOW:graphmode=0;/文件名: graphclass.cpp/功 能: 图形类的类实现/作 者: 0501xql QQ:527274766 2007.7.8/-/ 各类

33、图形类的实现/-/#include graphclass.hppFIGURE:FIGURE(int x,int y,int lstyle,int lcolor)x_pos=x;y_pos=y;style=lstyle;color=lcolor;return;void FIGURE:move_to(int bkcolor,int direction,int speed)hide(bkcolor);switch(direction)/避免把图形移动到作图区域外case LEFT:/* if(x_posspeed)*/x_pos-=speed; break;case RIGHT:/*if(x_pos

34、+speedspeed)*/y_pos-=speed; break;case DOWN: /*if(y_pos+speed15|fillcolor0) return; c=getpixel(x,y); /获取当前点的颜色 if(c=xycolor) /如果颜色为边界色则不填充 putpixel(x, y, fillcolor); /画点 Fill(fillcolor, color,x, y+1); Fill(fillcolor, color,x, y-1); Fill(fillcolor, color,x+1 ,y); Fill(fillcolor, color,x-1 ,y); */-MYLINE:MYLINE(int x1,int y1,int x2,int y2,int style,int color):FIGURE(x1,y1,style,color)x_pos2=x2;y_pos2=y2;return;void MYLINE:show()setcolor(color);setlinestyle(SOLID_LINE,1,style);line(x_pos,y_pos,x_pos2,y_pos2);setlinestyle(SOLID_LINE,1,1);return;void

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号