Chia-Po Wei
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 計算機程式甲 2018 課程討論區 請依下面格式提出問題,並讓新的問題出現在最上方 - 林義閔 物理系 大三 2019/01/05 - 請問老師,這題輸出的結果會是May th嗎?不懂為何答案給 May t - ![](https://i.imgur.com/9ZQAFqP.png) - <span style="color:green">Teacher Response:</span> - 課本答案沒錯,`cin.getline` 的輸入參數是 C-string,要留一個字元給 `\0` - 請問老師,所以這題如果是C++string,輸出結果就是May th囉? - <span style="color:green">Teacher Response:</span> - `cin.getline` 只能接受 C-string 不能接受 C++ string - `getline(cin, cppString)` 的輸入參數才是 C++ string,請看 `07 Strings.pdf` 第31頁 - 林義閔 物理系 大三 2019/01/05 - 請問老師,課本P411第六題 How many characters are in each of the following,b小題題目是"n",我認為這樣有兩個(n和\0),但答案給一個? - <span style="color:green">Teacher Response:</span> - 課本寫錯,是2個字元 -謝謝老師 - 林義閔 物理系 大三 2019/01/05 - 請問老師,為何我將你給的測試改成shallow Copy了但他輸出的結果還是Deep Copy? - ![](https://i.imgur.com/7kym8Yt.png) - <span style="color:green">Teacher Response:</span> - 那是因為測試程式碼沒有用到 copy constructor,只有用到 assignment operator,所以修改 copy constructor 的定義不會有任何改變。我已修改 [test_class_PFArrayD.cpp](https://drive.google.com/open?id=1yReoLahWokRSQ8tFipJKDz8TWsXEOIXI),你再測看看 - 好,謝謝老師 - 林義閔 物理系 大三 2019/01/02 - 請問老師,是不是有說Assignment Operator不考? - <span style="color:green">Teacher Response:</span> - 對,assignment operator 的部分不考 <!--- ![](https://i.imgur.com/3miv72p.png)--> - 林義閔 物理系 大三 2019/01/02 - 老師,想再請問一下,我不懂的地方是,function同樣是compraeAlphabet,bobblesort和sort()使用同樣的function竟然輸出結果排序會不同,我的理解是如果定義是str1>str2,輸出的結果都要是從A排到Z吧?(下圖1和2),而sort()如果拿掉後面的compareAlphabet,輸出結果又變成從A排到Z(下圖3) - ![](https://i.imgur.com/6FRVQ5L.png) - ![](https://i.imgur.com/R7TBRO4.png) - ![](https://i.imgur.com/V1v44jt.png) - <span style="color:green">Teacher Response:</span> - 你的理解有誤,如果定義是 `str1 > str2`,`sort()` 的結果會從Z排到A,因為當 `str1 < str2` 時,`sort()` 才會做交換。所以我前面才說 `sort()` 與我實作的 `bubbleSort()` 發動交換的條件不同。 - 了解了,謝謝老師。 - 林義閔 物理系 大三 2019/01/01 - 老師,我有點不懂為何這兩個看起來很像的程式碼輸出結果卻不一樣?(第一張圖是你給的測試程式,第二張圖是你的PPT)![](https://i.imgur.com/9oD3uFo.png) - ![](https://i.imgur.com/O6tqQ75.png) - <span style="color:green">Teacher Response:</span> - 其實就是遞增與遞減的差異而已,第一張圖的輸出如果要跟第二張圖一樣的話,要把下面`compareAlphabet` 定義中的 `>` 換成 `<` ```c++ bool compareAlphabet(const string& str1, const string& str2) { return str1 > str2; } ``` - 可是第一張圖原本的bool是str1>str2,代表如果str1是Zebra,str2是Banana,他們會交換順序,所以Z開頭的字串應該要在最後面才對吧?為何輸出結果是Z開頭的字串在最前面? - <span style="color:green">Teacher Response:</span> - 這要看交換動作是什麼時候發動,我的 `bubbleSort()` 的交換是 `str1 > str2` 時發動,而 `sort()` 的交換是 `str1 < str2` 時才發動 - 林義閔 物理系 大三 2019/01/01 - 老師,可以請你解釋一下這邊程式碼在寫什麼嗎? - ![](https://i.imgur.com/WqWeZX0.png) - <span style="color:green">Teacher Response:</span> - 這兩行是把 `vecNames` 及 `&vecNames` 所占的記憶體大小印出來,來解釋 call-by-value 與 call-by-reference 在傳遞變數時的差異,call-by-reference 是傳記憶體位址 `&vecNames`, 只要傳 4 bytes;如果用 call-by-value 傳 `vecNames`, 要傳 12 bytes。 - 謝謝老師的回答 - 林義閔 物理系 大三 2019/01/01 - 老師,請問你的PPT當中,最初的版本沒有.assign,所以是你最初打錯了嗎? - ![](https://i.imgur.com/dInRBq2.png) - <span style="color:green">Teacher Response:</span> - 應該是最初的版本沒有補充 assign() 的用法,後來的版本才將 assign() 的用法加進來 - 莊博勛 電機系 大二 2018/12/29 - 老師,為什麼我用vector存入 two dimension array 程式一直出現bug(只有這段出現紅字檢查了數遍也無發現異常) ``` c++ int *x= new int*[n]; for(int i=0;i<n;i++) x[i]=new int [n]; ``` 另一個方法是書上寫的 ``` c++ vector <int> line; line.assign(n,0); vector<vector<int>>x; x.assign(n,line); ``` 感謝回答~~ > 你可以先看看錯誤訊息(錯誤訊息其實也應該要貼上來),如果你打上來的時候沒打錯的話,那段應該第一句就有問題了。 > `new int*[n]` 得到的東西應該是不能賦值給 `int*` 的變數的,錯誤訊息會告訴你他們分別是什麼類型。 > - <span style="color:green">Teacher Response:</span> - 謝謝淮宇的解說,他說的沒錯,要把錯誤訊息貼上來,最好把程式碼的連結也附上來 - `new int*[n]` 所傳回的變數型態是 `int **`,你把傳回的變數 assign 給 `int *` 是語法錯誤。下面是 g++ 編譯器所產生的錯誤訊息 - `error: cannot convert ‘int**’ to ‘int*’ in initialization` - vector 可以成功編譯 [onlinegdb](https://onlinegdb.com/Bkj3OzrW4) > 謝謝老師xD 感謝老師 我知道問題錯在哪了~下一次會多注意~*THANKS* - 林義閔 物理系 大三 2018/12/25 - 老師,那為何我把newline隱藏之後,程式依然可以運作? ![](https://i.imgur.com/DRoOKFU.png) ![](https://i.imgur.com/uDZ11pg.png) > 如果你輸入的答案是 `no` , `cin` 會接到3個字符(`"no\n"`),但 `ans` 只是一個 `char` ,所以 `n` 被 `ans` 接走 > 之後緩衝區裡還還有東西,這會讓下一次 `cin` 收到的東西跟預期的不一樣,所以用 `NewLine()` 把剩下的字丟掉。 > 你可以看到下面驗證答案的地方只檢查 `ans` 是不是等於 `'N'` 或 `'n'` 。 > Btw 我是淮宇 > > *奇怪,Markdown裡面換行不應該被解釋成換行吧,這網站的排版怪怪的* - <span style="color:green">Teacher Response:</span> - 謝謝淮宇清楚的解說 (不同網站對 Markdown 語法的解釋會有差異) - 林義閔 物理系 大三 2018/12/24 - 老師,我看不懂newline是如何運作的 - ![](https://i.imgur.com/GdEwltY.png) - 想請問24行的symble代表的是getInt裡面的什麼?是ans嗎?而他究竟是如何連同先前輸入的錯誤的number一起discard的? > `symbol` 只是一個用來接 `cin` 的變數, `NewLine()` 的運作方式是從 `cin` 接一個字符,放到 `symbol` 裡面,然後驗證該字符是不是 > 換行符號 `'\n'` ,重複直到接到換行符為止,所以錯誤的輸入就消失了。 - 林義閔 物理系 大三 2018/12/17 - 老師我從六點寫作業寫了六個多小時寫到現在QQ,剛剛好不容易寫出來交上去了,能不能請老師幫我測試一下正確率,我期中考沒有及格需要補一點分數QQ - 林義閔 物理系 大三 2018/11/21 - 老師想請問你上課講了很多vector的概念,有沒有測試的程式碼可以讓我們實際跑看看呢? - <span style="color:green">Teacher Response:</span> - 已更新 [Reference](https://sites.google.com/view/nsysu-dvlab/courses/%E8%A8%88%E7%AE%97%E6%A9%9F%E7%A8%8B%E5%BC%8F%E4%B9%99-2018/reference) 頁面 - 林義閔 物理系 大三 2018/11/18 - 老師想請問你的string講義P28頁,How many characters are in each of thefollowing constants?這題的選項a.'\n'和b."\n"差在哪裡呢? - <span style="color:green">Response:</span> - '\n' is a character, while "\n" is a C-string - 林義閔 物理系 大三 2018/10/12 - 老師請問你的講義P22頁這三行程式碼是代表什麼呢? - cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(1); - <span style="color:green">Response:</span> - `cout.setf(ios::showpoint)` 是顯示的時候一定要有小數點 - `cout.setf(ios::fixed)` 是用一般小數點表示法來顯示浮點數(而非科學記號表示法) - `cout.precision(1)` 是設定小數點後要顯示幾個位數 - 範例程式:[test_cout_setf.cpp](https://drive.google.com/open?id=11qP7BG8ny7ZuUZzHtua9xm3SBrv9B08O) - 林義閔 物理系 大三 2018/10/07 - 課本99頁範例的while loop最後有一行return 0;,請問這行的意義是? - <span style="color:green">此行跟 while 無關,Chapter 1 中提到 return 0; 的目的在</span> > This statement ends the invocation of the function main and returns 0 as the function’s value. - 曹淮宇 物理系 大四 2018/10/04 - OS: ~ - 習題2B的最後面要換行嗎? - <span style="color:green">Response: 此題換不換行都沒關係 (習慣上是會換行)</span> - 原本要傳圖片的xD 回好快 謝謝老師 - 鄭成功 電機甲 大一 2018/09/13 - OS: windows 10, Compiler: MingGW g++ - 無法正常執行 `g++ hello_world.cpp -o hello_world` - 上面命令列無法產生 `hello_world.exe`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully