2016年10月6日 星期四

單元:ch01. 第一個程式、ch02. 資料的基本概念


1. 主控台應用程式用到的輸出方法有:console.write ,  console.writeline

2. 主控台應用程式用到的輸入方法有:console.read ,  console.readline


3. 寫出 VB 運算子的優先順序(由上到下代表高到低)

   : 算術運算>關係運算>邏輯運算

4. 只用一條程式碼,印出上機練習題 1 的結果。(字串串接及程式碼換行排版練習)


    Sub Main()
        Console.WriteLine("=====Console.WriteLine練習====") 
        Console.WriteLine("班級:資應一甲") :
        Console.WriteLine("學號1110534016") 
        Console.WriteLine("姓名:陳薇安") 
        Console.WriteLine("===============================")
    End Sub

5. 不恰當的資料型態宣告,會影響到結果的正確性。請參考 [ch02.資料的基本概念投影片] pp. 15-16 試寫一程式來印出各數值型別之表示範圍,並和課本比較是否有異。

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim ans As String = "" '答案字串
        ans = "型態" & vbTab & "Byte" & vbTab & "範圍" & vbNewLine
        'ans = ans & "sByte" & vbTab & "1" & vbTab &  SByte.MinValue & "~" & SByte.MaxValue & vbNewLine
        ans &= "sByte" & vbTab & "1" & vbTab & SByte.MinValue & "~" & SByte.MaxValue & vbNewLine
        ans &= "Byte" & vbTab & "1" & vbTab & Byte.MinValue & "~" & Byte.MaxValue & vbNewLine
        ans &= "short" & vbTab & "2" & vbTab & Short.MinValue & "~" & Short.MaxValue & vbNewLine
        ans &= "ushort" & vbTab & "2" & vbTab & UShort.MinValue & "~" & UShort.MaxValue & vbNewLine
        ans &= "integer" & vbTab & "4" & vbTab & Integer.MinValue & "~" & Integer.MaxValue & vbNewLine
        ans &= "uinteger" & vbTab & "4" & vbTab & UInteger.MinValue & "~" & UInteger.MaxValue & vbNewLine
        ans &= "long" & vbTab & "8" & vbTab & Long.MinValue & "~" & Long.MaxValue & vbNewLine
        ans &= "ulong" & vbTab & "8" & vbTab & ULong.MinValue & "~" & ULong.MaxValue & vbNewLine
        ans &= "single" & vbTab & "4" & vbTab & Single.MinValue & "~" & Single.MaxValue & vbNewLine
        ans &= "double" & vbTab & "8" & vbTab & Double.MinValue & "~" & Double.MaxValue & vbNewLine
        ans &= "decimal" & vbTab & "12" & vbTab & Decimal.MinValue & "~" & Decimal.MaxValue & vbNewLine

        MsgBox(ans)
    End Sub

6. 請各位寫一個文字模式的程式,導引使用者輸入數值 x,數值 y,展示此二數的各項算 術運算 ^ * / \ mod + - 結果(專案檔名: ch03-ConsoleIO-xxxxxxx)

Sub Main()
        Dim x, y As Single
        Console.WriteLine("輸入數值 x,數值 y")
        Console.Write("數值x=")
        x = Console.ReadLine
        Console.Write("數值y=")
        y = Console.ReadLine
        Console.WriteLine(x & "^" & y & "=" & x ^ y)
        Console.WriteLine(x & "*" & y & "=" & x * y)
        Console.WriteLine(x & "/" & y & "=" & x / y)
        Console.WriteLine(x & "\" & y & "=" & x \ y)
        Console.WriteLine(x & "mod" & y & "=" & x Mod y)
        Console.WriteLine(x & "+" & y & "=" & x + y)
        Console.WriteLine(x & "-" & y & "=" & x - y)
        Console.WriteLine("展示此二數的各項算術運算 ^ * / \ mod + - 結果")

    End Sub

7. 輸入半徑 r , 印出此圓之「圓周長」及「圓面積」。 (專案檔名: ch03-ConsoleCircle-xxxxxxx-prj, 請用常數來定義圓周率 pi=3.14159265)

 Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        ' 輸入半徑 r , 印出此圓之「圓周長」及「圓面積」。
        Dim ans As String = "" '答案
        Const pi = 3.1415926
        ' 輸入半徑 r 
        Dim r As Single
        r = InputBox("半徑 r =", "輸入半徑 r , 印出此圓之「圓周長」及「圓面積」。", 0)
        '印出此圓之「圓周長」
        ans &= "圓周長=" & 2 * pi * r & vbNewLine
        '及「圓面積」。
        ans &= "圓面積=" & pi * r ^ 2

        MsgBox(ans, , "結果")

    End Sub

沒有留言:

張貼留言