Organizing Your Program Code (P.508)

Slides:



Advertisements
Similar presentations
Overview of Previous Lesson(s) Over View  In computing, a visual programming language (VPL) is any programming language that lets users create programs.
Advertisements

Programming File I/O. COMP102 Prog. Fundamentals File I/O / Slide 2 Copyright © 2000 by Brooks/Cole Publishing Company A division of International Thomson.
五校社團標竿學習 「社團學習策略聯盟 ( 四 ) 」 中國科技大學『藝起傳薪』實務研討會. 『藝起傳薪』實務研討會 指導單位:教育部。 主辦單位:中國科技大學台北校區日間部學生會、學務處課外活動指導組。 協辦單位:德明財經科技大學、中國文化大學、聖約翰科技大學、 中華科技大學。 活動時間: 98 年.
National Chung Hsing University 國立中興大學企管系 Dr Ku-Ho Lin ( 林谷合 ) 14 th /Sep./2007 企業管理概論 Introduction to Business Management.
Technical English (I) Instructor: Kai-Yew Lum 林繼耀 Thursday 3pm – 6pm.
核心能力意見調查 計畫主持人:劉義周教授 研究助理: 林珮婷 報告日期: 調查案的目標與性質 調查的主要目的在進行宣傳,讓全校師生可以瞭 解何謂「課程地圖」與「核心能力」。 通識中心將核心能力主要區分為「學術訓練」、 「就業準備」、「公民文化養成」、「個人特質 提升」等四大面向,本調查依據此四大面向進一.
 Prentice Hall Chapter 71 科技與工作流程設計.  Prentice Hall Chapter 72 學習目標 了解科技如何影響生產力 討論電腦輔設計 認識彈性製造系統 定義組織再造的三項要素 資訊科技如何支援決策.
我的生涯 巫俊賢.
Chapter 0 Computer Science (CS) 計算機概論 教學目標 瞭解現代電腦系統之發展歷程 瞭解電腦之元件、功能及組織架構 瞭解電腦如何表示資料及其處理方式 學習運用電腦來解決問題 認知成為一位電子資訊人才所需之基本條 件 認知進階電子資訊之相關領域.
院 、 系所 學年度 中程校務發展計畫書撰寫說明 主辦單位 : 研究發展處 99 年 9 月 7 日.
1 真理大學運輸管理學系 實務實習說明 目錄  實務實習類別  實務實習條例  校外實習單位  實務實習成績計算方式  校外實習甄選 / 自洽申請流程  附錄:相關表格.
校務發展計畫. 目前高等教育所面臨的重要趨勢 1. 新科技的快速發展 -- 資訊科技,奈米科技,生物科 OOO 技, … 。 2. 知識經濟的重要發展 -- 強調培育專業人才,容易輕忽全人教 ooo 育。 3. 終身教育概念的形成 -- 如何提供社會各階層再教育的機會 -- 如何培養學生再學習的信心與能力.
遇見黃金山城:認識文化景觀 97-2 教育部優質通識課程獎助計畫 通識教育中心 / 黃士哲老師 第一週: 課程介紹與授課說明.
How to Bring the schools into 21 st Century? By Jane Kang.
環球技術學院 推動以通識教育為核心之全校課程 革新計畫 ( 第一年 / 三年計畫 ) 期初座談會 簡報 報告人:許舒翔 博士 環球技術學院 校長
國立成功大學性別與婦女研究中心: 回顧與展望 劉開鈴主任 2007 年 8 月 6 日. 跨領域研究,跨科際整合 成大研究型大學.
探索網站卓越中心計 劃啟動典禮 李芳樂 香港中文大學 資訊科技教育促進中心. 資訊科技教育促進中心 香港中文大學 Centre for the Advancement of Information Technology in Education.
真理大學航空運輸管理學系 實務實習說明. 實務實習部份 實務實習 校內實習 校外實習 實習時數必須在 300 小時 ( 含 ) 以上才承認 校內實習時數及實習成績。 二個寒假 各一個月 暑假兩個月.
21 st 世紀通識教育 賴 明 詔 2008/05/10. 環境變化與能力需求 1. 資訊爆炸,新領域出現頻繁 2. 壽命延長,須自我學習新知 3. 變化迅速,一生時常換工作 4. 世界交流,國際間活動增加 5. 競爭激烈,探索與關懷生命 1. 人文素養與專業技能 2. 融會貫通與創意 3. 領導能力.
專題製作(一) 邱明星 老師 遠東科技大學 資訊管理系. 專題製作的緣起 Learning how to learn. Know more. Learning space.
 Prentice Hall Chapter 11 歡迎來到多變的工作世界.  Prentice Hall Chapter 12 學習目標 描述全球化對經濟及組織的影響 檢視並討論人類歷史的三項衝擊 了解組織如何將風險外部化 解釋組織再造的發生原因 定義臨時勞動力 解釋兩種不同的勞動力 了解忠誠以保障工作想法的改變.
