C 帶小括號的運算

2021-09-19 02:59:34 字數 4333 閱讀 2159

計算類的封裝

jisuan.cs

1

using

system;

2using

system.collections.generic;

3using

system.linq;

4using

system.text;56

namespace

zy四則運算721

22const

string operators = "

+-*/

"; //

運算子23

24public

double compute(double leftnum, double rightnum, char op) //

這是一種方法,用來計算左右兩個數的靜態方法!

2534}35

36public

bool isoperator(char op) //

每次判斷這個字元是否是運算子?

3740

41public

bool isassoc(char op) //

返回乙個關聯符號

4245

46public queue queuesort(string expression) //

佇列排序

4762

else

6371 operatorstack.push(cur); //

把數字壓棧72}

73else

if (cur == '

)') //

將右括號新增到結尾

7479}80

else

8188 i =j;

89result.enqueue(tempnum);90}

91}92}

93while (operatorstack.count > 0)94

101102

result.enqueue(cur);

103}

104105

return

result;

106}

107108

public

double calucate(string

expression)

109125

else

126129

}130

return

operandstack.pop();

131}

132catch

133136

}137

}138 }

form1.cs

1

using

system;

2using

system.collections.generic;

3using

system.componentmodel;

4using

system.data;

5using

system.drawing;

6using

system.linq;

7using

system.text;

8using

system.windows.forms;

9using

system.io;

1011

namespace

zy四則運算

1220

private

void button1_click_1(object

sender, eventargs e)

2127

private

void button2_click(object

sender, eventargs e)

2831

}32 }

form2.cs

1

using

system;

2using

system.collections.generic;

3using

system.componentmodel;

4using

system.data;

5using

system.drawing;

6using

system.linq;

7using

system.text;

8using

system.windows.forms;

9using

system.io;

1011

namespace

zy四則運算

1219

int time = 40; //

倒計時20

int count = 0;21

int right = 0;22

private

void form2_load(object

sender, eventargs e)

23

28private

void timer1_tick(object

sender, eventargs e)

2937}38

private

void button1_click_1(object

sender, eventargs e)

3943

private

void button2_click_1(object

sender, eventargs e)

4447

private

void button3_click_1(object

sender, eventargs e)

4860

sw.flush();

61sw.close();

62fs.close();63}

64}65private

void listbox1_selectedindexchanged(object

sender, eventargs e)

6671

else

7275}76

private

void textbox2_keydown(object

sender, keyeventargs e)

7787 count++;

88if (textbox2.text ==js.calucate(result).tostring()) //

直接呼叫calucate這個方法計算result的值並與輸入的值進行比較

8995

96else

97102 label1.text = "

正確率:

" + convert.tostring(right * 1.0 / count * 100).padright(5, '

').substring(0, 5) + "%"

;103

textbox1.clear();

104textbox2.clear();

105}

106}

107}

108 }

執行測試:出題介面:

答題介面:

提示結束:

儲存:

土倫 閱讀(

...)

編輯收藏

C 帶小括號的運算

計算類的封裝 jisuan.cs 1 using system 2using system.collections.generic 3using system.linq 4using system.text 56 namespace zy四則運算721 22const string operator...

shell中的大括號和小括號

2009 7 23 13 27 32 在這裡我想說的是幾種shell裡的小括號,大括號結構和有括號的變數,命令的用法,如下 1.2.cmd 3.和 4.5.exp 6.var pattern var pattern var pattern var pattern 現在分述如下 1.shell中變數的...

C 11 大括號和小括號的使用

c 11之前主要有以下幾種初始化方式 小括號初始化 string str hello 等號初始化 string str hello pod物件與pod陣列列表初始化 struct studnet studnet s 純資料 plain of data,pod 型別物件 studnet sarr po...