Click here to Skip to main content
15,922,145 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
to add/sub/multiply/divide two complex numbers using classes providing in two textboxes
e.g
(2+3i)+(2-6i)=answer
the addtion should be done in one textbox and can change the opeartor,
the values should be inserted manually nt in code itself...
n answer should be in another textbox...
m n need ... plz help me....
Posted
Updated 14-Jun-12 1:34am
v3
Comments
arizan 14-Jun-12 7:19am    
thanx....
but i wanted to give values manually not in code itself...
i am new in vb.net....
Dave Kreskowiak 14-Jun-12 8:21am    
OK, so what were you having a problem with?? Nobody is going to just hand you a completed project.

This screams of being homework, so it's up to YOU to do this project. We'll only help with specific problems you're having.
arizan 15-Jun-12 0:13am    
Actually i have written a class for it which is right one.. bt in form getting bit confused
this is my code..
Public Class Form1
Dim mycomplexnumber As Complexnumber
Dim a As New Complexnumber
Dim b As New Complexnumber
Dim c As New Complexnumber

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
textbox1.Text = a.ToString
c = a + b
textbox2.Text = c.ToString
End Sub
bt how to do addition of a & b in same textbox????????
that code i m nt getting

 
Share this answer
 
Comments
VJ Reddy 14-Jun-12 7:40am    
Good reference. 5!
try this code i hope it will work

SQL
Public Class COmplexNumber
    Public realNo As Integer
    Public imag As Integer


  Public Function calctn(C1 As COmplexNumber, C2 As COmplexNumber,ByVal optr as string) As COmplexNumber
        Dim result As New COmplexNumber
        if (optr ="+") then
        result.realNo = (C1.realNo + C2.realNo)
            result.imag = (C1.imag + C2.imag)

    else if (optr ="-") then
        result.realNo = (C1.realNo - C2.realNo)
            result.imag = (C1.imag - C2.imag)

    else if (optr ="*") then
        result.realNo = (C1.realNo * C2.realNo)
            result.imag = (C1.imag * C2.imag)

    else if (optr ="/") then
        result.realNo = (C1.realNo / C2.realNo)
            result.imag = (C1.imag / C2.imag)
    end if
        calctn = result
    End Function
End Class
 
Share this answer
 
Try operator overloading like this


Public Class Form1

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim a, b, c As New COmplexNumber
a.realNum = 1
a.imaginary = 2
b.realNum = 2
b.imaginary = 3

c = a + b

TextBox1.Text = c.realNum & "+i" & c.imaginary
End Sub

End Class
Public Class COmplexNumber
Public realNum As Integer
Public imaginary As Integer

Public Shared Operator +(num1 As COmplexNumber, num2 As COmplexNumber) As COmplexNumber
Dim result As New COmplexNumber
result.realNum = num1.realNum + num2.realNum
result.imaginary = num1.imaginary + num2.imaginary
Return result
End Operator

End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900