數位內容學院專業學程 說明會 廖文宏 6/8/2006. 緣由 經濟部工業局為鼓勵優秀學子積極投入數位內 容產業,並縮短業界對於應屆畢業學生的 職前訓練時間,因此委託數位內容學院與大學 院校合作,為即將畢業的大四或研究所學 生,規劃開設數位內容相關課程,讓學生能在 理論與實務兼具的課程中培養數位內容專.
FGU LDT. FGU EIS 96 ‧ 8 ‧ 25 FGU LDT 佛光大學學習與數位科技學系.
CS1103 電機資訊工程實習 Department of Computer Science National Tsing Hua University.
台灣客家知識治理之研究 -- 以 行政院客委會為例 發表人: 彭安麗 南華大學公共行政與政策研究所助理教授 發表人: 彭安麗 南華大學公共行政與政策研究所助理教授
1/18 技職校院校際合作人才培育計畫 校際合作 人才培育 台北海洋 技術學院 國立台灣 科技大學 國立台灣 戲曲學院 NATIONAL TAIWAN UNIVERSITY OF SCIENCE AND TECHNOLOGY.
國立臺南藝術大學 材質創作與設計系 Department of Material Arts and Design Tainan National University of The Arts 學生職涯進路圖.
行政院國家科學委員會工程技術發展處自動化學門 * 試以國立成功大學製造工程研究所 鄭芳田教授 產學合作計畫 : 智慧預測保養系統之設計與實作 成果報告盤點為範例 國科會工程處專題計畫成果典藏 自動化學門成果報告盤點範例.
逢甲大學公共政策研究所座談會 與談人:何彩滿 香港大學亞洲研究中心博士後研究員. 報告結構 香港高等教育的發展沿革 香港教育體制與資源分配結構 香港高等教育的未來 — 亞太的教育樞紐 國際化與國際化的弔詭 香港的大學、研究所與台灣的比較.
資訊管理學生為何要學習商管知識? 中央大學、資訊管理系 范錚強. 資訊管理學門  “The Study of the effective design, delivery and usage of information systems in organizations.” Keen (1980)
1 高等演算法 授課老師 : 陳建源 研究室 : 法 401 網站
Learning to change- 教師專 業發展的應變作法 高雄師範大學成人教育研究所教授 兼進修暨推廣部主任 王政彥.
大華技術學院九十五學年度 資工系計算機概論教學大綱 吳弘翔. Wu Hung-Hsiang2 科目名稱:計算機概論與實習 授課老師:吳弘翔 學分數: 4 修別:必修 老師信箱:
寬頻通訊系統基礎教育計畫 分項計畫二 寬頻網路通訊 主要參與人員 黎碧煌 教 授 鍾順平 副教授
廣電新聞播報品質電腦化 評估系統之研發 國立政治大學 資訊科學系 指導教授:廖文宏 學生:蘇以暄.
Open Services Gateway Initiative (OSGi) Service Platform 1 OSGi Architecture.
National United University Department of Electrical Engineering ( Meiling CHEN ) Lecture 00 應用線性代數 (3 學分 ) Linear algebra and its applications.
副校長室 1 教師績效獎勵制度 與 教師升等作業簡介 簡報人:江行全副校長 2007/09/06.
B. I. T. The Way Forward 李允中 教授 國立中央大學 資訊工程學系 1. ©2011 Jonathan Lee, National Central University. A Brief Bio of Jonathan Lee 學 歷: Texas A&M University,
1 會計與產業整合之理論與架構初探 許恩得 En-te Hsu 東海大學會計學系副教授兼系主任. 2 簡報流程 壹、導論 貳、會計知識發展模式 參、會計學系經營模式 肆、結論.
報告人:陳錦生 校長 日 期: 99 年 10 月 21 日. 自我評鑑報告內容簡介 校務評鑑五大項目 自我評鑑過程 簡述自我評鑑過程 學校現況 校地、教職員生數、圖書冊數、院系所學位學程.
資訊教育 吳桂光 東海大學物理系助理教授 Tel: 3467 Office: ST223 Office hour: Tue, Fri. (10-11am)
論文研討 2 學分 授課教師:吳俊概. 第一節 論文發表的目的 第二節 論文發表的歷程 第三節 投稿過程 第四節 退稿處理 學術期刊論文的製作與發表.
1 知識管理期中簡報 - 運用人力資源管理達成知識的移轉 報告者:白大倫 學號: 日期: 2006/11/13.
Programming File I/O. COMP102 Prog. Fundamentals File I/O / Slide 2 Copyright © 2000 by Brooks/Cole Publishing Company A division of International Thomson.
數位系統實驗 -- 課程介紹 教師:潘欣泰. 課程目標  數位系統導論課程之實習課程  接續數位電路學課程  養成學生動手做的習慣  使學生對數位電路設計有實際的體驗.
二十一世紀的大學教育 賴 明 詔 成功大學校長 2009 年 12 月 20 日. 2成功大學 成立於 1931 於台南 (鄭成功的故鄉 ) 工學院,理學院,文學院, 電機資訊,規劃 設計,管理學院,醫學院,社會科學,生物 科技學院 學生 : 人 (10462 大學生, 6948 碩士,
學校本位暨教師自我 專業進修研習規劃服務 教育訓練 指導單位:教育部 執行單位:全國教師在職進修資訊網 講 師:國立高雄師範大學進修學院教師生涯專業發展研究中心 曾子唐 專任研究助理 尤嬿琇 專任研究助理.
FILE I/O IN C++. Using Input/Output Files A computer file  is stored on a secondary storage device (e.g., disk);  is permanent;  can be used to provide.
RFID 認證 1/99 建國科技大學資管系 饒瑞佶 RFID 認證 CompTIA RFID + ( 國際 ) EPC/RFID ( 台灣 ) RFID 工程師教育認證 ( 台灣 ) 2/99.
CS Seminar Y.-W. Chang 1 CS Seminar 專題討論 張耀文 Yao-Wen Chang Department of Electrical Engineering.
Wah Yan International Conference 2004 Critical Assessment of the Educational Reforms in HK and their Challenges Dr. K.C. Pang Chief Executive, K C Pang.
File I/O in C++. Using Input/Output Files A computer file  is stored on a secondary storage device (e.g., disk);  is permanent;  can be used to provide.
File I/O in C++ I. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk); is permanent; can be used to provide.
壹、整體規劃與實施架構 英語輔導 小組定期 團務會議 研擬 計畫 成效 評估 回流 修正 匯集 成 果 形 成共識 分工合作.
Introduction Every program takes some data as input and generate processed data as out put . It is important to know how to provide the input data and.
Chapter 8 (Part 3) Library Classes for Strings (P.405)
CS Computer Science IA: Procedural Programming
What is a File? A file is a collection on information, usually stored on a computer’s disk. Information can be saved to files and then later reused.
Basic Input and Output Operations
Copyright © 2003 Pearson Education, Inc.
Chapter 3 Input output.
File I/O in C++ I.
Programming File I/O.
Reading from and Writing to Files
Chapter 1 c++ structure C++ Input / Output
Chapter 8 (Part 3) Library Classes for Strings (P.405)
生查子 ~ 歐陽修 去年元夜時,花市燈如晝, 月上柳梢頭,人約黃昏後; 今年元夜時,月與燈依舊, 不見去年人,淚濕春衫袖。
File I/O in C++ I.
Reading from and Writing to Files
Presentation transcript:

