2020年6月14日 星期日

讀書心得 - C++ Primer (5th Edition) - Chapter 1

簡單的 C++ 程式

    要寫一個 C++ 程式跟 C 一樣,寫好 cpp 檔,交給編譯器 ( g++ ) 編成可執行程式。程式至少包含一個名為 main 的 function,用以當作程式的入口 function。
    int main() {
        return 0; // return 0 的原因為 0 通常代表著程式執行成功。
    }

Input/Output

    C++ 本身並沒有定義 I/O,需要額外的標準函式庫,iostream。
    #include <iostream>
    int main()
    {
        // operator << >> 會回傳左邊的 operand
        // 以 std::cin >> v1 >> v2; 為例
        // 執行結果 =
        //     std::cin >> v1;
        //     std::cin >> v2;
        int v1, v2;
        std::cout << "Enter two numbers:" << std::endl;
        std::cin >> v1 >> v2;
        std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1 + v2 << std::endl;
        return 0;
    }

Note

常用詞彙

  • prompt 提示 驅使

    We can extend our main program to prompt the user to give us two numbers and then print their sum

  • expression (數學中的)式,表達式

    The smallest unit of computation. An expression consists of one or more operands and usually one or more operators. Expressions are evaluated to produce a result. For example, assuming i and j are ints, then i + j is an expression and yields the sum of the two int values.

  • angle brackets : <>

  • quotation marks : ""

  • curly braces : {}

  • operator : 運算子

  • operand : 運算元

  • assignment

    Obliterates an object’s current value and replaces that value by a new one.

  • comments : 註解

  • statement : wiki

    The new part of this program is the while statement.A while has the form

    while (condition)
        statement

    A while executes by(alternately) testing the condition and executing the associated
    statement until the condition is false.A condition is an expression that yields a result
    that is either true or false..So long as condition is true, statement is executed.
下一篇 :

Related Posts:

  • Windows Command Line CMD : Command Line 列出檔案 dir // 列出當前資料夾下的檔案 dir /s // 列出當前資料夾下 + 子資料夾的檔案 dir /? // 列出所有 dir 的指令參數 輸出成檔案 dir /? > 123.txt… Read More
  • MySQL 筆數查詢、分頁查詢 N 筆資料查詢 SELECT * FROM 成績單 LIMIT 3 // 取成績單前三筆資料 SELECT * FROM 成績單 ORDER BY 分數 DESC LIMIT 3 // 取分數前三名的資料 SELECT * FROM 成績單 ORDER BY 分數 DESC LIMIT 3, 7 // 取第四名到第十名的資料 分頁查詢      隨著查詢筆數越來越多,網站可能就會需… Read More
  • 網頁開發(1) 使用 IE 瀏覽器時 Javascript 失效我本人非專業寫網頁,大學沒寫過是進公司才學的,因為沒人維護XD 公司常用瀏覽器是 IE,因為IE可以直接讓你以檔案總管的方式直接開啟 file://... 的超連結,其他瀏覽器都會擋,詳細原因我不知道,但這個可以讓你方便調用 SERVER 上資料,方便很多,其實其他瀏覽器也可以辦到,但要做設定,但不可能你叫公司員工都做這設定,所以大家都用 IE,離題了... JS 檔放到 Server 後無反應     我自己在寫程式時,第… Read More
  • IE CSS 失效 CSS 在 IE 瀏覽器下失效 在網站開發時,總會發現 IE 瀏覽器跟別人不太一樣 最常出事就是 CSS,CSS 在 IE 瀏覽器下失效 提供幾個從 stackoverflow 找的方法能影響下面 Do not code CSS on the HTML file     這裡應該是指 CSS Code 有很多 HTML Code 不一樣,舉個最常出現的例子就是註解。 <style type ="text… Read More
  • Python UnitTest Unit Test      單元測試有一個通用模式 AAA原則,理解了就可以開始實作 Arrange   : 初始化物件、要用到的參數 Act   : 呼叫要測試的方法 Assert   : 驗證測試結果 Python Unit Test      unittest — Uni… Read More

0 意見:

張貼留言

Popular Posts