C語言設計模擬計算器程式,C語言 設計一個 模擬計算器程式

時間 2021-08-11 17:14:53

1樓:滄海雄風

圖形介面 你打算用mfc 還是qt 還是c++builder

2樓:匿名使用者

#include /*dos介面函式*/

#include /*數學函式的定義*/

#include /*螢幕操作函式*/

#include /*i/o函式*/

#include /*庫函式*/

#include /*變數長度參數列*/

#include /*圖形函式*/

#include /*字串函式*/

#include /*字元操作函式*/

#define up 0x48 /*游標上移鍵*/

#define down 0x50 /*游標下移鍵*/

#define left 0x4b /*游標左移鍵*/

#define right 0x4d /*游標右移鍵*/

#define enter 0x0d /*回車鍵*/

void *rar; /*全域性變數,儲存游標圖象*/

struct palettetype palette; /*使用調色盤資訊*/

int graphdriver; /* 圖形裝置驅動*/

int graphmode; /* 圖形模式值*/

int errorcode; /* 錯誤***/

int maxcolors; /* 可用顏色的最大數值*/

int maxx, maxy; /* 螢幕的最大解析度*/

double aspectratio; /* 螢幕的畫素比*/

void drawboder(void); /*畫邊框函式*/

void initialize(void); /*初始化函式*/

void computer(void); /*計算器計算函式*/

void changetextstyle(int font, int direction, int charsize); /*改變文字樣式函式*/

void mwindow(char *header); /*視窗函式*/

int specialkey(void) ; /*獲取特殊鍵函式*/

int arrow(); /*設定箭頭游標函式*/

/*主函式*/

int main()

/* 設定系統進入圖形模式 */

void initialize(void)

getpalette( &palette ); /* 讀面板資訊*/

maxcolors = getmaxcolor() + 1; /* 讀取顏色的最大值*/

maxx = getmaxx(); /* 讀螢幕尺寸 */

maxy = getmaxy(); /* 讀螢幕尺寸 */

拷貝縱橫比到變數中*/

aspectratio = (double)xasp/(double)yasp;/* 計算縱橫比值*/

}/*計算器函式*/

void computer(void)

,c,temp[20]=;

char str1="1230.456+-789*/qc=^%";/* 定義字串在按鈕圖形上顯示的符號 */

mwindow( "calculator" ); /* 顯示主視窗 */

color = 7; /*設定灰顏色值*/

讀取當前視窗的大小*/

width=(vp.right+1)/10; /* 設定按鈕寬度 */

height=(vp.bottom-10)/10 ; /*設定按鈕高度 */

x = width /2; /*設定x的座標值*/

y = height/2; /*設定y的座標值*/

setfillstyle(solid_fill, color+3);

bar( x+width*2, y, x+7*width, y+height );

/*畫一個二維矩形條顯示運算數和結果*/

setcolor( color+3 ); /*設定淡綠顏色邊框線*/

rectangle( x+width*2, y, x+7*width, y+height );

/*畫一個矩形邊框線*/

setcolor(red); /*設定顏色為紅色*/

outtextxy(x+3*width,y+height/2,"0."); /*輸出字串"0."*/

x =2*width-width/2; /*設定x的座標值*/

y =2*height+height/2; /*設定y的座標值*/

for( j=0 ; j<4 ; ++j ) /*畫按鈕*/

y +=(height/2)*3; /* 移動行座標*/

x =2*width-width/2; /*復位列座標*/

}x0=2*width;

y0=3*height;

x=x0;

y=y0;

gotoxy(x,y); /*移動游標到x,y位置*/

arrow(); /*顯示游標*/

putimage(x,y,rar,xor_put);

m=0;

n=0;

strcpy(str2,""); /*設定str2為空串*/

while((v=specialkey())!=45) /*當壓下alt+x鍵結束程式,否則執行下面的迴圈*/

else

/*否則,右移到下一個字元位置*/

if(v==left) /*左移箭頭時新位置計算*/

if(x<=x0)

/*如果移到頭,再左移,則移動到最右邊字元位置*/

else

/*否則,左移到前一個字元位置*/

if(v==up) /*上移箭頭時新位置計算*/

if(y<=y0)

/*如果移到頭,再上移,則移動到最下邊字元位置*/

else

/*否則,移到上邊一個字元位置*/

if(v==down) /*下移箭頭時新位置計算*/

if(y>=7*height)

/*如果移到尾,再下移,則移動到最上邊字元位置*/

else

/*否則,移到下邊一個字元位置*/

putimage(x,y,rar,xor_put); /*在新的位置顯示游標箭頭*/

}c=str1[n*5+m]; /*將字元儲存到變數c中*/

if(isdigit(c)||c=='.') /*判斷是否是數字或小數點*/

/*將標誌值恢復為1*/

sprintf(temp,"%c",c); /*將字元儲存到字串變數temp中*/

strcat(str2,temp); /*將temp中的字串連線到str2中*/

setfillstyle(solid_fill,color+3);

bar(2*width+width/2,height/2,15*width/2,3*height/2);

outtextxy(5*width,height,str2); /*顯示字串*/

}if(c=='+')

if(c=='-')

}if(c=='*')

if(c=='/')

if(c=='^')

if(c=='%')

if(c=='=')

setfillstyle(solid_fill,color+3); /*設定用淡綠色實體填充*/

bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆蓋結果區*/

sprintf(temp,"%f",result); /*將結果儲存到temp中*/

outtextxy(5*width,height,temp); /*顯示結果*/

}if(c=='c')

if(c=='q')exit(0); /*如果選擇了q回車,結束計算程式*/

}putimage(x,y,rar,xor_put); /*在退出之前消去游標箭頭*/

return; /*返回*/

}/*視窗函式*/

void mwindow( char *header )

void drawboder(void) /*畫邊框*/

/*設計滑鼠圖形函式*/

int arrow()

; /*定義多邊形座標*/

setfillstyle(solid_fill,2); /*設定填充模式*/

fillpoly(8,raw); /*畫出一游標箭頭*/

size=imagesize(4,4,16,16); /*測試圖象大小*/

rar=malloc(size); /*分配記憶體區域*/

getimage(4,4,16,16,rar); /*存放游標箭頭圖象*/

putimage(4,4,rar,xor_put); /*消去游標箭頭圖象*/

return 0;

}/*按鍵函式*/

int specialkey(void)

用c語言編寫簡單計算器程式,用c語言編寫一個簡單計算器程式

問明 include stdio h 計算器 voidmenu 自定義的選單介面 printf n printf 請輸入你的選擇 n printf 1 n printf 2 n printf 3 n printf 4 n printf n intmain inti 0 intj 0 intnum 0...

C語言中如何實現計算器功能,c語言如何建立一個按鈕?做計算器用

如果你的表示式不超過一級括號,可以不使用棧.如你的例題,但象這樣不用棧很煩 3 4 3 2 6 3 如只有一級,沒人寫,就加我.include using namespace std bool cal double lv,char op,double rv,double val return tru...

題目18 用C語言設計簡單的計算器,要求能夠對輸入的數

include include include int deal int op1,int op2,char op 運算 return op1 char replace char source,char sub,char rep 字串替換 else pc1 source source pc1 null...