Organizing Your Program Code (P.508) Ex8_11: Distribute the code among several files. (P.506) This make it easy for you if you want to re-use any code from existing files in a new project. .h - class definition data members function prototypes .cpp - class implementation

HW: Define a Class for the SpreadSheet We are designing a spreadsheet program. Users can input numbers, strings, and expressions in each cell. Users can move the cursor with arrow keys UP, DOWN, LEFT, RIGHT. Alt-Q will quit the program.

Define the CCell Class in “cell.h” To save your time, you can download the main program and the constant.h file. All you need to do is design a class CCell, save it in “cell.h”, and integrate these three files to generate an executable program. Submit your “cell.h”

Requirements for CCell To make it easy, let’s start with all data members public. Each cell has a data member m_Expression to store the expression.  You may declare it as a character array containing MAX_EXPR_LEN bytes. A cell also has two data member "row" and "column" to indicate its location.  As the convention in C++, the index starts from 0. For convenience, we also create a data member m_Coordination, which stores the text representation of the location of each cell.  For example cell(0,0) is A1, cell(1,0) is A2, cell(0, 2) is C1. Don't forget to supply a constructor of this class.

春望 ~杜甫 國破山河在,城春草木深。 感時花濺淚,恨別鳥驚心。 烽火連三月,家書抵萬金。 白頭搔更短,渾欲不勝簪。

程式設計課程 核心能力 與 課程地圖

暨大資工系 教育目標 產業需求 實作能力 研發潛能 理論能力 人的本質 自己以外

暨大資工系 核心能力 基礎數理 理論 程式設計 軟體 電子元件 硬體 英文能力 團隊合作 生命品格

暨大資工系 課程地圖(部分) 全校共同課程14學分 通識領域課程17學分 專業選修 >= 32學分 未來發展(職涯)

暨大科技學院 核心能力 1.專業知識與實務技能 2.創新與獨立思考能力 3.溝通表達與團隊合作精神 4.專業倫理與社會責任認知 暨大科技學院 核心能力 1.專業知識與實務技能 2.創新與獨立思考能力 3.溝通表達與團隊合作精神 4.專業倫理與社會責任認知 5.掌握國際趨勢與全球視野

暨大學生 八大基本素養與核心能力 ﹙一﹚道德思辨與實踐能力 ﹙二﹚人際溝通與表達能力 ﹙三﹚獨立思考與創新能力 ﹙四﹚人文關懷與藝術涵養 ﹙五﹚專業知能與數位能力 ﹙六﹚團隊合作與樂業倫理 ﹙七﹚全球視野與尊重多元文化 ﹙八﹚社區參與與公民責任

資訊科技‧實現創意 暨大資工‧創意先鋒 資訊科技 ‧ 實現創意 ‧ 暨大資工 ‧ 創意先鋒

Chapter 8 (Part 3) Native C++ Library Classes for Strings (P.510)

String Concatenation Good afternoon. Bob. Good afternoon. Charlie. #include <iostream> using std::cout; int main() { char a[] = "Good afternoon. "; char b[] = "Bob. "; char c[] = "Charlie. "; char newline[] = "\n"; char str[80] = ""; strcpy(str, a); strcat(str, b); strcat(str, newline); strcat(str, a); strcat(str, c); cout << str; return 0; } Good afternoon. Bob. Good afternoon. Charlie.

Powerful C++ Class #include <iostream> #include <string> using std::cout; using std::string; int main() { string a = "Good afternoon. "; string b = "Bob. "; string c = "Charlie. "; string newline = "\n"; string str; str = a + b+ newline + a + c + newline; cout << str; return 0; }

Strings C language only has null-terminated strings which is stored as character arrays. char name[5] = "Mary"; C++ provides a string data type which is much easier to use. The class provides a bunch of powerful functions.

