C++ 入門指南 V2.00 - 單元 3 範例及練習程式碼



demo.cpp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// 引入標準程式庫中相關的輸入、輸出程式
#include <iostream>
// 引入標準程式庫中相關的字串程式
#include <string>
 
// std 為標準程式庫的命名空間
using namespace std;
  
int main(void) {
   // 下面建立名稱為 m , string 型態的物件
   // 小括弧為 string 的建構子
   // 雙引號為字串字面常數
   string m("There is no spoon.");
 
   // cout 用來輸出的物件
   // endl 為新行符號 '\n'    
   cout << endl;
   cout << m << endl;   
   cout << endl << endl;
     
   return 0;
}
  
/* 檔名: demo.cpp
   作者: Kaiching Chang
   時間: 2014-5 */

exercise0301.cpp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
  
using namespace std;
  
int main(void) {
   short a = 1;
   int b = 2;
   long c = 3;
      
   cout << endl;
   cout << "a: " << a << endl;
   cout << "b: " << b << endl;
   cout << "c: " << c << endl;
   cout << endl << endl;
     
   return 0;
}
  
/* 檔名: exercise0301.cpp
   作者: Kaiching Chang
   時間: 2014-5 */

exercise0302.cpp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
  
using namespace std;
  
int main(void) {
   float a = 0.1;
   double b = 0.2;
      
   cout << endl;
   cout << "a: " << a << endl;
   cout << "b: " << b << endl;
   cout << endl << endl;
     
   return 0;
}
  
/* 檔名: exercise0302.cpp
   作者: Kaiching Chang
   時間: 2014-5 */

exercise0303.cpp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
  
using namespace std;
  
int main(void) {
   char a = 'a';
      
   cout << endl;
   cout << "a + 1: " << a + 1 << endl;
   cout << "a + 2: " << a + 2 << endl;
   cout << endl << endl;
     
   return 0;
}
  
/* 檔名: exercise0303.cpp
   作者: Kaiching Chang
   時間: 2014-5 */

exercise0304.cpp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
  
using namespace std;
  
int main(void) {
   bool a = true;
      
   cout << endl;
   cout << "a: " << a << endl;
   cout << "!a: " << !a << endl;
   cout << endl << endl;
     
   return 0;
}
  
/* 檔名: exercise0304.cpp
   作者: Kaiching Chang
   時間: 2014-5 */

exercise0305.cpp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
  
using namespace std;
  
int main(void) {
   char a = '*';
      
   cout << endl;
   cout << a << endl;
   cout << a << a << endl;
   cout << a << a << a << endl;
   cout << a << a << a << a << endl;
   cout << a << a << a << a << a << endl;
   cout << endl << endl;
     
   return 0;
}
  
/* 檔名: exercise0305.cpp
   作者: Kaiching Chang
   時間: 2014-5 */

the end

沒有留言: