C课后习题参考答案(7)

2019-04-17 00:22

习题参考答案

printf(\

fclose(fp1); fclose(fp2); }

习 题 11

一、填空题

1、文本模式 图形模式 2、字符 像素

3、80 25 0 0 79 24

4、图形系统初始化 关闭图形系统 5、BGI

二、程序设计题 1、参考程序

#include #include

/* 将屏幕初始化成自测试图形方式 */ void init() {

int gd=DETECT,gm,err; initgraph(&gd,&gm,\ err=graphresult(); if(err!=0)

{printf(\ printf(\ getch(); exit(1); }

cleardevice(); }

main()

{char str[30]=\ int i,j,maxx,maxy,k; init();

maxx=getmaxx(); maxy=getmaxy(); k=1;

while(k<20)

{ i=rand()%maxx; /*产生不小于最大屏幕x值的随机数*/ j=rand()%maxy; /*产生不小于最大屏幕y值的随机数*/ setcolor(WHITE+k); outtextxy(i,j,str);

325

习题参考答案

delay(100000); k++; }

getch();

closegraph(); }

2、参考程序

#include #include

/* 将屏幕初始化成自测试图形方式 */ void init() {

int gd=DETECT,gm,err; initgraph(&gd,&gm,\ err=graphresult(); if(err!=0)

{printf(\ printf(\ getch(); exit(1); }

cleardevice(); }

/*函数large()将显示放大的字符*/

void large(int x,int y,unsigned char *str,int space,int color) {void readcclib(); unsigned char buf[72]; unsigned int upattern; int i,ci;

char ascstr[2]; setcolor(color); ci=0;

while(ci

ascstr[0]=str[ci];ascstr[1]='\\0';

settextstyle(SMALL_FONT,HORIZ_DIR,9);

outtextxy(x,y-3,ascstr);x=x+textwidth(\ ci+=strlen(ascstr); } }

main()

{int i; char str[30]=\ init();

326

for(i=100;i<110; i++)

large(50+i,50+i,str,5,WHITE+i); getch();

closegraph(); }

3、参考程序

#include

/* 将屏幕初始化成自测试图形方式 */ void init() {

int gd=DETECT,gm,err; initgraph(&gd,&gm,\ err=graphresult(); if(err!=0)

{printf(\ printf(\ getch(); exit(1); } }

main() {int i; init();

setbkcolor(BLUE); for(i=10;i<130; i+=10) {setcolor(WHITE+i/10); circle(250,250,i); }

getch(); }

4、参考程序

#include #include #include

/* 将屏幕初始化成自测试图形方式 */ void init() {

int gd=DETECT,gm,err; initgraph(&gd,&gm,\ err=graphresult(); if(err!=0)

{printf(\ printf(\ getch();

习题参考答案

327

习题参考答案

exit(1); }

cleardevice(); }

/* 画一个四边形填充框

(left,top) : 左上角坐标 ; (right,bottom) : 右下角坐标 ; color : 填充颜色 */ void draw_window(int left,int top,int right,int bottom,int color) { setwritemode(0);

setfillstyle(SOLID_FILL,color); bar(left,top,right,bottom); }

/* 画一个带凸凹的四边形填充框

(left,top) 左上角坐标; (right,bottom) :右下角坐标; width : 凸或凹的宽度; color1 : 下边框颜色;

color2 : 上边框颜色; color3 : 内框填充颜色 */ void draw3d(int left,int top,int right,int bottom, int width,int color1,int color2,int color3) {

int shape[6]; setwritemode(0);

setfillstyle(SOLID_FILL,color1);

bar(left+width,bottom-width,right-width,bottom); bar(right-width,top+width,right,bottom); setfillstyle(SOLID_FILL,color1); setcolor(color1);

shape[0]=right; shape[1]=top+width; shape[2]=right; shape[3]=top; shape[4]=right-width; shape[5]=top+width; fillpoly(3,shape);

shape[0]=left+width; shape[1]=bottom; shape[2]=left+width; shape[3]=bottom-width; shape[4]=left; shape[5]=bottom; fillpoly(3,shape);

setfillstyle(SOLID_FILL,color2); bar(left,top,right-width,top+width);

bar(left,top+width,left+width,bottom-width); setfillstyle(SOLID_FILL,color2); setcolor(color2);

shape[0]=right-width; shape[1]=top; shape[2]=right;

shape[3]=top; shape[4]=right-width; shape[5]=top+width; fillpoly(3,shape);

shape[0]=left; shape[1]=bottom-width; shape[2]=left+width; shape[3]=bottom-width; shape[4]=left; shape[5]=bottom; fillpoly(3,shape);

setfillstyle(SOLID_FILL,color3);

bar(left+width,top+width,right-width,bottom-width);

328

习题参考答案

}

/* 画按钮

color1,color2,color3 : 见 draw3d() 函数的说明 */ void draw_bar(int left,int top,int right,int bottom, int color1,int color2,int color3,char s[])

{ draw3d(left+5,top+3,right-5,bottom-3,2,color2,color1,color3); setcolor(BLACK);

outtextxy(left+16,top+12,s); }

main() {

init();

setfillstyle(SOLID_FILL,LIGHTGRAY); bar(100,100,200,210);

draw_window(105,105,195,205,WHITE);

draw_window(108,108,192,202,LIGHTGRAY);

draw_bar(120,110,180,140,WHITE,BLACK,LIGHTGRAY,\ draw_bar(120,140,180,170,WHITE,BLACK,LIGHTGRAY,\ draw_bar(120,170,180,200,WHITE,BLACK,LIGHTGRAY,\ getch();

closegraph(); }

329


C课后习题参考答案(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:高压电动机技术规范书

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: