Complex : Complex Number « Data Type « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Data Type » Complex Number 
2.19.1.Complex
public class Test

   public Shared Sub Main
        Dim X, Y As Complex
        X = New Complex(14)
        Y = New Complex(23)

        Console.WriteLine((X + Y).ToString)
        Console.WriteLine((X - Y).ToString)
        Console.WriteLine((X * Y).ToString)
        Console.WriteLine((X = Y).ToString)
        Console.WriteLine((X <> Y).ToString)
        Console.WriteLine((-X).ToString)
        Dim abs_x As Double = CDbl(X)
        Console.WriteLine(abs_x.ToString)

   End Sub

End class


Public Class Complex
    Public Re As Double
    Public Im As Double

    Public Sub New()
    End Sub
    Public Sub New(ByVal real_part As Double, ByVal imaginary_part As Double)
        Re = real_part
        Im = imaginary_part
    End Sub

    Public Overrides Function ToString() As String
        Return Re.ToString & " + " & Im.ToString & "i"
    End Function

    Public Shared Operator *(ByVal c1 As Complex, ByVal c2 As ComplexAs Complex
        Return New Complex_
            c1.Re * c2.Re - c1.Im * c2.Im, _
            c1.Re * c2.Im + c1.Im * c2.Re)
    End Operator
    Public Shared Operator +(ByVal c1 As Complex, ByVal c2 As ComplexAs Complex
        Return New Complexc1.Re + c2.Re,c1.Im + c2.Im)
    End Operator
    Public Shared Operator -(ByVal c1 As Complex, ByVal c2 As ComplexAs Complex
        Return New Complex(c1.Re - c2.Re, c1.Im - c2.Im)
    End Operator
    Public Shared Operator =(ByVal c1 As Complex, ByVal c2 As ComplexAs Boolean
        Return (c1.Re = c2.ReAndAlso (c1.Im = c2.Im)
    End Operator
    Public Shared Operator <>(ByVal c1 As Complex, ByVal c2 As ComplexAs Boolean
        Return (c1.Re <> c2.ReOrElse (c1.Im <> c2.Im)
    End Operator
    Public Shared Operator -(ByVal c1 As ComplexAs Complex
        Return New Complex(c1.Im, c1.Re)
    End Operator
    Public Shared Narrowing Operator CType(ByVal c1 As ComplexAs Double
        Return System.Math.Sqrt(c1.Re * c1.Re + c1.Im * c1.Im)
    End Operator
End Class
3 + 7i
-1 + 1i
-10 + 11i
False
True
4 + 1i
4.12310562561766
2.19.Complex Number
2.19.1.Complex
2.19.2.Complex Number
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.