2 回答

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個(gè)贊
f(c=='-')
{
if(strcmp(str2,"")==0) /*如果str2為空,說明是負(fù)號,而不是減號*/
flag=-1; /*設(shè)置負(fù)數(shù)標(biāo)志*/
else
{
num1=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/
strcpy(str2,""); /*將str2清空*/
act=2; /*做計(jì)算減法標(biāo)志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/
outtextxy(5*width,height,"0."); /*顯示字符串*/
}
}
if(c=='*')
{
num1=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/
strcpy(str2,""); /*將str2清空*/
act=3; /*做計(jì)算乘法標(biāo)志值*/
setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*顯示字符串*/
}
if(c=='/')
{
num1=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/
strcpy(str2,""); /*將str2清空*/
act=4; /*做計(jì)算除法標(biāo)志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*顯示字符串*/
}
if(c=='^')
{
num1=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/
strcpy(str2,""); /*將str2清空*/
act=5; /*做計(jì)算乘方標(biāo)志值*/
setfillstyle(SOLID_FILL,color+3); /*設(shè)置用淡綠色實(shí)體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/
outtextxy(5*width,height,"0."); /*顯示字符串*/
}
if(c=='%')
{
num1=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/
strcpy(str2,""); /*將str2清空*/
act=6; /*做計(jì)算模運(yùn)算乘方標(biāo)志值*/
setfillstyle(SOLID_FILL,color+3); /*設(shè)置用淡綠色實(shí)體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/
outtextxy(5*width,height,"0."); /*顯示字符串*/
}
if(c=='=')
{
num2=atof(str2); /*將第二個(gè)操作數(shù)轉(zhuǎn)換為浮點(diǎn)數(shù)*/
switch(act) /*根據(jù)運(yùn)算符號計(jì)算*/
{
case 1:result=num1+num2;break; /*做加法*/
case 2:result=num1-num2;break; /*做減法*/
case 3:result=num1*num2;break; /*做乘法*/
case 4:result=num1/num2;break; /*做除法*/
case 5:result=pow(num1,num2);break; /*做x的y次方*/
case 6:result=fmod(num1,num2);break; /*做模運(yùn)算*/
}
setfillstyle(SOLID_FILL,color+3); /*設(shè)置用淡綠色實(shí)體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆蓋結(jié)果區(qū)*/
sprintf(temp,"%f",result); /*將結(jié)果保存到temp中*/
outtextxy(5*width,height,temp); /*顯示結(jié)果*/
}
if(c=='c')
{
num1=0; /*將兩個(gè)操作數(shù)復(fù)位0,符號標(biāo)志為1*/
num2=0;
flag=1;
strcpy(str2,""); /*將str2清空*/
setfillstyle(SOLID_FILL,color+3); /*設(shè)置用淡綠色實(shí)體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆蓋結(jié)果區(qū)*/
outtextxy(5*width,height,"0."); /*顯示字符串*/
}
if(c=='Q')exit(0); /*如果選擇了q回車,結(jié)束計(jì)算程序*/
}
putimage(x,y,rar,XOR_PUT); /*在退出之前消去光標(biāo)箭頭*/
return; /*返回*/
}
/*窗口函數(shù)*/
void mwindow( char *header )
{
int height;
cleardevice(); /* 清除圖形屏幕 */
setcolor( MaxColors - 1 ); /* 設(shè)置當(dāng)前顏色為白色*/
setviewport( 20, 20, MaxX/2, MaxY/2, 1 ); /* 設(shè)置視口大小 */
height = textheight( "H" ); /* 讀取基本文本大小 */
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );/*設(shè)置文本樣式*/
settextjustify( CENTER_TEXT, TOP_TEXT );/*設(shè)置字符排列方式*/
outtextxy( MaxX/4, 2, header ); /*輸出標(biāo)題*/
setviewport( 20,20+height+4, MaxX/2+4, MaxY/2+20, 1 ); /*設(shè)置視口大小*/
drawboder(); /*畫邊框*/
}
void drawboder(void) /*畫邊框*/
{
struct viewporttype vp; /*定義視口類型變量*/
setcolor( MaxColors - 1 ); /*設(shè)置當(dāng)前顏色為白色 */
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );/*設(shè)置畫線方式*/
getviewsettings( &vp );/*將當(dāng)前視口信息裝入vp所指的結(jié)構(gòu)中*/
rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top ); /*畫矩形邊框*/
}
/*設(shè)計(jì)鼠標(biāo)圖形函數(shù)*/
int arrow()
{
int size;
int raw[]={4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4}; /*定義多邊形坐標(biāo)*/
setfillstyle(SOLID_FILL,2); /*設(shè)置填充模式*/
fillpoly(8,raw); /*畫出一光標(biāo)箭頭*/
size=imagesize(4,4,16,16); /*測試圖象大小*/
rar=malloc(size); /*分配內(nèi)存區(qū)域*/
getimage(4,4,16,16,rar); /*存放光標(biāo)箭頭圖象*/
putimage(4,4,rar,XOR_PUT); /*消去光標(biāo)箭頭圖象*/
return 0;
}
/*按鍵函數(shù)*/
int specialkey(void)
{
int key;
while(bioskey(1)==0); /*等待鍵盤輸入*/
key=bioskey(0); /*鍵盤輸入*/
key=key&0xff? key&0xff:key>>8; /*只取特殊鍵的掃描值,其余為0*/
return(key); /*返回鍵值*/
}

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊
純C語言,沒有圖形界面的,要做出圖形界面,得依靠系統(tǒng)的API,如MFC、WIN32 API、QT、等
- 2 回答
- 0 關(guān)注
- 209 瀏覽
添加回答
舉報(bào)