Microsoft PowerPoint - 12_StreamIO.ppt

Size: px
Start display at page:

Download "Microsoft PowerPoint - 12_StreamIO.ppt"

Transcription

1 1 第 12 章 C++ Stream Input/Output 12.1 簡介 12.2 串流 (Streams) 12.3 輸出串流 (Stream output) 12.4 輸入串流 (Stream output) 12.5 未格式化 I/O 12.6 串流操作器 12.7 串流格式設定 12.8 串流錯誤狀態處理 12.9 結合輸入 / 輸出串流

2 2 一般 I/O 特色 C++ I/O 物件導向 12.1 簡介 參考, 函式多載, 運算子多載 型態安全 (Type safe) I/O 敏感資料型態 如果型態不合會發生錯誤 使用者定義及標準型態 使 C++ 更具可擴充性

3 3 Stream: 位元組序列 12.2 串流 (Streams) 輸入 : 由輸入裝置 ( 鍵盤, 硬碟 ) 到記憶體 輸出 : 由記憶體到裝置 ( 螢幕, 印表機等 ) I/O 運作通常很花時間 例如 : 等待硬碟或鍵盤輸入 低階 I/O 未格式化 ( 不方便使用 ) 一個位元組一個位元組傳送 高速, 大量傳輸

4 串流 (Streams) 高階 I/O 格式化 位元組群 ( 整數, 字串等 ) 較適合使用

5 5 一般串流與標準串流 一般串流 輸入 / 輸出 chars ( 一個位元組 ) 字元數目有限 (ASCII) 標準串流函式庫 12.2 串流 (Streams) 大部份語言需要特殊文字 Unicode 支援多種文字 資料型態 :wchar_t 輸入 / 輸出可使用 unicode

6 6 iostream 函式庫 12.2 串流 (Streams) 提供多個標頭檔, 具數百種 I/O 存取能力 引用 <iostream.h> 標準輸入 (cin) 標準輸出 (cout) 不經緩衝的錯誤訊息輸出 (cerr) 經緩衝的錯誤訊息輸出 (clog)

7 串流 (Streams) <iomanip.h> 使用串流操作子 (stream manipulators) 設定輸入輸出格式 <fstream.h> 檔案處理相關功能

8 8 iostream 函式庫 12.2 串流 (Streams) 提供 I/O 類別樣版 basic_istream ( 串流輸入 ) basic_ostream ( 串流輸出 ) basic_iostream ( 串流輸入與輸出 ) 可供輸入輸出字元

9 串流 (Streams) 衍生自 basic_ios 的樣版 basic_ios basic_istream basic_ostream basic_iostream

10 10 使用 typedef 定義多個別名 istream ostream iostream typedef 用法 12.2 串流 (Streams) typedef Card * CardPtr; CardPtr 變成 Card * 的別名

11 11 << 與 >> 運算子 cin 12.2 串流 (Streams) 串流輸入與輸出運算子 是一種 istream 物件 連接到標準輸入 ( 通常是鍵盤 ) cin >> grade; 編譯器確認 grade 資料型態 呼叫適當的多載運算子 不需提供額外的型態資訊

12 12 cout 12.2 串流 (Streams) 是一種 ostream 物件 標準輸出 ( 通常顯示在螢幕上 ) cout << grade; 編譯器確認 grade 資料型態 呼叫適當的多載運算子 不需提供額外的型態資訊

13 13 cerr, clog 12.2 串流 (Streams) 是一種 ostream 物件 連接到標準錯誤裝置 cerr 會立即輸出 clog 會存入輸出緩衝區 若緩衝區滿, 則輸出 有效能上的好處

14 14 C++ 檔案處理方式類似 類別樣版 12.2 串流 (Streams) basic_ifstream ( 檔案輸入 ) basic_ofstream( 檔案輸出 ) basic_fstream( 檔案 I/O) 允許由檔案輸入輸出字元

15 15 樣版階層 12.2 串流 (Streams) basic_ios basic_istream basic_ostream basic_ifstream basic_iostream basic_ofstream basic_fstream

16 串流 (Streams) 使用 typedef 定義多個別名 ifstream ofstream fstream

17 17 輸出 使用 ostream 格式化與非格式化 標準資料型態 (<<) 字元 整數 put 函式 12.3 輸出串流 十進位 (decimal) 八進位 (octal) 十六進位 (hexadecimal)

18 輸出串流 浮點數 不同精確度 強制小數點出現 科學表示 對齊方式 附加資料 大小寫控制

19 19 C++ 會自動確定資料型態 比 C 語言好 可能問題 如果要印出一個 char * 的記憶體位址 則會印出整個字串 解決方法 : 轉型成 void * 以 16 進位方式列印 12.3 輸出串流

20 1 // Fig. 12.3: fig12_03.cpp 2 // 印出 char * 變數的記憶體位址 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 8 int main() 9 { 10 char *word = "test"; // 顯示 char * 變數所指到字串的值, 然後顯示 char * 變數的值 13 // 靜態轉型到 void * 14 cout << "Value of word is: " << word << endl 15 << "Value of static_cast< void * >( word ) is: " 16 << static_cast< void * >( word ) << endl; return 0; } // end main fig12_03.cpp (1 of 1) fig12_03.cpp output (1 of 1) 20 Value of word is: test Value of static_cast< void *>( word ) is: 0046C Prentice Hall, Inc. All rights reserved.

21 21 put 函式 輸出字元 cout.put( 'A' ); 可串接 cout.put( 'A' ).put( '\n' ); 點運算子 (.) 由左至右執行 可使用 ASCII 數值 cout.put( 65 ); 印出 'A' 12.3 輸出串流

22 輸入串流 格式化與非格式化輸入 istream >> 運算子 通常會忽略空白字元 (blanks, tabs, newlines) 可改變 沒東西讀 (EOF) 會傳回 0 否則傳回物件的參考 (reference) cin >> grade 假如有錯會設定相對的狀態值 (12.7,12.8)

23 輸入串流 get 函式 cin.get() 由輸入串流傳回一個字元 ( 含空白字元 ) 假如已經讀到檔案結尾則傳回 EOF 檔案結尾 EOF(End-of-file) 表示輸入內容已被讀完 ctrl-z on IBM-PCs ctrl-d on UNIX and Macs cin.eof() 如果已至檔案結尾傳回 1 否則傳回 0

24 1 // Fig. 12.4: fig12_04.cpp 2 // 使用輸入串流 (input stream) 成員函式 :get,put 與 eof. 3 #include <iostream> 4 5 using std::cout; 6 using std::cin; 7 using std::endl; 8 9 int main() 10 { 11 int character; // 使用 int 因為字元不能表示 EOF // 印出目前 eof 狀態 ; 提示使用者輸入一行文字 14 cout << "Before input, cin.eof() is " << cin.eof() << endl 15 << "Enter a sentence followed by end-of-file:" << endl; // 使用 get 函式讀取每個字元 ; 使用 put 函式顯示字元 18 while ( ( character = cin.get() )!= EOF ) 19 cout.put( character ); // 顯示 EOF 字元 22 cout << "\neof in this system is: " << character << endl; 23 cout << "After input, cin.eof() is " << cin.eof() << endl; return 0; } // end main fig12_04.cpp 2003 Prentice Hall, Inc. All rights reserved. 24

25 Before input, cin.eof() is 0 Enter a sentence followed by end-of-file: Testing the get and put member functions Testing the get and put member functions ^Z fig12_04.cpp output 25 EOF in this system is: -1 After input cin.eof() is Prentice Hall, Inc. All rights reserved.

26 26 get(charref) 利用傳參考方式 取得一個字元, 放入 charref 假如 EOF, 傳回 -1 get(chararray, size, delimiter) 一次讀取 size-1 個字元, 或直到遇到邊界符號 (delimiter), 陣列後面以 \0 結尾 預設邊界符號為 '\n' 邊界符號仍會留在輸入串流中 12.4 輸入串流 可用 cin.get() 或 cin.ignore() 移除邊界符號

27 1 // Fig. 12.5: fig12_05.cpp 2 // 使用輸入串流成員函式 cin.get. 3 #include <iostream> 4 5 using std::cout; 6 using std::cin; 7 using std::endl; 8 9 int main() 10 { 11 // 產生兩個字元陣列, 每個陣列可放 80 個元素 ( 最多 79 字元 ) 12 const int SIZE = 80; 13 char buffer1[ SIZE ]; 14 char buffer2[ SIZE ]; // 使用 cin 輸入字串至 buffer1 17 cout << "Enter a sentence:" << endl; 18 cin >> buffer1; // 顯示 buffer1 內容 21 cout << "\nthe string read with cin was:" << endl 22 << buffer1 << endl << endl; // 使用 cin.get 輸入字串至 buffer2 25 cin.get( buffer2, SIZE ); // 顯示 buffer2 內容 28 cout << "The string read with cin.get was:" << endl 29 << buffer2 << endl; return 0; } // end main fig12_05.cpp 2003 Prentice Hall, Inc. All rights reserved. 27

28 Enter a sentence: Contrasting string input with cin and cin.get The string read with cin was: Contrasting fig12_05.cpp output 28 The string read with cin.get was: string input with cin and cin.get 2003 Prentice Hall, Inc. All rights reserved.

29 29 getline(array, size, delimiter) 跟 get 一樣 一次讀取 size-1 個字元, 或直到遇到邊界符號 (delimiter), 陣列後面以 \0 結尾 預設邊界符號為 '\n' 12.4 輸入串流 會將邊界符號從輸入串流中去除

30 1 // Fig. 12.6: fig12_06.cpp 2 // 使用 cin 的成員函式 getline 輸入字串 3 #include <iostream> 4 5 using std::cout; 6 using std::cin; 7 using std::endl; 8 9 int main() 10 { 11 const int SIZE = 80; 12 char buffer[ SIZE ]; // 產生字元陣列 // 利用 cin 的 getline 函式輸入字串 15 cout << "Enter a sentence:" << endl; 16 cin.getline( buffer, SIZE ); // 顯示字串內容 19 cout << "\nthe sentence entered is:\n" << buffer << endl; return 0; } // end main fig12_06.cpp Prentice Hall, Inc. All rights reserved.