Creating String Objects string sentence = "This sentence is false."; string sentence("This sentence is false."); string bees(7, 'b'); string bees("bbbbbbb"); string letters(bees); string part(sentence, 5, 11); string part("sentence is"); the first character is at index position 0 string names[] = { "Alice", "Bob" }; string arrays

Input a string Read a character string into a string object: string sentence; cin >> sentence; However, cin will ignores leading whitespaces, and also terminates input when you enter a space, so for the input “This is a book”, only “This” is read into the object. Use the getline() function: getline(cin, sentence); ifstream fsIn("abc.txt"); getline(fsIn, sentence); the source of the input the destination for the input

Concatenating Strings Use the + operator to concatenate two string objects or a string object and a string literal. #include <iostream> #include <string> using std::cout; using std::endl; using std::string; int main() { string sentence1 = "This"; string sentence2 = "That"; string combined = sentence1 + "\n" + sentence2; cout << combined << endl; return 0; } This That

Concatenating Strings (2) You can also use the + operator to join a character to a string object sentence = sentence + '\n'; sentence += '\n'; sentence += "\n"; Length of a string sentence.length() // returns an integer sentence.empty() // returns true or false Ex8_12.cpp (P.513) size_t is defined using typedef statement to be equivalent to unsigned int. (P.190)

Accessing Strings Access a character in a string string sentence("Too many cooks spil the broth."); for (int i = 0; i < sentence.length(); i++) { if (' ' == sentence[i]) sentence[i] = '*'; } Use the at() member function if (' ' == sentence.at(i)) sentence.at(i) = '*'; Subscripting is faster, but the validity of the index is not checked.

Access a substring in a string Extract a part of an existing string object as a new string object. string sentence("Too many cooks spoil the broth."); string w = sentence.substr(4,10); // Extracts "many cooks"

Modifying Strings (1) Add one or more characters to the end of a string. string phrase("The higher"); string word("fewer"); phrase.append(1, ' '); // Append one space phrase.append("the "); // Append a string literal phrase.append(word); // Append a string object phrase.append(2, '!');// Append two exclamation marks When you call append(), the function returns a reference to the object, so you could write the above calls in a single statement: phrase.append(1, ' ').append("the ").append(word).append(2, '!');

Modifying Strings (2) Insert a string in the interior of another string: (P.517) string word("ABCDEF"); string test("==="); word.insert(3, test); // word will become "ABC===DEF" Swap the contents of two string objects: string phrase("The more the merrier."); string query("Any"); query.swap(phrase);

Modifying Strings (3) Replace part of a string object string text("ABCDEF"); text.replace(2, 3, "->"); text will become “AB->F” Replacement with a null string will essentially delete that part. text = "AB->F"; text.replace(2, 2, ""); text will become “ABF”

Comparing Strings Operator overloading has been implemented for == != < <= > >= When two corresponding characters are compared, their ASCII codes determine which one is less than the other. “USA” < “unique” If no character pairs are found to be different, the string with fewer characters is less. “book” < “books”

Ex8_13.cpp in main(): string* sort(string* strings, size_t count) nstrings: # of input strings maxwidth: maximum length of input strings string* sort(string* strings, size_t count) Actually the return type can be void in this example.

Search Strings Four versions of the find() function: string phrase("So near and yet so far"); string str("So near"); cout << phrase.find(str) << endl; // Outputs 0 (starting position) cout << phrase.find("so far") << endl; // Outputs 16 cout << phrase.find("so near") << endl; // Outputs string::npos = 4294967295 The function returns the value string::npos if the item was not found. The value of string::npos may vary with different C++ compilers, so you should always use string::npos and not the explicit value.

Search Strings (2) Searching from a specified position: string phrase("ABCDEABCDEABCDE"); cout << phrase.find("A"); // Outputs 0 cout << phrase.find("A", 3); // Outputs 5 cout << phrase.find("A", 11); // Outputs string::npos = 4294967295

Exercise Each line in "/home/solomon/horse.txt" contain the information in the format: Horse2 wins Horse1 wins Write a program to calculate how many times each horse wins? Horse1 wins 5 times Horse2 wins 6 times

