2016年4月30日 星期六

a001~a005說明

a001題目中已給參考

a002: This is a book
 直接以 cout 印三行,
cout語法:
cout << 資料流1 << 資料流 2 ... << 資料流n ;
資料流可以是字串、變數、運算式…, 本題只用到字串常數,以""框住要印的資料

<< endl是換行
cout <<"This is a book." << endl; 三行,每行使用一個 cout 
cout <<"That is a pen." << endl;  每一行也皆有 endl換行
cout <<"I am a student." << endl;

a003: 許願
有一些字元是特殊用途,需以 \註明要印而非特殊用
這題有雙引號、反斜線
cout << "^_^" << endl;
cout << "\"o\"" << endl;  印"前加 \
cout << "\\^o^/" << endl;  印\前也要加 \

a004: 民國與西元的換算
這題使用 cin輸入資料存至變數 n,再將n運算後輸出,使用 變數前需宣告
int n; 使用前需宣告

cin >> n;    輸入 >>傳至變數
cout << n+1911 << endl; 將n加1911後再輸出 

a005: 矩形面積
這題使用 cin輸入兩個資料存至變數 a,b,再將a乘b後輸出
int a,b; 一行宣告兩個,以逗號隔開

cin >> a >> b;    輸入兩個資料,以兩個 >>傳入變數
cout << a*b << endl; 將 a乘b 後再輸出


Related Posts:

  • b549 數位相片檔名/* b549 nr102-5 北二區102年-5 數位相片檔名  */ #include <iostream> #include <iomanip> #include <set> #include <map> using namespace… Read More
  • Z2A河內塔範例4/26中午加強,Z2A三位學生到課 Vb2010 -Windows Form專案: 一個按鈕、一個文字方塊,以debug.print輸出至即時運算視窗 程式碼如下:   Private Sub Button1_Click(ByVal sender As System.Object, By… Read More
  • Z2A,Z1A求組合數4/28中午及5/1晚上加強,Z2A三位、Z1A三位,共6位到課 Vb2010 -Windows Form專案: 四個按鈕、二個文字方塊(輸入m,n),一個標籤(輸出) M取N求組合數(二項係數) 0<=N<=M<=66,分四種解法程式碼如下:     Dim… Read More
  • b547 巧克力口味/* b547-巧克力口味 */ #include <iostream> #include <sstream> #include <iomanip> #include <cstring> #include <cstdio> #includ… Read More
  • vb版 BST建立及巡訪一個TextBox1輸入5~30個皆不相同的整數以「,」隔開 一個Label1顯示輸出 一個按鈕,執行(1)建二元搜尋樹,(2)在Label1顯示{前序、中序、後序}巡訪結果 程式碼如下: Public Class Form1     Class BT    … Read More

0 意見:

張貼留言