--- Title: 筆記庫 tags: 各語言定義 disqus: C --- 彰師大資工系學生自學筆記 === **目錄** [TOC] ## 學習歷程 沒什麼,就住八卦山上(๑• . •๑) 我的日記: https://medium.com/@aa0983563272 我的筆記: https://hackmd.io/?nav=overview 實作題練習: https://hackmd.io/2L1FDFgATr2xasuTLfoKWQ 我的Github: https://github.com/pinchen1017 我的讀書帳: https://www.instagram.com/112_friendlygroup/ | 大一上 | 大一下 | 大二上 | 大二下 | 大三上 | 大三下 | 大四上 | | -------------- |:---------------- | ------------ | ------ | ------ | ------ | ------ | | 計算機技術 | 物件導向程式設計 | 硬體描述語言 | | | | | | 計算機概論 | 數位邏輯 | 微處理機技術 | | | | | | 程式設計 | 進階程式設計 | JAVA程式設計 | | | | | | 微積分(一) | 微積分(二) | 資料結構 | | | | | | 教學媒體與運用 | 線性代數 | 電腦網路 | | | | | | | | 離散數學 | | | | | ## 目標 身為資工人我需要一個打敗客戶的能力 ![打敗客戶](https://hackmd.io/_uploads/SJQm2-F5p.jpg) 所以做為英雄,我必須準備好一切 [耍帥技巧](https://www.kocpc.com.tw/archives/194013) **必要條件** | 過人的聰明才智 | 可以斬破一切的劍 | 打怪的經驗 | 好的人緣 | | -------------- | ------------------ | ---------------- | -------- | | 演算法 | Python | Leetcode | 會算命 | | 線性代數 | C | ZeroJudge | 長的ok | | 離散數學 | C++ | 一堆專案 | 會彈吉他 | | | Java | 去104找人才資質 | 會繪畫 | | | C# | 找人一起打怪 | | | | Javascript | 把抽象內容便真實 | | **打怪策略** | 入大學前 | 大一上 | 寒假 | 大一下 | 暑假 | 大二上 | 寒假 | 大二下 | 暑假 | 大三上 | 寒假 | 大三下 | 暑假 | 大四上 | | ---------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ---- | ------ | ---- | ------ | ---- | ------ | ---- | ------ | | C++(高中) | C(計技+程設) | **C/C++(觀念+使用)** | **2~3小時學程式(Python/C/C++)** | Leetcode 100題\\[刷題初階](https://cses.fi/problemset/)\\[刷題中級](https://atcoder.jp/contests/dp/tasks)\\[刷題高級](https://vjudge.net/article/524) | **程式競賽(ICPC/CPE)**[相關資料](https://hackmd.io/@jakao/collegiateCompetitionsProgramming#%E5%88%B7%E9%A1%8C) | 多益、CPE考試 | | | | | | | | | Python(入大學前的暑假) | 計概(初步) | **資工系了解** | **參加專案比賽** | Data Science & Data Analysis | 設計專案 | | | | | | | | | | | 會看別人的程式+解決 | 線性代數\\[線性代數講義](https://web.mit.edu/18.06/www/)\\[線性代數影片](https://www.youtube.com/watch?v=J7DzL2_Na80&list=RDCMUCEBb1b_L6zDS3xTUrIALZOw&start_radio=1&rv=J7DzL2_Na80&t=3) | [台大電機碩班課程_學習機器人](https://speech.ee.ntu.edu.tw/~hylee/ml/2021-spring.php)\\[機器學習2021](https://www.youtube.com/playlist?list=PLJV_el3uVTsMhtt7_Y6sgTHGHp1Vb2P2J) | Competitive Programing | Github整理+投履歷? | | | | | | | | | | | 跟朋友一起讀書 | 演算法 | 線性代數\\[線性代數講義](https://web.mit.edu/18.06/www/)\\[線性代數影片](https://www.youtube.com/watch?v=J7DzL2_Na80&list=RDCMUCEBb1b_L6zDS3xTUrIALZOw&start_radio=1&rv=J7DzL2_Na80&t=3) | Google 類神經網路線上上課 | GDSC 社團 | | | | | | | | | | | | 寒假作業(つ﹏⊂) | 演算法 | 學習地圖 | 工讀 | | | | | | | | | | | |**英文** | 課業 | 思考未來 | | | | | | | | | | | | | | 紀錄學習成長([日記](https://medium.com/@aa0983563272)\\[筆記](https://hackmd.io/?nav=overview)) | 好好休息 | | | | | | | | | | | | | |**英文** | | | | | | | | | | | **打怪地圖** ![尋寶圖](https://hackmd.io/_uploads/B16tTXt5p.jpg) ▲Picure 1 學習地圖(大二進行規劃) **打怪等級** - [ ] 對生活有熱情,追尋夢想 [中正資工學長](https://future-outlier.medium.com/%E9%9B%B6%E5%9F%BA%E7%A4%8E%E8%B3%87%E5%B7%A5%E7%B3%BB%E5%AD%B8%E7%94%9F%E5%9C%A8%E6%88%90%E7%82%BAgoogle%E5%B7%A5%E7%A8%8B%E5%B8%AB%E4%B9%8B%E8%B7%AF-af5d71300d82) [Google 面試準備](https://www.1111.com.tw/1000w/fanshome/discussTopic.asp?cat=FANS&id=346361) - [ ] 課業顧好 - [ ] coding實力增強 [如何練習 LeetCode 問題(正確的方法)](https://medium.com/@anthonydmays/how-to-practice-leetcode-questions-the-right-way-4f9735cf06c6) [各程式的學習資源](https://www.johntool.com/programming-language-rank/#C_%E5%AD%B8%E7%BF%92%E8%B3%87%E6%BA%90) [程式語言的輸入輸出彙整](https://medium.com/@s1084535/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80%E7%9A%84%E8%BC%B8%E5%85%A5%E8%BC%B8%E5%87%BA-%E5%BD%99%E6%95%B4-cab0337313a9) - [ ] 解決事情的能力 - [ ] 英文(閱讀/溝通) - [ ] 吉他 - [ ] 社交(珍惜身邊朋友,有多餘能力才可以認識不同人為主) - [ ] 運動 # 小驚喜 ## 1. CodeBlocks 的 Debug 問題 簡而言之,CodeBlocks 20.3 版本的gdb.exe不能用 1. CodeBlocks Debugger [2015 程式設計 如何使用 CodeBlocks 的 Debugger](https://www.youtube.com/watch?v=HghfCpOcfF0) [2015 程式設計 如何使用 CodeBlocks 的 Debugger Part 2 要設 -g](https://www.youtube.com/watch?v=Jx5a6hxEg0g) 2. 解决codeblocks新版(20.03)不能debug问题(https://blog.csdn.net/yuemanxilou_/article/details/122390989) **個人解決辦法** 依照第一、二項內容確認是否做完,不過因為普遍是版本問題所以無法debug,解決辦法只有換個gdb.exe進行編譯。 他debug的主要概念是將gdb.exe執行後灌入某C++檔案的.exe檔進行除錯。 除錯方法有兩種,簡單一點就是從以下的Executable path進行更換 我的原本為: **C:\Program Files\CodeBlocks\MinGW\bin\gdb.exe** 改成: **C:\MinGW\bin\gdb.exe** ![image](https://hackmd.io/_uploads/H1zwIlacp.png) 除了使用CodeBlocks上的debug功能,也可以使用cmd進行執行 (Window+R+cd.../資料夾路徑+cmd)。 1. dir 列出目錄找尋資料夾中的程式檔(通常列出< DIR >代表其裡面還有小資料夾)。 ![image](https://hackmd.io/_uploads/rJXx2y6cT.png) 2. 將路徑轉進想除錯的資料夾裡並再列出目錄一次。 ![image](https://hackmd.io/_uploads/r1mNhyaqa.png) 3. 將路徑轉進 bin 裡並再列目錄。 ![image](https://hackmd.io/_uploads/HkHunkT5a.png) 4. 將路徑轉進 debug 裡,並讓C槽中gdb.exe在這裡執行,執行完記得打quit關閉。 ![image](https://hackmd.io/_uploads/H1i93kacT.png) 5. 讓gdb.exe再執行一遍,並在後面附上除錯檔案的執行檔名稱,一樣執行完記得打quit關閉。 ![image](https://hackmd.io/_uploads/HJrh3kpqT.png) ## 2. Dev-C++ CPU 狀態視圖 ![image](https://hackmd.io/_uploads/HyNbAf6qT.png) ## 3. 動態記憶體配置( new / delet ) New C++用來作為函數的指標指向新配置的記憶體,通常用來製作一維陣列 ``` void* new void* new[] ``` Delet C++用來作為函數的指標指向刪除配置的記憶體 ``` void delet(void* p) void delet[](void* p) ``` 例如: ```C++ int *p=new int; int *p=new int[10]; delet p; delet[] p; ``` ```C++== #include <iostream> //固定輸入與輸出流為鍵盤與終端機 #include <fstream> //開通文件流 #define _USE_MATH_DEFINES //定義數學常數 #include <cmath> //數學函式庫 #include <ctime> //時間函式庫 #include <cstdlib> //C語言中的基本函式庫(繼承) #include <cctype> //辨別資料型態 #include <cstring> //string資料型態的設定 using namespace std; int *sqr(int *, int); int main() { int score[5]={99,44,78,87,55}; int *result=sqr(score,5); for(int i=0;i<5;i++){ cout<<"score["<<i<<"]= "<<score[i]<<endl; cout<<"result["<<i<<"]= "<<result[i]<<endl; } return 0; } int *sqr(int *arr, int n){ int *a=new int[n]; //用來製造一維陣列,新配置的記憶體n個 for(int i=0;i<n;i++){ *(a+i)=arr[i]*arr[i]; } return a; } ``` ## 4.函式指標 設立指標指向函式,使其成為新的函式名稱,指向元函式位址,並可以將值丟入進行計算。 ```C++== #include <iostream> //固定輸入與輸出流為鍵盤與終端機 #include <fstream> //開通文件流 #define _USE_MATH_DEFINES //定義數學常數 #include <cmath> //數學函式庫 #include <ctime> //時間函式庫 #include <cstdlib> //C語言中的基本函式庫(繼承) #include <cctype> //辨別資料型態 #include <cstring> //string資料型態的設定 using namespace std; int add(int, int); int diff(int, int); int main() { int (*p)(int, int); int result, a=20, b=10; p=add; cout<<"函式p的位址為"<<&p<<endl; cout<<"函式p的內容為"<<(int)p<<endl; cout<<"函式add的位址為"<<(int)add<<endl; result=p(a,b); cout<<a<<"+"<<b<<"= "<<result<<endl; p=diff; cout<<"函式p的位址為"<<&p<<endl; cout<<"函式p的內容為"<<(int)p<<endl; cout<<"函式diff的位址為"<<(int)diff<<endl; result=p(a,b); cout<<a<<"-"<<b<<"= "<<result<<endl; return 0; } int add(int x, int y){ return x+y; } int diff(int x, int y){ return x-y; } ``` ## 5. C++的!文件指標.eof()會吃到enter 在C++中,為了確保所有字串有被正常讀入,會以以下方式進行輸寫: ``` #include <fstream> #include <cassert> ifsream in("文件名稱"); string input; while(!in.eof()){ in>>input; } ``` 但因為其<kbd>\n</kbd>會被吃到,所以需要注意文件是否有<kbd>\n</kbd>,否則整個程式會再被執行一次。 ## 6. 迴圈變數不能用到unsinged int 因為當迴圈中的i變成負數時,會從4294967296開始往下算,使迴圈會無法結束,例如: ``` unsigned int i=length-1; while(i>=0){ cout<<i<<" "; i--; } ``` ## 7. C 本身不支援 long double ,所以在 printf 上面需要改成 ``` __mingw_printf("j = %.2Lf\n",j); ``` ## 8. 後綴字在 unsigned long int 在計算方面可能會出問題 i 因為數字初始設定為 int ,所以無法負荷計算值造成差別 ![image](https://hackmd.io/_uploads/HJRNHyYyA.png) ## 9. 浮點數的誤差值 double 其實有隱藏小數點多位,如果直接比較會出問題 建議用 EPS 或是 fabs 來讓浮點數精確度統一 ??? 用浮點數去除會有問題??? ## 10. 計算機的程式設計人員 QWORD -> 8 bytes、DWORD -> 4 bytes ![image](https://hackmd.io/_uploads/SkEJvktk0.png) ## 11. static_cast<data_type>(data_name) 要記得加 () !! ## 12. 浮點數精確度 ![image](https://hackmd.io/_uploads/rywpj2UlC.png) 如果要取小數點底下第 n 位,應該要對小數點底下 n+6 位進行精確度測試 ``` //假設要取小數點底下第二位 if(fabs((floor(area*100)+0.5)-area*100)<1e-8){ area = round(floor(area*100)+0.5)/100; } ``` 主要是將答案 <kbd>* 1e-n</kbd> 後,小數點底下第六位後的會先被四捨五入後才會對進行小數點底下第 n 位進行四捨五入。 # 13. 萬用標頭檔 ``` #include <bits/stdc++.h> ``` 我還在努力啦~٩(๑>◡<๑)۶