用C 寫多型計算器

2021-10-20 22:57:41 字數 3588 閱讀 8673

多型計算器涉及到的知識點有繼承,重寫,多型,抽象類,抽象方法

以父類做模板,子類套用

呼叫方法時,向下轉型,父類引用指向子類引用

根據計算符號來確定父類要指向的子類

設定迴圈,迴圈為字串的長度,使用length接收

將迴圈到的字元轉換為byte格式

如果byte不為數字範圍,表明包含非數字字元

如果含有非數字字元就返回false

如果沒有字元就返回true

需要用到的控制項有:groupbox,combobox,button,label,textbox

主窗體**:

using system;

using system.collections.generic;

using system.componentmodel;

using system.data;

using system.drawing;

using system.linq;

using system.text;

using system.threading.tasks;

using system.windows.forms;

namespace 多型計算器

private

void

combobox1_selectedindexchanged

(object sender,

eventargs e)

private

void

form1_load

(object sender,

eventargs e)

private

void

loaddata()

public

bool

isnumber

(string temp)

}return

true;}

private

void

button1_click

(object sender,

eventargs e)if(

isnumber

(textbox1.text.

trim()

)&&isnumber

(textbox2.text.

trim()

))else

// 獲取運算操作符

// 獲取組合框的文字內容

string fuhao = combobox1.text;

// 計算物件

jisuan js=

null

;// 根據不同的符號,賦值不同的物件

switch

(fuhao)

**加粗樣式*

*// 運算

// 獲得資料

int num1 = convert.

toint32

(textbox1.text)

;int num2 = convert.

toint32

(textbox2.text)

; js.

yunsuan

(num1,num2)

;// 讓標籤顯示內容

label2.text = js.result.

tostring()

;}}}

父類**:

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace 多型計算器

}

子類加法**:

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace 多型計算器

}}

子類減法**:

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace 多型計算器

}}

子類除法**:

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace 多型計算器

}}

子類乘法**:

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace 多型計算器

}}

子類取餘**:

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace 多型計算器

}}

子類平方**:

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace 多型計算器

}}

用VB寫計算器

我是沒什麼心思寫計算器的。不過要參加星火杯的話這個坎還是要過一過。emmmm然後發現寫個gui真是步步艱難,先用了vs發現特麼廢流量,再用qt一直蜜汁錯誤。然後。然後最終還是向vb低頭orz 演算法上不存在什麼問題啦。只是不熟悉而且很多細節需要注意。debug幾下就好。最重要的是學到了用程式寫程式的...

C 多型例項 計算器

include using namespace std class calculator void stev2 int v2 為私有屬性賦值的介面 int getresult string oper else if oper 操作 private int value1 int value2 void...

正則寫計算器

之前看到網上有很多在問正規表示式去編寫計算器的 也有很多放出了自己的 所以利用空閒時間 自己也寫了乙個,時間匆忙可能 有些小瑕疵不排除會有bug.還是那句話進攻參考 import re unm 1 2 60 30 40 5 9 2 5 3 7 3 99 4 2998 10 568 14 4 3 16...