📂
CMiOSBook
  • CMoney iOS Book
  • Coding 101
    • Value / Reference Type
    • ARC + Retain Cycle
    • 物件之間的溝通方式
  • 工具主題
    • 基本工具篇
    • Git 篇
  • 架構主題
    • MVC
  • CodingStyle主題
    • CodingStyle 規則
      • 專案(Project)
      • 命名(Naming)
      • 程式格式(Format)
      • 註解(Comment)
      • 類別與結構(Classes and Structures)
      • 修飾詞(Modifier)
      • 閉包表達式(Closures)
    • 靜態檢查器
    • 專案基本規定
  • UI主題
    • UIScrollViewDelegate & UITableViewDelegate
  • Charts主題
    • 簡介
    • Lesson1 Chart Setup
    • Lesson2 Chart Data
    • Lesson3 CombinedChartView
    • Lesson4 Renderer
  • Test主題
    • 單元測試的基本概念
    • XCTest-UnitTest
    • XCTest-UITest
  • 學習資源
    • 相關網站
    • 相關會議與社群
    • 計算機考題
Powered by GitBook
On this page
  • if else 的寫法
  • 繼承與多型的寫法
  • 計算機考題:
  • 延伸議題:

Was this helpful?

  1. 學習資源

計算機考題

使用繼承與多型來取代 if else,練習OOP的概念。

Previous相關會議與社群

Last updated 4 years ago

Was this helpful?

if else 的寫法

func execute(input: String){
    if input == "A"{
        // 做A事情
    } else if input == "B"{
        // 做B事情
    }
}

繼承與多型的寫法

class Base{
    func doSomething(){}
}

class A: Base{
    override func doSomething(){
        // 做A事情
    }
}

class B: Base{
    override func doSomething(){
        // 做B事情
    }
}

func execute(base: Base){
    base.doSomething()
}

計算機考題:

請不要使用if else來實作簡單的計算機

  • 先實作簡單輸入(ex. 1+2=3)

  • 先不考慮先乘除後加減的案例

  • 考慮多位數輸入(ex. 12+35=47)

  • 考慮連續輸入(ex. 1+2+3+4=10)

  • 考慮取代輸入(ex. 先輸入1+,再輸入-,變成1-)

延伸議題:

  1. 計算式把中序轉後序

  2. 把後序的運算符號放入Stack裡計算即可

先乘除後加減需要兩步驟 -

參考資料Link
計算機