31 Enter a sentence: Using the getline member function The sentence entered is: Using the getline member function fig12_06.cpp output Prentice Hall, Inc. All rights reserved.

32 32 ignore(num) 忽略輸入串流中的字元, num 預設值是 1 直到遇到邊界符號 (delimiter) 預設邊界符號是 EOF putback() 將字元放入輸入串流中 peek() 12.4 輸入串流 傳回輸入串流中的字元, 但不移除該字元

33 33 型態安全 I/O << 與 >> 運算子 已被多載可接受特定資料型態 假如遇到不正確的資料型態 設定錯誤位元 (Error bits) 使用者可測試錯誤位元看是否發生 I/O 錯誤 在 12.8 節介紹 12.4 輸入串流

34 未格式化 I/O 未格式化 I/O read (istream 的成員函式 ) 輸入新的位元組到字元陣列 - 不會自動加 \0 假如所讀取的字元數不夠 - 設定 failbit gcount() 傳回上次讀取的位元組數 write (ostream 的成員函式 ) 由字元陣列輸出多個位元組, 或遇到 \0 字元 char buffer[] = "HAPPY BIRTHDAY"; cout.write( buffer, 10 ); 輸出 10 個字元 "HAPPY BIRT"

35 1 // Fig. 12.7: fig12_07.cpp 2 // 使用 read, gcount 與 write 函式進行未格式化 I/O. 3 #include <iostream> 4 5 using std::cout; 6 using std::cin; 7 using std::endl; 8 9 int main() 10 { 11 const int SIZE = 80; 12 char buffer[ SIZE ]; // 產生 80 個字元陣列 // 使用函式 read 輸入多個字元 15 cout << "Enter a sentence:" << endl; 16 cin.read( buffer, 20 ); // 使用函式 write 及 gcount 顯示陣列中的字元 19 cout << endl << "The sentence entered was:" << endl; 20 cout.write( buffer, cin.gcount() ); 21 cout << endl; return 0; } // end main fig12_07.cpp 2003 Prentice Hall, Inc. All rights reserved. 35

36 Enter a sentence: Using the read, write, and gcount member functions The sentence entered was: Using the read, writ fig12_07.cpp output Prentice Hall, Inc. All rights reserved.

37 串流操作子 串流操作子 (manipulator) 可設定串流格式 #include <iomanip> 欄位長度 精確度 格式旗號 (Flags) 填滿字元 清空串流 在輸出串流插入換行符號 在輸入串流跳過空白字元

38 38 設定整數數字系統 12.6 串流操作子 串流操作子可改變整數數字系統 dec: 10 進位 ( 預設值 ) hex : 16 進位 oct: 8 進位 用法 : cout << hex << myinteger setbase(newbase) newbase : 8, 10, 或 16 用法 : cout << setbase(8) << myinteger 數字系統設定後會一直維持, 直到重新設定

39 1 // Fig. 12.8: fig12_08.cpp 2 // 使用串流操作子 :hex, oct, dec, setbase. 3 #include <iostream> 4 5 using std::cout; 6 using std::cin; 7 using std::endl; 8 using std::hex; 9 using std::dec; 10 using std::oct; #include <iomanip> using std::setbase; int main() 17 { 18 int number; cout << "Enter a decimal number: "; 21 cin >> number; // input number // 使用 hex 串流操作子顯示 16 進位數字 24 cout << number << " in hexadecimal is: " << hex 25 << number << endl; fig12_08.cpp (1 of 2) 2003 Prentice Hall, Inc. All rights reserved. 39

40 26 27 // 使用 dec 與 oct 串流操作子顯示 10 與 8 進位數字 28 cout << dec << number << " in octal is: " 29 << oct << number << endl; // 使用 setbase 串流操作子顯示 10 進位數字 32 cout << setbase( 10 ) << number << " in decimal is: " 33 << number << endl; return 0; } // end main fig12_08.cpp (2 of 2) fig12_08.cpp output (1 of 1) 40 Enter a decimal number: in hexadecimal is: in octal is: in decimal is: Prentice Hall, Inc. All rights reserved.

41 41 浮點數表示法 fixed 12.6 串流操作子 double value1= ; cout << value1 << endl; 結果 : scientific double value1= ; cout << value1 << endl; 結果 : e+002

42 42 設定浮點數精確度 12.6 串流操作子 要在小數點右邊顯示幾位數字 使用 setprecision 操作子 cout << setprecision(5) 或使用 precision 成員函式 cout.precision(newprecision) 會傳回改變前的精確度設定 沒給參數的話, 會傳回目前的精確度

43 1 // Fig. 12.9: fig12_09.cpp 2 // 設定浮點數的精確度 3 #include <iostream> 4 5 using std::cout; 6 using std::cin; 7 using std::endl; 8 using std::fixed; 9 10 #include <iomanip> using std::setprecision; #include <cmath> // 要使用 sqrt 函式, 所以引用 cmath int main() 17 { 18 double root2 = sqrt( 2.0 ); // 計算 2 的開根號結果 19 int places; cout << "Square root of 2 with precisions 0-9." << endl 22 << "Precision set by ios_base member-function " 23 << "precision:" << endl; cout << fixed; // 使用定點表示法 fig12_09.cpp (1 of 2) 2003 Prentice Hall, Inc. All rights reserved. 43

44 26 27 // 顯示開根號結果 ; 使用 ios_base 函式精確度 28 for ( places = 0; places <= 9; places++ ) { 29 cout.precision( places ); 30 cout << root2 << endl; 31 } cout << "\nprecision set by stream-manipulator " 34 << "setprecision:" << endl; // 使用 setprecision 操作子設定每個數字的精確度 37 for ( places = 0; places <= 9; places++ ) 38 cout << setprecision( places ) << root2 << endl; return 0; } // end main fig12_09.cpp (2 of 2) Prentice Hall, Inc. All rights reserved.

45 Square root of 2 with precisions 0-9. Precision set by ios_base member-function precision: fig12_09.cpp output (1 of 1) 45 Precision set by stream-manipulator setprecision: Prentice Hall, Inc. All rights reserved.

46 46 設定欄位寬度 width 成員函式 ( 基礎類別 ios_base) cin.width(5) 設定欄位寬度 設定輸出時的顯示欄位寬度 設定輸入時最大應輸入長度 傳回原來寬度 12.6 串流操作子

47 47 設定欄位寬度 12.6 串流操作子 跟填滿字元函式一齊使用 輸出小於所設定寬度 也能使用 setw 操作子 用於讀取字串時, 必須留一個位置放 \0

48 1 // Fig : fig12_10.cpp 2 // 展示成員函式 width 用法 3 #include <iostream> 4 5 using std::cout; 6 using std::cin; 7 using std::endl; 8 9 int main() 10 { 11 int widthvalue = 4; 12 char sentence[ 10 ]; cout << "Enter a sentence:" << endl; 15 cin.width( 5 ); // 設定 cin 的寬度為 5, 輸入 4 個字元 // 設定 cout 欄位寬度, 並依欄位寬度顯示 18 while ( cin >> sentence ) { 19 cout.width( widthvalue++ ); 20 cout << sentence << endl; 21 cin.width( 5 ); // 取得 4 個輸入字元 22 } // end while return 0; } // end main fig12_10.cpp 2003 Prentice Hall, Inc. All rights reserved. 48

49 Enter a sentence: This is a test of the width member function This is a test of the widt h memb er func tion fig12_10.cpp output (1 of 1) Prentice Hall, Inc. All rights reserved.

50 50 使用者可以自訂串流操作子 沒有參數 例如 ostream& bell( ostream& output ) { return output << '\a'; // 讓喇叭叫一聲 } \a -bell 12.6 串流操作子

51 1 // Fig : fig12_11.cpp 2 // 測試使用者自訂, 無參數的串流操作子 3 // 4 #include <iostream> 5 6 using std::ostream; 7 using std::cout; 8 using std::flush; 9 10 // bell 操作子 ( 使用 \a) 11 ostream& bell( ostream& output ) 12 { 13 return output << '\a'; // 命今系統叫一聲 14 } // carriagereturn 操作子 ( 使用 \r) 17 ostream& carriagereturn( ostream& output ) 18 { 19 return output << '\r'; // 回到目前這行開頭處 20 } // tab 操作子 ( 使用 \t) 23 ostream& tab( ostream& output ) 24 { 25 return output << '\t'; // tab 26 } 27 fig12_11.cpp (1 of 2) 2003 Prentice Hall, Inc. All rights reserved. 51

52 28 // endline 操作子 ( 使用 \n 與成員函式 flush) 29 // flush 可命令輸出內容馬上輸出 30 ostream& endline( ostream& output ) 31 { 32 return output << '\n' << flush; 33 } int main() 36 { 37 // 使用 tab 與 endline 操作子 38 cout << "Testing the tab manipulator:" << endline 39 << 'a' << tab << 'b' << tab << 'c' << endline; cout << "Testing the carriagereturn and bell manipulators:" 42 << endline << "..."; cout << bell; // 使用 bell 操作子 // 使用 carriagereturn 及 endline 操作子 47 cout << carriagereturn << "-----" << endline; return 0; } // end main fig12_11.cpp (2 of 2) 52 Testing the tab manipulator: a b c Testing the carriagereturn and bell manipulators: Prentice Hall, Inc. All rights reserved.

53 串流格式設定 許多串流操作子可用來設定輸出格式 全部繼承自 ios_base

54 54 showpoint 強制印出小數點及數字後面的 0 例如 : 一個十進位數字 79.0 沒有使用 showpoint 印出 79 使用 showpoint 可能印出 印多少 0 視準確度而定 noshowpoint 12.7 串流格式設定 取消 showpoint 設定

55 1 // Fig : fig12_13.cpp 2 // 使用 showpoint 控制要不要印出數字後面的 0 及小數點 3 // 4 #include <iostream> 5 6 using std::cout; 7 using std::endl; 8 using std::showpoint; 9 10 int main() 11 { 12 // 使用預設的格式顯示浮點數 13 cout << "Before using showpoint" << endl 14 << " prints as: " << << endl 15 << " prints as: " << << endl 16 << " prints as: " << << endl << endl; // 設定 showpoint 後的結果 19 cout << showpoint 20 << "After using showpoint" << endl 21 << " prints as: " << << endl 22 << " prints as: " << << endl 23 << " prints as: " << << endl; return 0; } // end main fig12_13.cpp 2003 Prentice Hall, Inc. All rights reserved. 55

56 Before using showpoint prints as: prints as: prints as: 9 After using showpoint prints as: prints as: prints as: fig12_13.cpp output Prentice Hall, Inc. All rights reserved.

57 57 對齊方式 與 width 寬度有關 left: 靠左對齊 Right: 靠右對齊 internal 12.7 串流格式設定 正負號符號靠左, 數字靠右 showpos 強制印出正負號 noshowpos: 取消 showpos 功能

58 1 // Fig : fig12_14.cpp 2 // left 與 right 操作子使用範例 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 using std::left; 8 using std::right; 9 10 #include <iomanip> using std::setw; int main() 15 { 16 int x = 12345; // 以靠右對齊方式顯示 x ( 預設值 ) 19 cout << "Default is right justified:" << endl 20 << setw( 10 ) << x; // 以靠左對齊方式顯示 x 23 cout << "\n\nuse std::left to left justify x:\n" 24 << left << setw( 10 ) << x; 25 fig12_14.cpp (1 of 2) 2003 Prentice Hall, Inc. All rights reserved. 58

59 26 // 以靠右對齊方式顯示 x 27 cout << "\n\nuse std::right to right justify x:\n" 28 << right << setw( 10 ) << x << endl; return 0; } // end main Default is right justified: fig12_14.cpp (2 of 2) fig12_14.cpp output 59 Use std::left to left justify x: Use std::right to right justify x: Prentice Hall, Inc. All rights reserved.

60 1 // Fig : fig12_15.cpp 2 // internal 使用範例 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 using std::internal; 8 using std::showpos; 9 10 #include <iomanip> using std::setw; int main() 15 { 16 // 使用 internal 方式顯示數字 cout << internal << showpos << setw( 10 ) << 123 << endl; return 0; } // end main fig12_15.cpp fig12_15.cpp output Prentice Hall, Inc. All rights reserved.

61 61 顯示數字系統 12.7 串流格式設定 showbase noshowbase: 取消顯示基底功能 8 進位有前導 0 16 進位前導 0x 或 0X

62 62 填充 (Padding) 可將所設定寬度中空白處以填充字元填滿 設定填充字元 12.7 串流格式設定 fill 成員函式 :cout.fill('*') setfill 串流操作子 :setfill( '^' )

63 1 // Fig : fig12_16.cpp 2 // 使用成員函式 fill 與串流操作子 setfill 改變填充字元 #include <iostream> 6 7 using std::cout; 8 using std::endl; 9 using std::showbase; 10 using std::left; 11 using std::right; 12 using std::internal; 13 using std::hex; 14 using std::dec; #include <iomanip> using std::setw; 19 using std::setfill; int main() 22 { 23 int x = 10000; // 顯示 x 26 cout << x << " printed as int right and left justified\n" 27 << "and as hex with internal justification.\n" 28 << "Using the default pad character (space):" << endl; 29 fig12_16.cpp (1 of 2) 2003 Prentice Hall, Inc. All rights reserved. 63

64 30 // 設定 showbase 顯示基底符號, 及設定欄位寬度 31 cout << showbase << setw( 10 ) << x << endl; // 靠左對齊, 顯示 x 34 cout << left << setw( 10 ) << x << endl; // 設定 16 進位顯示, 以 internal 方式顯示 x 37 cout << internal << setw( 10 ) << hex << x << endl << endl; cout << "Using various padding characters:" << endl; // 靠右對齊, 使用填充字元 '*', 顯示 x 42 cout << right; 43 cout.fill( '*' ); 44 cout << setw( 10 ) << dec << x << endl; // 靠左對齊, 使用填充字元 %, 顯示 x 47 cout << left << setw( 10 ) << setfill( '%' ) << x << endl; // internal 對齊, 使用填充字元 ^, 顯示 x 50 cout << internal << setw( 10 ) << setfill( '^' ) << hex 51 << x << endl; return 0; } // end main fig12_16.cpp (2 of 2) 2003 Prentice Hall, Inc. All rights reserved. 64

65 10000 printed as int right and left justified and as hex with internal justification. Using the default pad character (space): x 2710 fig12_16.cpp output 65 Using various padding characters: ***** %%%%% 0x^^^^ Prentice Hall, Inc. All rights reserved.

66 1 // Fig : fig12_17.cpp 2 // 使用 showbase 串流操作子 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 using std::showbase; 8 using std::oct; 9 using std::hex; int main() 12 { 13 int x = 100; // 使用 showbase 顯示數字系統 16 cout << "Printing integers preceded by their base:" << endl 17 << showbase; cout << x << endl; // 以 10 進位方式列印數字 20 cout << oct << x << endl; // 以 8 進位方式列印數字 21 cout << hex << x << endl; // 以 16 進位方式列印數字 return 0; } // end main fig12_17.cpp 66 Printing integers preceded by their base: x Prentice Hall, Inc. All rights reserved.

67 67 scientific 串流操作子 Forces scientific notation e+009 fixed 串流操作子 使用定點格式 如果沒有指定 12.7 串流格式設定 數字的內容決定使用哪種方式

68 1 // Fig : fig12_18.cpp 2 // 顯示浮點數 : 使用系統預設值, scientific, fixed 3 // 4 #include <iostream> 5 6 using std::cout; 7 using std::endl; 8 using std::scientific; 9 using std::fixed; int main() 12 { 13 double x = ; 14 double y = 1.946e9; // 使用預設方式顯示 x 與 y 17 cout << "Displayed in default format:" << endl 18 << x << '\t' << y << endl; // 使用 scientific 方式顯示 x 與 y 21 cout << "\ndisplayed in scientific format:" << endl 22 << scientific << x << '\t' << y << endl; // 使用 fixed 方式顯示 x 與 y 25 cout << "\ndisplayed in fixed format:" << endl 26 << fixed << x << '\t' << y << endl; return 0; } // end main fig12_18.cpp 2003 Prentice Hall, Inc. All rights reserved. 68

69 Displayed in default format: e+009 Displayed in scientific format: e e+009 fig12_18.cpp output 69 Displayed in fixed format: Prentice Hall, Inc. All rights reserved.

70 70 大小寫控制 uppercase 串流操作子 使用大寫方式表示科學記號表示法 1E10 使用大寫方式表示 16 進位表示法 0XABCD 12.7 串流格式設定 預設值是小寫 (lowercase) nouppercase: 清除設定

71 1 // Fig : fig12_19.cpp 2 // uppercase 串流操作子 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 using std::uppercase; 8 using std::hex; 9 10 int main() 11 { 12 cout << "Printing uppercase letters in scientific" << endl 13 << "notation exponents and hexadecimal values:" << endl; // 使用 uppercase 顯示大寫字元 16 // 使用 hex 以 16 進位方式顯示數值 17 cout << uppercase << 4.345e10 << endl << hex << << endl; return 0; } // end main fig12_19.cpp 71 Printing uppercase letters in scientific notation exponents and hexadecimal values: 4.345E BCD Prentice Hall, Inc. All rights reserved.

72 72 資料型態 bool 值 true 或 false 使用 << 輸出 true: 輸出 0 false: 輸出 串流格式設定 boolalpha 串流操作子 顯示字串 "true" 及 "false" noboolalpha: 清除設定

73 1 // Fig : fig12_20.cpp 2 // boolalpha 與 noboolalpha 串流操作子使用範例 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 using std::cin; 8 using std::boolalpha; 9 using std::noboolalpha; int main() 12 { 13 bool booleanvalue = true; // 使用預設方式顯示 booleanvalue 16 cout << "booleanvalue is " << booleanvalue << endl; // 使用 boolalpha 方式顯示 booleanvalue 19 cout << "booleanvalue (after using boolalpha) is " 20 << boolalpha << booleanvalue << endl << endl; cout << "switch booleanvalue and use noboolalpha" << endl; 23 booleanvalue = false; // 改變 booleanvalue 值 24 cout << noboolalpha << endl; // 使用 noboolalpha 25 fig12_20.cpp (1 of 2) 2003 Prentice Hall, Inc. All rights reserved. 73

74 26 // 顯示 booleanvalue 27 cout << "booleanvalue is " << booleanvalue << endl; // 使用 boolalpha 方式顯示 booleanvalue 30 cout << "booleanvalue (after using boolalpha) is " 31 << boolalpha << booleanvalue << endl; return 0; } // end main fig12_20.cpp (2 of 2) fig12_20.cpp output (1 of 1) 74 booleanvalue is 1 booleanvalue (after using boolalpha) is true switch booleanvalue and use noboolalpha booleanvalue is 0 booleanvalue (after using boolalpha) is false 2003 Prentice Hall, Inc. All rights reserved.

75 75 使用 flags 成員函式設定或重置格式設定 格式設定可以儲存與還原 例如 : 12.7 串流格式設定 呼叫函式前先儲存格式設定狀態 呼叫函式 結束函式呼叫後還原格式設定狀態

76 76 成員函式 flags cout.flags() 沒有參數 12.7 串流格式設定 傳回 fmtflags 物件 - 存放目前格式設定 Namespace ios_base fmtflags originalformat = cout.flags(); 使用 fmtflags 設定格式 還原格式設定 cout.flags(originalformat);

77 1 // Fig : fig12_21.cpp 2 // flags 成員函式使用範例 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 using std::oct; 8 using std::scientific; 9 using std::showbase; 10 using std::ios_base; int main() 13 { 14 int integervalue = 1000; 15 double doublevalue = ; // 使用預設格式 : 顯示 flags, integervalue 與 doublevalue 值 18 cout << "The value of the flags variable is: " << cout.flags() 19 << "\nprint int and double in original format:\n" 20 << integervalue << '\t' << doublevalue << endl << endl; // 使用 cout flags 函式存放目前格式 23 ios_base::fmtflags originalformat = cout.flags(); 24 cout << showbase << oct << scientific; // 改變格式 Prentice Hall, Inc. All rights reserved. 77 fig12_21.cpp (1 of 2)

78 26 // 使用新格式 : 顯示 flags, integervalue, 與 doublevalue 值 27 cout << "The value of the flags variable is: " << cout.flags() 28 << "\nprint int and double in a new format:\n" 29 << integervalue << '\t' << doublevalue << endl << endl; cout.flags( originalformat ); // 還原格式設定 // 使用原來格式 : 顯示 flags, integervalue, 與 doublevalue 值 34 cout << "The restored value of the flags variable is: " 35 << cout.flags() 36 << "\nprint values in original format again:\n" 37 << integervalue << '\t' << doublevalue << endl; return 0; } // end main 78 fig12_21.cpp (2 of 2) The value of the flags variable is: 513 Print int and double in original format: The value of the flags variable is: Print int and double in a new format: e-002 The restored value of the flags variable is: 513 Print values in original format again: Prentice Hall, Inc. All rights reserved.

79 串流錯誤狀態 使用位元測試串流狀態 eofbit:eof 成立時被設定 假如 eofbit 被設定, 傳回 true cin.eof() 傳回 eofbit 內容 failbit: 串流發生錯誤時被設定 如果資料沒丟掉, 錯誤可回復 cin.fail() 傳回 failbit 內容

80 串流錯誤狀態 badbit: 資料遺失時被設定 通常無法回復 cin.bad() 傳回 badbit 內容 goodbit:badbit, failbit 與 eofbit 都為 0 時被設定 cin.good() 傳回 badbit 內容

81 串流錯誤狀態 成員函式 rdstate() 傳回串流錯誤狀態 可供使用 goodbit, badbit 等測試 比使用 good(), bad() 好 clear() 清除錯誤狀態 設定串流至正常狀態, I/O 才可以繼續 也可用來設定錯誤狀態 cin.clear( ios::failbit ) 設定 failbit

82 1 // Fig : fig12_22.cpp 2 // 測試錯誤狀態 3 #include <iostream> 4 5 using std::cout; 6 using std::endl; 7 using std::cin; 8 9 int main() 10 { 11 int integervalue; // 顯示 cin 目前狀態 14 cout << "Before a bad input operation:" 15 << "\ncin.rdstate(): " << cin.rdstate() 16 << "\n cin.eof(): " << cin.eof() 17 << "\n cin.fail(): " << cin.fail() 18 << "\n cin.bad(): " << cin.bad() 19 << "\n cin.good(): " << cin.good() 20 << "\n\nexpects an integer, but enter a character: "; cin >> integervalue; // 輸入字元值 ; 格式不合, 會導致錯誤 23 cout << endl; 24 fig12_22.cpp (1 of 2) 2003 Prentice Hall, Inc. All rights reserved. 82

83 25 // 顯示 cin 目前狀態 26 cout << "After a bad input operation:" 27 << "\ncin.rdstate(): " << cin.rdstate() 28 << "\n cin.eof(): " << cin.eof() 29 << "\n cin.fail(): " << cin.fail() 30 << "\n cin.bad(): " << cin.bad() 31 << "\n cin.good(): " << cin.good() << endl << endl; cin.clear(); // 清除串流 // 顯示 cin 目前狀態 36 cout << "After cin.clear()" 37 << "\ncin.fail(): " << cin.fail() 38 << "\ncin.good(): " << cin.good() << endl; return 0; } // end main fig12_22.cpp (2 of 2) Prentice Hall, Inc. All rights reserved.

84 Before a bad input operation: cin.rdstate(): 0 cin.eof(): 0 cin.fail(): 0 cin.bad(): 0 cin.good(): 1 fig12_22.cpp output (1 of 1) 84 Expects an integer, but enter a character: A After a bad input operation: cin.rdstate(): 2 cin.eof(): 0 cin.fail(): 1 cin.bad(): 0 cin.good(): 0 After cin.clear() cin.fail(): 0 cin.good(): Prentice Hall, Inc. All rights reserved.

85 85 輸入格式錯誤 failbit 被設定 使用 cin.clear() 12.8 串流錯誤狀態 可清除錯誤狀態 沒有清除輸入串流內容 因為格式錯誤, 沒有被讀出來 還留在串流內 如果要讓程式繼續執行 需清除輸入串流內容 使用 cin.seekg(0,ios::end);

86 結合輸入 / 輸出串流 使用緩衝輸出的問題 互動問題 ( 提示使用者, 使用者回應 ) 提示必須在可供輸入之前出現 緩衝輸出只在緩衝區填滿或被更新時顯示 inputstream.tie( 0 )

87 87 成員函式 tie 12.9 結合輸入 / 輸出串流 可同步串流 輸出會在隨後出現的輸入動作前顯示 針對 cin 與 cout, 系統會自動做結合動作 cin.tie( &cout ) 其它串流則必須明確指定 解除結合 inputstream.tie( 0 )

IO

IO 1 C/C++ C FILE* fscanf fgets fread fprintf fputs fwrite C++ ifstream ofstream >>

More information

新版 明解C++入門編

新版 明解C++入門編 511!... 43, 85!=... 42 "... 118 " "... 337 " "... 8, 290 #... 71 #... 413 #define... 128, 236, 413 #endif... 412 #ifndef... 412 #if... 412 #include... 6, 337 #undef... 413 %... 23, 27 %=... 97 &... 243,

More information

C/C++ - 字符输入输出和字符确认

C/C++ - 字符输入输出和字符确认 C/C++ Table of contents 1. 2. getchar() putchar() 3. (Buffer) 4. 5. 6. 7. 8. 1 2 3 1 // pseudo code 2 read a character 3 while there is more input 4 increment character count 5 if a line has been read,

More information

Microsoft PowerPoint - CH02 Introduction to C++ Programming_輸入與輸出 [相容模式]

Microsoft PowerPoint - CH02 Introduction to C++ Programming_輸入與輸出 [相容模式] Ch2. Introduction to C++ Programming 輸入與輸出 標準 I/O 課程名稱 : 程式設計 Computer Programming 班級 : 資管一 Freshman, ISMS 任課教師 : 謝明哲 Hsieh, Ming-Che, Miller 單位職稱 : 台東大學資管系副教授 Associate Professor, ISMS, NTTU 電子郵件 :hmz@nttu.edu.tw

More information

C/C++语言 - C/C++数据

C/C++语言 - C/C++数据 C/C++ C/C++ Table of contents 1. 2. 3. 4. char 5. 1 C = 5 (F 32). 9 F C 2 1 // fal2cel. c: Convert Fah temperature to Cel temperature 2 # include < stdio.h> 3 int main ( void ) 4 { 5 float fah, cel ;

More information

C/C++程序设计 - 字符串与格式化输入/输出

C/C++程序设计 - 字符串与格式化输入/输出 C/C++ / Table of contents 1. 2. 3. 4. 1 i # include # include // density of human body : 1. 04 e3 kg / m ^3 # define DENSITY 1. 04 e3 int main ( void ) { float weight, volume ; int

More information

C++ 程式設計

C++ 程式設計 C C 料, 數, - 列 串 理 列 main 數串列 什 pointer) 數, 數, 數 數 省 不 不, 數 (1) 數, 不 數 * 料 * 數 int *int_ptr; char *ch_ptr; float *float_ptr; double *double_ptr; 數 (2) int i=3; int *ptr; ptr=&i; 1000 1012 ptr 數, 數 1004

