###### tags: `作業-進階` `大一程設` `東華大學` `東華大學資管系` `基本程式概念` `資管經驗分享` HW3-1 === 這一題用陣列其實很容易,但為了讓大家更加了解第六章與第八章字串,**HW3-1 請嘗試不用陣列,並多利用字串處理的各種函式完成此題。** ## Description 假設今天你手邊有一份資料,資料內容如下,請點選下方連結複製內容至 txt 檔案。 <a href="http://www.elearn.ndhu.edu.tw/moodle/file.php/91280/test_data.txt" download="test_data.txt">test_data.txt</a> | Name | Age | Salary Per Month | Gender | Marriage | | -------- | -------- | -------- | -------- | -------- | | David | 24 | 32.5 | Male | Y | | John | 23 | 40 | Male | N | | Amy | 32 | 45.5 | Female | Y | | Amily | 45 | 60 | Female | N | | Steven | 40 | 70.5 | Male | Y | | Bob | 60 | 100 | Male | Y | | Rebecca | 36 | 50 | Female | Y | 請根據第六章檔案讀取的內容讀取檔案,並根據字串處理的工具處理檔案內的文字,請寫出一支程式來讀取這份檔案,並求出這份資料的平均年齡、平均薪水、平均男性薪水、平均女性薪水、已婚人士平均薪水以及未婚人士平均薪水。 * 相關字串處理的工具請閱讀下方第八章字串筆記 * [字串String](https://hackmd.io/@ndhu-programming-2021/SJwkBQW0t) ## Constraint * 讀取每行資料請利用迴圈,並能夠偵測到是否讀取完畢 * 提示 ``` while(!in.eof()){ ... } ``` * <span style="color:red">**HW3-1 請嘗試在不用陣列的情況下完成此題**</span> * **若使用陣列一律不算分** * 複製檔案時,第一行的 column 也須包含在內 * 你的 test_data.txt 必須和下圖長的一樣,我們一律以此種樣式做為測資 *  * 檔案開啟的路徑一律統一,請繳交答案時確定路徑如下 * `in.open("test_data.txt")` ## Hint * 使用 `string.find("我要找的字串",從字串的第幾個開始找) 的時候` 若找不到,函式會回傳 -1 或是最大整數 npos,若有利用 `string.find()` 來判斷沒有找到,在做條件判斷時,請 -1 跟 npos 都需考慮,否則會有問題。 * 範例: ``` if(s.find("a", 3) != string::npos || s.find("a", 3) != -1){...} ``` * 上面只是範例,實際的條件情況依你所想的情況而有不同 ## Sample Input And Output 
×
Sign in
Email
Password
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