protected void divComp_Click(object sender, EventArgs e) { string x, y, q, w; x = TextBox4.Text; y = TextBox5.Text; q = TextBox7.Text; w = TextBox8.Text; object[] newobj = new object[2]; newobj[0] = new cFloat(Convert.ToSingle(x), Convert.ToSingle(y)); newobj[1] = new cFloat(Convert.ToSingle(q), Convert.ToSingle(w)); Type classtype = assem.GetType("ComplexCalc"); Object obj = Activator.CreateInstance(classtype); MethodInfo myMethodInfo = classtype.GetMethod("divide"); object[] mParam = new object[] { newobj[0], newobj[1] }; cFloat flOut = (cFloat)myMethodInfo.Invoke(obj, mParam); float realfl = flOut.getReal(); float imfl = flOut.getImg(); TextBox6.Text = realfl.ToString(); TextBox9.Text = imfl.ToString(); }
private void invokeComplex(string operation) { Type typeC = DLL.GetType("ComplexMath"); // complex num 1 float r1 = Convert.ToSingle(Real1.Text); float i1 = Convert.ToSingle(Complex1.Text); float r2 = Convert.ToSingle(Real2.Text); float i2 = Convert.ToSingle(Complex2.Text); var arg1 = new cFloat(r1, i1); var arg2 = new cFloat(r2, i2); // clear text boxes here. clearTextBoxes(); //MessageBox.Show(typeC.GetMethod("Add")); Object obj = Activator.CreateInstance(typeC); MethodInfo method = typeC.GetMethod(operation); var result = method.Invoke(obj, new object[] { arg1, arg2 }); Type typeD = DLL.GetType("cFloat"); Result2.Text = Convert.ToString(typeD.GetMethod("getReal").Invoke(result, new object[] {})); Result3.Text = Convert.ToString(typeD.GetMethod("getImg").Invoke(result, new object[] { })); /*if (result.GetType() == typeof(cFloat)){ * cFloat meta = result. * } * //Result2.Text = Convert.ToString(method.Invoke(obj, new object[] { arg1, arg2 })); * method = */ }
}//multiply public cFloat divide(cFloat c1, cFloat c2){ Complex comp1 = new Complex(c1.getReal(), c1.getImg()); Complex comp2 = new Complex(c2.getReal(), c1.getImg()); Complex comp3 = comp1 / comp2; return new cFloat((float)comp3.Real, (float)comp3.Imaginary); }//divide
// Returns the result of multiplying cFloat number a and b. public cFloat multiply(cFloat a, cFloat b) { float p1 = a.getReal() * b.getReal(); float p2 = a.getReal() * b.getImg(); float p3 = a.getImg() * b.getReal(); float p4 = a.getImg() * b.getImg(); return new cFloat(p1 + p4, p2 + p3); }
public cFloat divide(cFloat a, cFloat b) { float real, imag; real = a.getReal() / b.getReal(); imag = a.getImg() / b.getImg(); cFloat c = new cFloat(real, imag); return(c); }
public cFloat subtract(cFloat a, cFloat b) { float real, imag; real = a.getReal() - b.getReal(); imag = a.getImg() - b.getImg(); cFloat c = new cFloat(real, imag); return(c); }
public cFloat multiply(cFloat a, cFloat b) { float real, imag; real = a.getReal() * b.getReal(); imag = a.getImg() * b.getImg(); cFloat c = new cFloat(real, imag); return(c); }
public cFloat subtract(cFloat c1, cFloat c2) { return(new cFloat(c1.getReal() - c2.getReal(), c1.getImg() - c2.getImg())); }
}//subtract public cFloat multiply(cFloat c1, cFloat c2){ return new cFloat(((c1.getReal()*c2.getReal())-(c1.getImg()*c2.getImg())) ,((c1.getImg()*c2.getReal())+(c1.getReal()+c2.getImg()))); }//multiply
}//add public cFloat subtract(cFloat c1, cFloat c2){ return new cFloat((c1.getReal() - c2.getReal()), (c1.getImg() - c2.getImg())); }//subtract
public cFloat add(cFloat c1, cFloat c2){ return new cFloat((c1.getReal() + c2.getReal()), (c1.getImg() + c2.getImg())); }//add
// Returns the result of subtracting cFloat number b from a. public cFloat subtract(cFloat a, cFloat b) { return new cFloat(a.getReal() - b.getReal(), a.getImg() - b.getImg()); }
// Returns the result of adding Complex number a to b. public cFloat add(cFloat a, cFloat b) { return new cFloat(a.getReal() + b.getReal(), a.getImg() + b.getImg()); }
// Returns the result of dividing cFloat number b from a. public cFloat divide(cFloat a, cFloat b) { return new cFloat(a.getReal() / b.getReal(), a.getImg() / b.getImg()); }
private void Calculate(object sender, RoutedEventArgs e) { Button b = (Button)sender; if (b.Name == "SinT") { SimpleCalc s = new SimpleCalc(); try { Result.Text = "Result: " + s.sin(Convert.ToSingle(Num1.Text)); } catch (FormatException) { Result.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "CosT") { SimpleCalc s = new SimpleCalc(); try { Result.Text = "Result: " + s.cos(Convert.ToSingle(Num1.Text)); } catch (FormatException) { Result.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "TanT") { SimpleCalc s = new SimpleCalc(); try { Result.Text = "Result: " + s.tan(Convert.ToSingle(Num1.Text)); } catch (FormatException) { Result.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "SimplePlus") { SimpleCalc s = new SimpleCalc(); try { SimpleResult.Text = "Result: " + s.add(Convert.ToSingle(SimpleNum1.Text), Convert.ToSingle(SimpleNum2.Text)); } catch (FormatException) { SimpleResult.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "SimpleMinus") { SimpleCalc s = new SimpleCalc(); try { SimpleResult.Text = "Result: " + s.subtract(Convert.ToSingle(SimpleNum1.Text), Convert.ToSingle(SimpleNum2.Text)); } catch (FormatException) { SimpleResult.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "SimpleMultiply") { SimpleCalc s = new SimpleCalc(); try { SimpleResult.Text = "Result: " + s.multiply(Convert.ToSingle(SimpleNum1.Text), Convert.ToSingle(SimpleNum2.Text)); } catch (FormatException) { SimpleResult.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "SimpleDivide") { SimpleCalc s = new SimpleCalc(); try { SimpleResult.Text = "Result: " + s.divide(Convert.ToSingle(SimpleNum1.Text), Convert.ToSingle(SimpleNum2.Text)); } catch (FormatException) { SimpleResult.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "SimplePower") { SimpleCalc s = new SimpleCalc(); try { SimpleResult.Text = "Result: " + s.pow(Convert.ToSingle(SimpleNum1.Text), Convert.ToSingle(SimpleNum2.Text)); } catch (FormatException) { SimpleResult.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "SimpleModulous") { SimpleCalc s = new SimpleCalc(); try { SimpleResult.Text = "Result: " + s.mod(Convert.ToSingle(SimpleNum1.Text), Convert.ToSingle(SimpleNum2.Text)); } catch (FormatException) { SimpleResult.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "ComplexPlus") { ComplexCalc c = new ComplexCalc(); try { cFloat num1 = new cFloat(Convert.ToSingle(ComplexReal1.Text), Convert.ToSingle(ComplexImg1.Text)); cFloat num2 = new cFloat(Convert.ToSingle(ComplexReal2.Text), Convert.ToSingle(ComplexImg2.Text)); cFloat res = c.add(num1, num2); ComplexResult.Text = "Result: (" + res.getReal() + "," + res.getImg() + ")"; } catch (FormatException) { ComplexResult.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "ComplexMinus") { ComplexCalc c = new ComplexCalc(); try { cFloat num1 = new cFloat(Convert.ToSingle(ComplexReal1.Text), Convert.ToSingle(ComplexImg1.Text)); cFloat num2 = new cFloat(Convert.ToSingle(ComplexReal2.Text), Convert.ToSingle(ComplexImg2.Text)); cFloat res = c.subtract(num1, num2); ComplexResult.Text = "Result: (" + res.getReal() + "," + res.getImg() + ")"; } catch (FormatException) { ComplexResult.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "ComplexMultiply") { ComplexCalc c = new ComplexCalc(); try { cFloat num1 = new cFloat(Convert.ToSingle(ComplexReal1.Text), Convert.ToSingle(ComplexImg1.Text)); cFloat num2 = new cFloat(Convert.ToSingle(ComplexReal2.Text), Convert.ToSingle(ComplexImg2.Text)); cFloat res = c.multiply(num1, num2); ComplexResult.Text = "Result: (" + res.getReal() + "," + res.getImg() + ")"; } catch (FormatException) { ComplexResult.Text = "Please Enter Valid Numbers"; } } else if (b.Name == "ComplexDivide") { ComplexCalc c = new ComplexCalc(); try { cFloat num1 = new cFloat(Convert.ToSingle(ComplexReal1.Text), Convert.ToSingle(ComplexImg1.Text)); cFloat num2 = new cFloat(Convert.ToSingle(ComplexReal2.Text), Convert.ToSingle(ComplexImg2.Text)); cFloat res = c.divide(num1, num2); ComplexResult.Text = "Result: (" + res.getReal() + "," + res.getImg() + ")"; } catch (FormatException) { ComplexResult.Text = "Please Enter Valid Numbers"; } } }
public cFloat add(cFloat c1, cFloat c2) { return(new cFloat(c1.getReal() + c2.getReal(), c1.getImg() + c2.getImg())); }
public cFloat divide(cFloat c1, cFloat c2) { return(new cFloat(Convert.ToSingle((c1.getReal() * c2.getReal()) + (c1.getImg() * c2.getImg()) / Convert.ToSingle((c2.getReal() * c2.getReal()) + (c2.getImg() * c2.getImg()))), (Convert.ToSingle((c1.getImg() * c2.getReal()) - (c1.getReal() * c2.getImg())) / Convert.ToSingle((c2.getReal() * c2.getReal()) + (c2.getImg() * c2.getImg()))))); }
public cFloat multiply(cFloat c1, cFloat c2) { return(new cFloat(((c1.getReal() * c2.getReal()) - (c1.getImg() * c2.getImg())), ((c1.getReal() * c2.getImg()) + (c1.getImg() * c2.getReal())))); }