Exercise Use the find() function to design an occurrence function, which will count the number of occurrences of a string in a text. int occurrence(string text, string str); Try to use a long text to test your function. Modify your function so that it is case-insensitive (i.e., both “ABC” and “aBc” matches “abc”).

Homework The sample code of Ex8_14.cpp does not generate the expected result. Try to find out the bug and fix it.

File I/O

Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk); is permanent; can be used to provide input data to a program or receive output data from a program, or both; must reside in Project directory (not necessarily the same directory as the .cpp files) must be opened before it is used.

C Functions for File I/O In function-oriented programming, we use the following functions to access disk files: fopen() fclose() fread() fwrite() fprintf() In object-oriented programming, we use a well-prepared class “fstream”.

C++ Classes for Input / Output stream - a sequence of characters interactive (iostream)  cin - input stream associated with keyboard.  cout - output stream associated with display. file (fstream)  ifstream - defines new input stream (normally associated with a file).  ofstream - defines new output stream (normally associated with a file).

Input File-Related Functions #include <fstream> ifstream fsIn; fsIn.open("fname.txt") connects stream fsIn to the external file "fname.txt". fsIn >> c; //Behaves just like cin fsIn.close() disconnects the stream and associated file.

Output File-Related Functions #include <fstream> ofstream fsOut; fsOut.open("fname.txt") connects stream fsOut to the external file "fname.txt". fsOut << c; //Behaves just like cout fsOut.close() disconnects the stream and associated file.

Example 1 #include <iostream> #include <fstream> using namespace std; int main() { char FirstName[30], LastName[30]; int Age; char FileName[20]; cout << "Enter First Name: "; cin >> FirstName; cout << "Enter Last Name: "; cin >> LastName; cout << "Enter Age: "; cin >> Age; cout << "\nEnter the name of the file you want to create: "; cin >> FileName; ofstream Students(FileName, ios::out); Students << FirstName << "\n" << LastName << "\n" << Age; cout << "\n\n"; return 0; } The file will be created in the directory where your “.cpp” file resides. e.g. “D:\VisualStudio2010\Projects\YourProject\YourProject”

Example 2 #include <iostream> #include <fstream> using std::cin; using std::cout; using std::ofstream; int main() { char FirstName[30], LastName[30]; int Age; char FileName[20]; cout << "Enter First Name: "; cin >> FirstName; cout << "Enter Last Name: "; cin >> LastName; cout << "Enter Age: "; cin >> Age; cout << "\nEnter the name of the file you want to create: "; cin >> FileName; ofstream Students(FileName); Students << FirstName << "\n" << LastName << "\n" << Age; Students.close(); return 0; }

Example 3: Output to a File #include <fstream> #include <iostream> using std::cout; using std::endl; using std::ofstream; int main() { ofstream Student("message.txt"); Student << "HELLO\n"; Student << "HI\n"; return 0; }

Example 4 #include <iostream> #include <fstream> using std::cin; using std::cout; using std::ifstream; int main() { char FirstName[30], LastName[30]; int Age; char FileName[20]; cout << "Enter the name of the file you want to open: "; cin >> FileName; ifstream Students(FileName); Students >> FirstName >> LastName >> Age; Students.close(); cout << "\nFirst Name: " << FirstName; cout << "\nLast Name: " << LastName; cout << "\nEnter Age: " << Age; cout << "\n\n"; return 0; }

Exercise: ifstream There are 100 lines in "/home/solomon/data.txt".  There is exact one integer in a line. Write a program and use the "ifstream" class to read data from this file. Calculate the sum and average of these numbers. Extend your program to handle unlimited number of lines with the following indefinite loop: while (fsIn >> n) { sum += n; count++; }

Exercise Download a text file containing the list members of CS101. Write a C++ program which reads the 137 entries from this file and sort them in alphabetical order. Some students registers twice with different email accounts. Write a program to find out these students. For example, s100321002@mail1.ncnu.edu.tw s100321002@ncnu.edu.tw