More information

第八﹑九章 I/O系統

第八﹑九章 I/O系統 第八 九章 I/O 系統 檔案 I/O 的基本概念 格式化 I/O 建立自訂的嵌入子 建立自訂的擷取子 自訂 I/O 與檔案 檔案 I/O 的基本概念 C++ 對 I/O 的支援是放在 中, 而 Class ios 包括有許多成員函數與變數可以用來控制和監督串流的運作. 要處理檔案 I/O, 心必須 #include, 它包含了 ifstream,ofstream

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 49 [P.51] C/C++ [P.52] [P.53] [P.55] (int) [P.57] (float/double) [P.58] printf scanf [P.59] [P.61] ( / ) [P.62] (char) [P.65] : +-*/% [P.67] : = [P.68] : ,

More information

Microsoft PowerPoint - CPP-Ch Print.ppt [兼容模式]

Microsoft PowerPoint - CPP-Ch Print.ppt [兼容模式] Chapter 17 File Processing http://jssec.seu.edu.cn 杨明 yangming2002@seu.edu.cn OBJECTIVES To create, read, write and update files. Sequential file processing. Random-access file processing. To use high-performance

More information

C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1

C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1 C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 月 3 日 1 1 INPUTOUTPUT 1 InputOutput 题目描述 用 cin 输入你的姓名 ( 没有空格 ) 和年龄 ( 整数 ), 并用 cout 输出 输入输出符合以下范例 输入 master 999 输出 I am master, 999 years old. 注意 "," 后面有一个空格,"." 结束,

More information

Microsoft Word - CS-981.doc

Microsoft Word - CS-981.doc 4. 資料表示法 4.1 十進位與數字系統 (1). 基本觀念 數字系統的觀念 人們習慣以十進位的計量方式來計算 不同的數字系統有二進位 (Binary) 八進位 (Octal) 十進位 (Decimal) 十六進位(Hexadecimal) 二進位 電腦內部用來表達訊號的資料只有兩種符號 : 0 表示沒電,1 表示有電透過多個電路的組合表示出無數符號, 電腦便利用這些符號來表示不同的數字 利用兩條電線可以表示出

More information

C/C++ - 函数

C/C++ - 函数 C/C++ Table of contents 1. 2. 3. & 4. 5. 1 2 3 # include # define SIZE 50 int main ( void ) { float list [ SIZE ]; readlist (list, SIZE ); sort (list, SIZE ); average (list, SIZE ); bargragh

More information

CHAPTER VC#

CHAPTER VC# 1. 2. 3. 4. CHAPTER 2-1 2-2 2-3 2-4 VC# 2-5 2-6 2-7 2-8 Visual C# 2008 2-1 Visual C# 0~100 (-32768~+32767) 2 4 VC# (Overflow) 2-1 2-2 2-1 2-1.1 2-1 1 10 10!(1 10) 2-3 Visual C# 2008 10! 32767 short( )

More information

C/C++ - 文件IO

C/C++ - 文件IO C/C++ IO Table of contents 1. 2. 3. 4. 1 C ASCII ASCII ASCII 2 10000 00100111 00010000 31H, 30H, 30H, 30H, 30H 1, 0, 0, 0, 0 ASCII 3 4 5 UNIX ANSI C 5 FILE FILE 6 stdio.h typedef struct { int level ;

More information

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf (%d, & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf (%d %d 2013 18 ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp, Compilation Error cin scanf Time Limit Exceeded 1: A 5 B 5 C 5 D 5 E 5 F 5 1 2013 C 1 # include 2 int main ( void ) 3 { 4 int cases, a, b,

More information

Microsoft PowerPoint - ch09_AEL0080.ppt

Microsoft PowerPoint - ch09_AEL0080.ppt 9 字 串 子曰 : 質勝文則野, 文勝質則史 文質彬彬, 然後君子 論語論語.雍也第六雍也第六 標準的 C++ 提供了方便的程式庫, 讓我們能將 字串 視為獨立的單元, 以進行各種存取和剪接的處理 1/36 字串 9.1 9.2 9.3 9.4 9.5 字串的基本概念字串的輸入與輸出字串的處理字串的指標陣列字串處理在編碼上的應用 2/36 字串的基本概念 字串 (string) 是由雙引號 所包括起來的一串文字

More information

C C

C C C C 2017 3 8 1. 2. 3. 4. char 5. 2/101 C 1. 3/101 C C = 5 (F 32). 9 F C 4/101 C 1 // fal2cel.c: Convert Fah temperature to Cel temperature 2 #include 3 int main(void) 4 { 5 float fah, cel; 6 printf("please

More information

Microsoft PowerPoint - 11_Templates.ppt

Microsoft PowerPoint - 11_Templates.ppt 1 1. 上機考 20% 期末考 6/23( 四 ) 晚 6:30~8:30 範圍 : 第 7, 8, 9, 10 章實習內容 按座位坐, 隨機抽兩題 2. 紙上測驗 20% 6/21( 二 ) :9:30~11:00 課本 7-11, 13 章內容 2 第 11 章樣版 (Templates) 11.1 簡介 11.2 函式樣版 11.3 多載函式樣版 11.4 類別樣版 11.5 類別樣版與無型

More information

Microsoft Word - CPE考生使用手冊160524.docx

Microsoft Word - CPE考生使用手冊160524.docx 大 學 程 式 能 力 檢 定 (CPE) 考 生 使 用 手 冊 2016 年 5 月 24 日 這 份 手 冊 提 供 給 參 加 CPE 檢 定 考 試 的 考 生 內 容 包 含 考 試 環 境 的 使 用, 以 及 解 題 時 所 使 用 I/O 的 基 本 知 識 1. 如 欲 報 名 參 加 CPE 考 試, 請 先 於 CPE 網 站 完 成 帳 號 註 冊, 然 後 再 報 名 該

More information

C/C++ 语言 - 循环

C/C++ 语言 - 循环 C/C++ Table of contents 7. 1. 2. while 3. 4. 5. for 6. 8. (do while) 9. 10. (nested loop) 11. 12. 13. 1 // summing.c: # include int main ( void ) { long num ; long sum = 0L; int status ; printf

More information

FY.DOC

FY.DOC 高 职 高 专 21 世 纪 规 划 教 材 C++ 程 序 设 计 邓 振 杰 主 编 贾 振 华 孟 庆 敏 副 主 编 人 民 邮 电 出 版 社 内 容 提 要 本 书 系 统 地 介 绍 C++ 语 言 的 基 本 概 念 基 本 语 法 和 编 程 方 法, 深 入 浅 出 地 讲 述 C++ 语 言 面 向 对 象 的 重 要 特 征 : 类 和 对 象 抽 象 封 装 继 承 等 主

More information

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf (%d, & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9 201 201 21 ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp Compilation Error long long cin scanf Time Limit Exceeded 1: A 1 B 1 C 5 D RPG 10 E 10 F 1 G II 1 1 201 201 C 1 # include 2 int main ( void

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 9 [P.11] : Dev C++ [P.12] : http://c.feis.tw [P.13] [P.14] [P.15] [P.17] [P.23] Dev C++ [P.24] [P.27] [P.34] C / C++ [P.35] 10 C / C++ C C++ C C++ C++ C ( ) C++

More information

c_cpp

c_cpp C C++ C C++ C++ (object oriented) C C++.cpp C C++ C C++ : for (int i=0;i

More information

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf("%d", &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf("%

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf(%d, &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf(% 2013 ( 28 ) ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp Compilation Error long long cin scanf Time Limit Exceeded 1: A 10 B 1 C 1 D 5 E 5 F 1 G II 5 H 30 1 2013 C 1 #include 2 int main(void) 3

More information

C 1

C 1 C homepage: xpzhangme 2018 5 30 C 1 C min(x, y) double C // min c # include # include double min ( double x, double y); int main ( int argc, char * argv []) { double x, y; if( argc!=

More information

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc References (Section 5.2) Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 15-16, 2010 H.-T. Lin (NTU CSIE) References OOP 03/15-16/2010 0 / 22 Fun Time (1) What happens in memory? 1 i n t i ; 2

More information

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023) ( CIP) /. :, 2005. 2 ( ) ISBN 7-5624-3339-9.......... TP311. 1 CIP ( 2005) 011794 : : : : * : : 174 ( A ) :400030 : ( 023) 65102378 65105781 : ( 023) 65103686 65105565 : http: / /www. cqup. com. cn : fxk@cqup.

More information

C

C C 2017 3 14 1. 2. 3. 4. 2/95 C 1. 3/95 C I 1 // talkback.c: 2 #include 3 #include 4 #define DENSITY 62.4 5 int main(void) 6 { 7 float weight, volume; 8 int size; 9 unsigned long letters;

More information

Strings

Strings Streams and File I/O Cheng-Chin Chiang Streams 串流是 C++ 中一種負責資料輸出入程式的機制 輸入串流 : 資料流入程式 鍵盤 程式 檔案 程式 輸出串流 : 資料流出程式 程式 螢幕 程式 檔案 String Usage 我們已經學過的串流 cn: 鍵盤輸入串流 cout:: 螢幕輸出串流 我們可以定義其他形式的串流 例如 : 檔案輸入或檔案輸出 使用方法與

More information

C/C++语言 - 分支结构

C/C++语言 - 分支结构 C/C++ Table of contents 1. if 2. if else 3. 4. 5. 6. continue break 7. switch 1 if if i // colddays.c: # include int main ( void ) { const int FREEZING = 0; float temperature ; int cold_ days

More information

Computer Architecture

Computer Architecture ECE 3120 Computer Systems Assembly Programming Manjeera Jeedigunta http://blogs.cae.tntech.edu/msjeedigun21 Email: msjeedigun21@tntech.edu Tel: 931-372-6181, Prescott Hall 120 Prev: Basic computer concepts

More information

Microsoft PowerPoint - C_Structure.ppt

Microsoft PowerPoint - C_Structure.ppt 結構與其他資料型態 Janet Huang 5-1 結構的宣告 struct 結構名稱 struct 結構名稱變數 1, 變數 2,, 變數 m; struct 結構名稱 變數 1, 變數 2,, 變數 m; student; student; 5-2 1 結構變數初值的設定 struct 結構名稱 struct 結構名稱變數 = 初值 1, 初值 2,, 初值 n student="janet","1350901",100,95

More information

Microsoft PowerPoint - STU_EC_Ch02.ppt

Microsoft PowerPoint - STU_EC_Ch02.ppt 樹德科技大學資訊工程系 Chapter 2: Number Systems Operations and Codes Shi-Huang Chen Sept. 2010 1 Chapter Outline 2.1 Decimal Numbers 2.2 Binary Numbers 2.3 Decimal-to-Binary Conversion 2.4 Binary Arithmetic 2.5

More information

科学计算的语言-FORTRAN95

科学计算的语言-FORTRAN95 科 学 计 算 的 语 言 -FORTRAN95 目 录 第 一 篇 闲 话 第 1 章 目 的 是 计 算 第 2 章 FORTRAN95 如 何 描 述 计 算 第 3 章 FORTRAN 的 编 译 系 统 第 二 篇 计 算 的 叙 述 第 4 章 FORTRAN95 语 言 的 形 貌 第 5 章 准 备 数 据 第 6 章 构 造 数 据 第 7 章 声 明 数 据 第 8 章 构 造

More information

untitled

untitled 1 Outline 數 料 數 數 列 亂數 練 數 數 數 來 數 數 來 數 料 利 料 來 數 A-Z a-z _ () 不 數 0-9 數 不 數 SCHOOL School school 數 讀 school_name schoolname 易 不 C# my name 7_eleven B&Q new C# (1) public protected private params override

More information

jsj0.nps

jsj0.nps 第 3 章 Word 基 础 应 用 制 作 求 职 简 历 3 畅 1 求 职 简 历 案 例 分 析 本 章 以 制 作 求 职 简 历 为 例, 介 绍 Word 强 有 力 的 文 字 处 理 功 能, 包 括 Word 的 字 符 格 式 的 设 置 段 落 格 式 的 设 置 表 格 的 制 作 图 片 的 插 入 制 表 位 的 使 用 页 面 边 框 的 设 置 打 印 输 出 等

More information

C/C++语言 - 运算符、表达式和语句

C/C++语言 - 运算符、表达式和语句 C/C++ Table of contents 1. 2. 3. 4. C C++ 5. 6. 7. 1 i // shoe1.c: # include # define ADJUST 7. 64 # define SCALE 0. 325 int main ( void ) { double shoe, foot ; shoe = 9. 0; foot = SCALE * shoe

More information

第3章.doc

第3章.doc 3 3 3 3.1 3 IT Trend C++ Java SAP Advantech ERPCRM C++ C++ Synopsys C++ NEC C C++PHP C++Java C++Java VIA C++ 3COM C++ SPSS C++ Sybase C++LinuxUNIX Motorola C++ IBM C++Java Oracle Java HP C++ C++ Yahoo

More information

ebook39-5

ebook39-5 5 3 last-in-first-out, LIFO 3-1 L i n e a r L i s t 3-8 C h a i n 3 3. 8. 3 C + + 5.1 [ ] s t a c k t o p b o t t o m 5-1a 5-1a E D 5-1b 5-1b E E 5-1a 5-1b 5-1c E t o p D t o p D C C B B B t o p A b o

More information

Microsoft Word - ch04三校.doc

Microsoft Word - ch04三校.doc 4-1 4-1-1 (Object) (State) (Behavior) ( ) ( ) ( method) ( properties) ( functions) 4-2 4-1-2 (Message) ( ) ( ) ( ) A B A ( ) ( ) ( YourCar) ( changegear) ( lowergear) 4-1-3 (Class) (Blueprint) 4-3 changegear

More information

Microsoft PowerPoint - string_kruse [兼容模式]

Microsoft PowerPoint - string_kruse [兼容模式] Strings Strings in C not encapsulated Every C-string has type char *. Hence, a C-string references an address in memory, the first of a contiguous set of bytes that store the characters making up the string.

More information

第十一章 流类库与输入/输出

第十一章 流类库与输入/输出 第十一章流类库与输入 / 输出 本章主要内容 I/O 流的概念 输出流 输入流 输入 / 输出流 2 I/O 流的概念 当程序与外界环境进行信息交换时, 存在着两个对象, 一个是程序中的对象, 另一个是文件对象 流是一种抽象, 它负责在数据的生产者和数据的消费者之间建立联系, 并管理数据的流动 程序建立一个流对象, 并指定这个流对象与某个文件对象建立连接, 程序操作流对象, 流对象通过文件系统对所连接的文件对象产生作用

More information

Microsoft Word - 01.DOC

Microsoft Word - 01.DOC 第 1 章 JavaScript 简 介 JavaScript 是 NetScape 公 司 为 Navigator 浏 览 器 开 发 的, 是 写 在 HTML 文 件 中 的 一 种 脚 本 语 言, 能 实 现 网 页 内 容 的 交 互 显 示 当 用 户 在 客 户 端 显 示 该 网 页 时, 浏 览 器 就 会 执 行 JavaScript 程 序, 用 户 通 过 交 互 式 的

More information

新版 明解C言語入門編

新版 明解C言語入門編 328, 4, 110, 189, 103, 11... 318. 274 6 ; 10 ; 5? 48 & & 228! 61!= 42 ^= 66 _ 82 /= 66 /* 3 / 19 ~ 164 OR 53 OR 164 = 66 ( ) 115 ( ) 31 ^ OR 164 [] 89, 241 [] 324 + + 4, 19, 241 + + 22 ++ 67 ++ 73 += 66

More information

The golden pins of the PCI card can be oxidized after months or years

The golden pins of the PCI card can be oxidized after months or years Q. 如何在 LabWindows/CVI 編譯 DAQ Card 程式? A: 請參考至下列步驟 : 步驟 1: 安裝驅動程式 1. 安裝 UniDAQ 驅動程式 UniDAQ 驅動程式下載位置 : CD:\NAPDOS\PCI\UniDAQ\DLL\Driver\ ftp://ftp.icpdas.com/pub/cd/iocard/pci/napdos/pci/unidaq/dll/driver/

More information

Ps22Pdf

Ps22Pdf C ( CIP) C /. :, 2001. 7 21 ISBN 7-5624 -2355-5. C........ C. TP312 CIP ( 2001 ) 034496 C * * : 7871092 1 /16 : 14. 25 : 356 20017 1 20017 1 : 1 6 000 ISBN 7-5624-2355-5 / TP311 : 21. 00 C, C,,,, C,, (

More information

3.1 num = 3 ch = 'C' 2

3.1 num = 3 ch = 'C' 2 Java 1 3.1 num = 3 ch = 'C' 2 final 3.1 final : final final double PI=3.1415926; 3 3.2 4 int 3.2 (long int) (int) (short int) (byte) short sum; // sum 5 3.2 Java int long num=32967359818l; C:\java\app3_2.java:6:

More information

星星排列 _for loop Protected Sub Page_Load(ByVal sender As Object, ByVal e As Dim h As Integer = 7 'h 為變數 ' Dim i, j As Integer For i = 1 To h

星星排列 _for loop Protected Sub Page_Load(ByVal sender As Object, ByVal e As Dim h As Integer = 7 'h 為變數 ' Dim i, j As Integer For i = 1 To h 資訊系統與實習 製作 : 林郁君 一 2009.09.28 9X9 'button 被按下後 ' Dim i, j As Integer For i = 1 To 9 'i 從 1 到 9' For j = 1 To 9 'j 從 1 到 9' If j * i < 10 Then ' 如果 j 乘上 i 是為個位數 ' Response.Write(i & "*" & j & " =" & i *

More information

Go构建日请求千亿微服务最佳实践的副本

Go构建日请求千亿微服务最佳实践的副本 Go 构建 请求千亿级微服务实践 项超 100+ 700 万 3000 亿 Goroutine & Channel Goroutine Channel Goroutine func gen() chan int { out := make(chan int) go func(){ for i:=0; i

More information

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 WWW PHP 2003 1 Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 Comments PHP Shell Style: # C++ Style: // C Style: /* */ $value = $p * exp($r * $t); # $value

More information

Microsoft PowerPoint - ch02_AEL0080.ppt

Microsoft PowerPoint - ch02_AEL0080.ppt 2 C++ 的基本語法和使用環境 親自撰寫和執行程式是學好程式語言的不二法門 本章藉由兩個簡單的程式, 介紹 C++ 程式的基本結構和開發環境, 讓初學者能逐漸建立使用 C++ 的信心 1/44 C++ 的基本語法和使用環境 2.1 2.2 2.3 2.4 2.5 2.6 基本程式開發步驟第一個完整的 C++ 程式 Borland C++ 編譯器的取得和安裝使用 Visual C++.NET 程式開發步驟第二個

More information

Microsoft PowerPoint - ch12.ppt

Microsoft PowerPoint - ch12.ppt 12 資料流與檔案的存取 如果程式所處理的資料只能寫在原始程式內部, 或以互動的方式由鍵盤逐一輸入, 則功能將很有限 本章探討如何從檔案讀取資料, 以及將處理後的資料存入檔案的方法 1/69 資料流與檔案的存取 12.1 12.2 12.3 12.4 12.5 12.6 資料流檔案的存取檔案的存取模式資料的讀取與寫入檔案內容的位置標記將檔案的存取寫成函數 2/69 3/69 資料流 (stream)

More information

運算子多載 Operator Overloading

運算子多載 Operator Overloading 多載 Overloading 講師 : 洪安 1 多型 編譯時期多型 ( 靜態多型 ) function overloading 函數多載 如何正確呼叫同名的函數? 利用參數個數與型態 operator overloading 運算子多載 其實同 function overloading 執行時期多型 ( 或動態多型 ) 如何正確呼叫不同物件的相同名稱的成員函數 利用繼承與多型 2 函數多載 Function

More information

Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2

Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2 Chapter 02 變數與運算式 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.2 2.2.1 2.2.2 2.2.3 type 2.2.4 2.3 2.3.1 print 2.3.2 input 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 + 2.4.6 Python Python 2.1 2.1.1 a p p l e b e a r c 65438790

More information

Microsoft PowerPoint - ch03_AEL0080.ppt

Microsoft PowerPoint - ch03_AEL0080.ppt 3 基本資料型態 能盡物之性, 則可以贊天地之化育 可以贊天地之化育, 則可以與天地矣 中庸中庸.第二十一章第二十一章 1/88 基本資料型態 3.1 3.2 3.3 3.4 3.5 3.6 3.7 整數和浮點數變數和常數算術運算標準數學函數的運算邏輯值及其運算字元與字串位元處理運算 2/88 C++ 的資料型態 C++ 資料型態 基本資料型態 整數 int, short, long 浮點數 float,

More information

概述

概述 OPC Version 1.6 build 0910 KOSRDK Knight OPC Server Rapid Development Toolkits Knight Workgroup, eehoo Technology 2002-9 OPC 1...4 2 API...5 2.1...5 2.2...5 2.2.1 KOS_Init...5 2.2.2 KOS_InitB...5 2.2.3

More information

untitled

untitled 3 C++ 3.1 3.2 3.3 3.4 new delete 3.5 this 3.6 3.7 3.1 3.1 class struct union struct union C class C++ C++ 3.1 3.1 #include struct STRING { typedef char *CHARPTR; // CHARPTR s; // int strlen(

More information

C

C C 2017 4 1 1. 2. while 3. 4. 5. for 6. 2/161 C 7. 8. (do while) 9. 10. (nested loop) 11. 12. 3/161 C 1. I 1 // summing.c: 2 #include 3 int main(void) 4 { 5 long num; 6 long sum = 0L; 7 int status;

More information

Microsoft PowerPoint - 13_Exception.ppt

Microsoft PowerPoint - 13_Exception.ppt 1 第 13 章例外處理 (Exception Handling) 13.1 簡介 13.2 例外處理概觀 13.3 其它錯誤處理技術 13.4 簡單的例外處理範例 - 除 0 錯誤 13.5 重新丟出例外 13.6 函式例外清單 13.7 處理非預期例外 13.8 堆疊返回 13.9 建構子, 解構子, 與例外處理 13.10 例外與繼承 13.11 處理新的錯誤 13.12 auto_ptr 類別與動態記憶體配置

More information

Microsoft Word - 09.數學136-281.docx

Microsoft Word - 09.數學136-281.docx 136. 計 算 梯 型 面 積 (1 分 ) 請 以 JAVA 運 算 式 計 算 下 面 梯 形 面 積, 並 輸 出 面 積 結 果 梯 形 面 積 公 式 為 :( 上 底 + 下 底 ) 高 2 每 一 組 依 序 分 別 輸 入 梯 形 的 上 底 下 底 及 高 的 整 數 輸 出 梯 形 面 積 輸 入 輸 出 94 190 120 99 54 47 137. 計 算 三 角 形 面

More information

四川省普通高等学校

四川省普通高等学校 四 川 省 普 通 高 等 学 校 计 算 机 应 用 知 识 和 能 力 等 级 考 试 考 试 大 纲 (2013 年 试 行 版 ) 四 川 省 教 育 厅 计 算 机 等 级 考 试 中 心 2013 年 1 月 目 录 一 级 考 试 大 纲 1 二 级 考 试 大 纲 6 程 序 设 计 公 共 基 础 知 识 6 BASIC 语 言 程 序 设 计 (Visual Basic) 9

More information

C++ 程序设计 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1

C++ 程序设计 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1 C++ 程序设计 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1 1 PERSON 1 Person 题目描述 编写程序, 定义一个基类 Person, 包含 name 和 age 两个数据成员 ; 再由它派生出学生类 Student 和教师类 Teacher, 其中学生类添加学号 no 数据, 教师类添加职称 title 数据 ; 要求每个类均有构造函数 析构函数和显示数据的函数

More information

Microsoft PowerPoint - ch04_AEL0080.ppt

Microsoft PowerPoint - ch04_AEL0080.ppt 4 選擇 在正常的情況下, 電腦程式的執行是以敘述的排列次序逐步處理的 使用控制架構 (control structures) 可以改變這種既定的先後次序, 讓程式得以進行更複雜的運算, 或以更簡潔的指令來實現演算法 1/42 選擇 4.1 演算法的描述方式 4.2 變數的運用範圍 (Scope of variables) 4.3 if- 敘述 4.4 巢狀 if- 敘述 (Nested if statements)

More information

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor 1 4.1.1.1 (Load) 14 1.1 1 4.1.1.2 (Save) 14 1.1.1 1 4.1.2 (Buffer) 16 1.1.2 1 4.1.3 (Device) 16 1.1.3 1 4.1.3.1 (Select Device) 16 2 4.1.3.2 (Device Info) 16 2.1 2 4.1.3.3 (Adapter) 17 2.1.1 CD-ROM 2 4.1.4

More information

全國各級農會第 2 次聘任職員統一考試試題 科目 : 程式設計類別 : 九職等以下新進人員作答注意事項 : 1 全部答案請寫在答案卷內, 如寫在試題紙上, 則不予計分 2 請以黑色或藍色鋼筆或原子筆書寫, 並以橫式書寫 ( 由左至右, 由上而下 ) 一 選擇題 ( 每題 4 分, 共 40 分 )

全國各級農會第 2 次聘任職員統一考試試題 科目 : 程式設計類別 : 九職等以下新進人員作答注意事項 : 1 全部答案請寫在答案卷內, 如寫在試題紙上, 則不予計分 2 請以黑色或藍色鋼筆或原子筆書寫, 並以橫式書寫 ( 由左至右, 由上而下 ) 一 選擇題 ( 每題 4 分, 共 40 分 ) 全國各級農會第 2 次聘任職員統一考試試題 一 選擇題 ( 每題 4 分, 共 40 分 ) 1. 在 Java 語言中, 請問下列何者資料型別的變數, 所需的儲存空間最少? (a) char (b) float (c) double (d) int 2. 請問下列何者非 C 語言的關鍵字 (key word)? (a) const (b) default (c) dynamic (d) continue

More information

untitled

untitled A, 3+A printf( ABCDEF ) 3+ printf( ABCDEF ) 2.1 C++ main main main) * ( ) ( ) [ ].* ->* ()[] [][] ** *& char (f)(int); ( ) (f) (f) f (int) f int char f char f(int) (f) char (*f)(int); (*f) (int) (

More information

Microsoft PowerPoint - scanfCommonTraps.ppt

Microsoft PowerPoint - scanfCommonTraps.ppt scanf 的緩衝區問題 與 scanf 支援的資料剖析功能 丁培毅 1 01 #include 02 #include 03 04 int main() { 05 char str[100]; 06 char symbol='\0'; 07 問題 1 描述 08 printf("please input a string: "); 09 scanf("%s",str);

More information

新・解きながら学ぶJava

新・解きながら学ぶJava 481! 41, 74!= 40, 270 " 4 % 23, 25 %% 121 %c 425 %d 121 %o 121 %x 121 & 199 && 48 ' 81, 425 ( ) 14, 17 ( ) 128 ( ) 183 * 23 */ 3, 390 ++ 79 ++ 80 += 93 + 22 + 23 + 279 + 14 + 124 + 7, 148, 16 -- 79 --

More information

Microsoft PowerPoint - 12 struct and other datatypes.ppt

Microsoft PowerPoint - 12 struct and other datatypes.ppt 第十一章結構與其它資料型態 結構與巢狀結構 結構陣列的各種使用方法 列舉型態 自定的型態別名 typedef 認識結構 使用者自定的資料型態 結構可將型態不同的資料合併成為新的型態 定義結構與宣告結構變數的格式如下 : struct 結構名稱 資料型態成員名稱 1; 資料型態成員名稱 2;... 資料型態成員名稱 n; struct 結構名稱變數 1, 變數 2,, 變數 n; 定義結構與宣告結構變數的語法

More information

Strings

Strings Strings Cheng-Chin Chiang Strings Strings 一串儲存在連續記憶體之字元串 表示法 : 以雙引號圍起 This is a book, I love programming, 12234 字串須有一結束字元 \0 (NULL) 在字串尾,NULL 在 C++ 內為一個內定常數值 H i t h e r e! \0 An Array Type of Strings

More information

《计算概论》课程 第十九讲 C 程序设计语言应用

《计算概论》课程 第十九讲  C 程序设计语言应用 计算概论 A 程序设计部分 字符数组与字符串 李戈 北京大学信息科学技术学院软件研究所 lige@sei.pku.edu.cn 字符数组的定义 #include int main() char a[10] = 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' ; for (int i = 0; i < 10; i++) cout

More information

CHAPTER 1

CHAPTER 1 CHAPTER 1 1-1 System Development Life Cycle; SDLC SDLC Waterfall Model Shelly 1995 1. Preliminary Investigation 2. System Analysis 3. System Design 4. System Development 5. System Implementation and Evaluation

More information

Microsoft PowerPoint - Class2.pptx

Microsoft PowerPoint - Class2.pptx C++ 程式初探 II 2015 暑期 C++ 程式 II 大綱 1. 變數 2. 運算式 3. 輸出 4. 條件判斷 5. 迴圈 6. 陣列 2 基本變數型態 整數 位元組 浮點數 位元組 字元 位元組 short 2 float 4 char ( 整數 ) 1 int 2 (4) double 8 long 4 (8) long double 8(10) 位元組 整數値域 浮點數値域 準確度 1-128

More information

運算子多載 Operator Overloading

運算子多載 Operator Overloading 多型 Polymorphism 講師 : 洪安 1 多型 編譯時期多型 ( 靜態多型 ) function overloading 如何正確呼叫同名的函數? 利用參數個數與型態 operator overloading 其實同 function overloading 執行時期多型 ( 或動態多型 ) 如何正確呼叫不同物件的相同名稱的成員函數 利用繼承與多型 2 子類別與父類別物件間的指定 (assignment)

More information

新・解きながら学ぶC言語

新・解きながら学ぶC言語 330!... 67!=... 42 "... 215 " "... 6, 77, 222 #define... 114, 194 #include... 145 %... 21 %... 21 %%... 21 %f... 26 %ld... 162 %lf... 26 %lu... 162 %o... 180 %p... 248 %s... 223, 224 %u... 162 %x... 180

More information

第 5 章 使用資料

第 5 章  使用資料 新觀念的 Visual Basic.NET 教本 第 5 章使用資料 5-1 資料的表示法 VB.NET 資料的分類 數值資料 字串資料 日期時間資料 布林資料 數值資料 整數 VB.NET 的整數與數學的整數並沒有什麼不同, 如 2005 0 +512-204 等均為正確的寫法, 但逗號是不能使用的, 如 10,000 便是不正確的表示法 十六進位數要在前面加上 &H, 八進位數要在前面加上 &O(

More information

第1章

第1章 第 15 章 標準類別 1 本章提要 15.1 前言 15.2 基本資料類別介紹 15.3 Integer 類別 15.4 Double 類別 15.5 Float 類別 Long 類別 Short 類別 15.6 數學相關類別 Math 15.7 後記 2 15.1 前言 不同基本資料型別可以互相轉換, 但也只予許由小轉大的情況, 例如 1. byte 轉為 short int long float

More information

第1章

第1章 第 7 章 字串 1 本章提要 7.1 前言 7.2 類別與物件 7.3 String 類別 7.4 StringBuffer 類別 7.5 綜合練習 7.6 後記 2 7.1 前言 Java 用 String 類別 (Class) 來處理字串, String 類別是 Java 類別庫內建的類別, 它是一堆已經寫好的程式, 我們可以直接拿來使用字串很像字元型別的一維陣列, 字串裡能存放的資料都屬於字元性質,

More information

Microsoft PowerPoint - 20-string-s.pptx

Microsoft PowerPoint - 20-string-s.pptx String 1 String/ 1.: char s1[10]; char *s2; char s3[] = "Chan Tai Man"; char s4[20] = "Chan Siu Ming"; char s5[]={'h','e','l','l','o','\0'; 0 1 2 3 4 5 6 7 8 9 10 11 12 s3 C h a n T a i \0 M a n \0 printf

More information

Microsoft PowerPoint - Class4.pptx

Microsoft PowerPoint - Class4.pptx C++ 程式初探 IV 2015 暑期 ver. 1.0.2 C++ 程式 IV 大綱 1. 時間函式 2. 格式化輸出 3. 遞迴函式 (recursion) 4. 字串 5. 字串轉型 2 補充語法 時間計算 引入標頭檔 #include #include #include #include using namespace

More information

Microsoft PowerPoint - Class5.pptx

Microsoft PowerPoint - Class5.pptx C++ 程式初探 V 2015 暑期 ver. 1.0.1 C++ 程式語言 大綱 1. 大量檔案讀取 & 計算 2. 指標 3. 動態記憶體 & 動態陣列 4. 標準函式庫 (STL) vector, algorithm 5. 結構與類別 2 大量檔案讀取 & 計算 若目前有一個程式將讀取純文字文件 (.txt) 中的整數, 並將該文件中的整數有小到大排序後, 儲存到另外一個新的純文字件中 假設有

More information

untitled

untitled 不 料 料 例 : ( 料 ) 串 度 8 年 數 串 度 4 串 度 數 數 9- ( ) 利 數 struct { ; ; 數 struct 數 ; 9-2 數 利 數 C struct 數 ; C++ 數 ; struct 省略 9-3 例 ( 料 例 ) struct people{ char name[]; int age; char address[4]; char phone[]; int

More information

ebook14-4

ebook14-4 4 TINY LL(1) First F o l l o w t o p - d o w n 3 3. 3 backtracking parser predictive parser recursive-descent parsing L L ( 1 ) LL(1) parsing L L ( 1 ) L L ( 1 ) 1 L 2 L 1 L L ( k ) k L L ( 1 ) F i r s

More information

C++ 程序设计 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1

C++ 程序设计 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1 C++ 程序设计 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1 1 CIRCLE 1 Circle 描述 编写一个圆类 Circle, 实现半径的输入 面积的计算和输出 输入 圆的半径 (double 类型 ) 输出 圆的面积 ( 保留小数点后两位 ) 样例输入 3 样例输出 28.27 提示 圆周率的取值需要比较精确, 以保证计算结果的精度 #include

More information

C++ 程序设计 OJ9 - 参考答案 MASTER 2019 年 6 月 7 日 1

C++ 程序设计 OJ9 - 参考答案 MASTER 2019 年 6 月 7 日 1 C++ 程序设计 OJ9 - 参考答案 MASTER 2019 年 6 月 7 日 1 1 CARDGAME 1 CardGame 题目描述 桌上有一叠牌, 从第一张牌 ( 即位于顶面的牌 ) 开始从上往下依次编号为 1~n 当至少还剩两张牌时进行以下操作 : 把第一张牌扔掉, 然后把新的第一张放到整叠牌的最后 请模拟这个过程, 依次输出每次扔掉的牌以及最后剩下的牌的编号 输入 输入正整数 n(n

More information

字元意義備註 \n 換行字元 \t Tab \r 迴車鍵 Windows 系統中以 \r\n 代表換行 \ 單引號 \" 雙引號 \0 空字元 用來代表字串的結束 \\ 倒斜線 倒斜線被用做跳脫字元, 因此要用兩個倒斜線表示 表 3.2: 常用特殊字元 ( 二 ) 常用技巧 : 字元判斷在 ASCI

字元意義備註 \n 換行字元 \t Tab \r 迴車鍵 Windows 系統中以 \r\n 代表換行 \ 單引號 \ 雙引號 \0 空字元 用來代表字串的結束 \\ 倒斜線 倒斜線被用做跳脫字元, 因此要用兩個倒斜線表示 表 3.2: 常用特殊字元 ( 二 ) 常用技巧 : 字元判斷在 ASCI 第三章 字串處理 第一節 字元與字串 一 字元與 ASCII C++ 中的字元 (Character) char 其實是儲存一個 0 到 255 的整數, 在電腦中有一個符號表, 每個符號都有他各自的編號 輸出字元時, 計算機就會自動將 char 裡面的整數去查符號表, 印出對應符號, 這個表格我們稱為 ASCII 碼 雖然 char 印出來是符號, 但實際上儲存的是整數 ASCII 碼網路上都能查到,

More information

新・明解C言語入門編『索引』

新・明解C言語入門編『索引』 !... 75!=... 48 "... 234 " "... 9, 84, 240 #define... 118, 213 #include... 148 %... 23 %... 23, 24 %%... 23 %d... 4 %f... 29 %ld... 177 %lf... 31 %lu... 177 %o... 196 %p... 262 %s... 242, 244 %u... 177

More information

碩命題橫式

碩命題橫式 一 解釋名詞 :(50%) 1. Two s complement of an integer in binary 2. Arithmetic right shift of a signed integer 3. Pipelining in instruction execution 4. Highest and lowest layers in the TCP/IP protocol suite

More information

3. 企 业 债 券 : 公 司 债 券 : 5. 证 券 公 司 债 券 : 6. 企 业 短 期 融 资 券 : 7. 中 期 票 据 : 8. 资 产 支 持 证 券 : 9. 国 际 开 发 机 构 人 民 币 债 券 : 10. 中 小 非 金 融 企 业 集 合 票 据 例 题? 判 断

3. 企 业 债 券 : 公 司 债 券 : 5. 证 券 公 司 债 券 : 6. 企 业 短 期 融 资 券 : 7. 中 期 票 据 : 8. 资 产 支 持 证 券 : 9. 国 际 开 发 机 构 人 民 币 债 券 : 10. 中 小 非 金 融 企 业 集 合 票 据 例 题? 判 断 第 1 节 投 资 银 行 业 务 概 述 1. 投 资 银 行 的 含 义 [ 熟 悉 ]: 等 第 1 章 证 劵 经 营 机 构 的 投 资 银 行 业 务 (1) 狭 义 的 就 是 指 某 些 资 本 市 场 活 动, 着 重 指 一 级 市 场 上 的 承 销 并 购 和 融 资 活 动 的 财 务 顾 问 (2) 广 义 的 包 括 公 司 融 资 并 购 顾 问 股 票 和 债 券

More information

(Guangzhou) AIT Co, Ltd V 110V [ ]! 2

(Guangzhou) AIT Co, Ltd V 110V [ ]! 2 (Guangzhou) AIT Co, Ltd 020-84106666 020-84106688 http://wwwlenxcn Xi III Zebra XI III 1 (Guangzhou) AIT Co, Ltd 020-84106666 020-84106688 http://wwwlenxcn 230V 110V [ ]! 2 (Guangzhou) AIT Co, Ltd 020-84106666

More information

Chapter 8 - Operator Overloading

Chapter 8 - Operator Overloading 1 第八章 - 運算子多載 Operator Overloading 8.1 簡介 8.2 運算子多載基本原理 8.3 運算子多載的限制 8.4 運算子函式 - 成員函式與非成員函式 8.5 多載 > 運算子 8.6 多載單運算元運算子 (Unary Operators) 8.7 多載雙運算元運算子 (Binary Operators) 8.8 案例研讀 : Array 類別 8.9 物件型別轉換

More information

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File 51 C 51 51 C C C C C C * 2003-3-30 pnzwzw@163.com C C C C KEIL uvision2 MCS51 PLM C VC++ 51 KEIL51 KEIL51 KEIL51 KEIL 2K DEMO C KEIL KEIL51 P 1 1 1 1-1 - 1 Project New Project 1 2 Windows 1 3 N C test

More information

運算子多載 Operator Overloading

運算子多載 Operator Overloading 函數樣板 (Function Template) 與 類別樣板 (Class Template) 講師 : 洪安 1 資料結構與 C++ 程式設計進階班 為何需要通用函數? (1/2) int abs(int x) { return (x>0)?x:-x; 取名困難不好記 float fabs(float x) { return (x>0)?x:-x; complex cabs(complex x)

More information

Microsoft PowerPoint - 09_Inheritance.ppt

Microsoft PowerPoint - 09_Inheritance.ppt 1 第九章 - 繼承 (Inheritance) 9.1 簡介 9.2 基本類別與衍生類別 9.3 受保護的成員 9.4 基本類別與衍生類別的關係 9.5 案例研究 : 三層繼承架構 9.6 衍生類別的建構子與解構子 9.8 public, protected, 與 private 繼承關係 9.9 繼承的優點 2 9.1 簡介 不同類別之間的關係 合成關係與繼承關係 合成關係 ( has-a )

More information

nooog

nooog C : : : , C C,,, C, C,, C ( ), ( ) C,,, ;,, ; C,,, ;, ;, ;, ;,,,, ;,,, ; : 1 9, 2 3, 4, 5, 6 10 11, 7 8, 12 13,,,,, 2008 1 1 (1 ) 1.1 (1 ) 1.1.1 ( ) 1.1.2 ( ) 1.1.3 ( ) 1.1.4 ( ) 1.1.5 ( ) 1.2 ( ) 1.2.1

More information

The return of scanf The number of fields successfully converted and assigned int a =1, b =2, c =3; int n = scanf("%d %d %d", &a, &b, &c); printf("%d\n

The return of scanf The number of fields successfully converted and assigned int a =1, b =2, c =3; int n = scanf(%d %d %d, &a, &b, &c); printf(%d\n Introduction to Computer and Program Design Lesson 2 Functions, scanf and EOF James C.C. Cheng Department of Computer Science National Chiao Tung University The return of scanf The number of fields successfully

More information

C语言的应用.PDF

C语言的应用.PDF AVR C 9 1 AVR C IAR C, *.HEX, C,,! C, > 9.1 AVR C MCU,, AVR?! IAR AVR / IAR 32 ALU 1KBytes - 8MBytes (SPM ) 16 MBytes C C *var1, *var2; *var1++ = *--var2; AVR C 9 2 LD R16,-X ST Z+,R16 Auto (local

More information

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F 1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET 2.0 2.0.NET Framework.NET Framework 2.0 ( 3).NET Framework 2.0.NET Framework ( System ) o o o o o o Boxing UnBoxing() o

More information