本站電子書

您可以在這些電子書店找到本站電子書: Google Play 圖書iBooks StoreHyReadReadmooPubu
===>>>本站推出學習遊戲意見調查<<<===《如何自學程式設計》入選 Google Play 台灣地區2016年度最佳書籍

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



select_demo.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   cout << endl;
   if (3 > 5) {
      cout << "喔,3大於5發生了!" << endl;
   }
   else if (4 > 5) {
      cout << "喔,4大於5發生了!" << endl;
   }
   else if (5 > 5) {
      cout << "喔,5大於5發生了!" << endl;
   }
   else if (6 > 5) {
      cout << "6當然大於5哩!" << endl;
   }
   else {
      cout << "以上沒有符合的條件 :(" << endl;
   }
   cout << endl;
         
   return 0;
}
 
/* 檔名: select_demo.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

switch_demo.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   cout << endl;
   switch (6) {
      case 3:
         cout << "選擇是3..." << endl;
         break;
          
      case 4:
         cout << "選擇是4..." << endl;
         break;
     
      case 5:
         cout << "選擇是3..." << endl;
         break;
          
      case 6:
         cout << "選擇是6..." << endl; 
         break;
     
      default:
         cout << "以上沒有符合的條件 :(" << endl;
   }
   cout << endl;
         
   return 0;
}

/* 檔名: switch_demo.cpp
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0701.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a = 3;
   int b = 5;
    
   cout << endl;
   if (a == b) { 
      cout << "a == b" << endl;
   }
   else {
      cout << "a != b" << endl;
   }
   cout << endl;
    
   return 0;
}
 
/* 檔名: exercise0701.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0702.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a;
   int b;
    
   cin >> a;
   cin >> b;
    
   cout << endl;
   if (a == b) { 
      cout << "a == b" << endl;
   }
   else {
      cout << "a != b" << endl;
   }
   cout << endl;
    
   return 0;
}
 
/* 檔名: exercise0702.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0703.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a = 6;
    
   cout << endl;
   switch (a) {
      case 0:
         cout << "a: 0" << endl;

      case 1:
         cout << "a: 1" << endl;
        
      case 2:
         cout << "a: 2" << endl;
        
      case 3:
         cout << "a: 3" << endl;

      case 4:
         cout << "a: 4" << endl;
        
      case 5:
         cout << "a: 5" << endl;
        
      case 6:
         cout << "a: 6" << endl;
        
      case 7:
         cout << "a: 7" << endl;

      case 8:
         cout << "a: 8" << endl;
        
      case 9:
         cout << "a: 9" << endl;
   }
   cout << endl;
    
   return 0;
}
 
/* 檔名: exercise0703.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0704.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a;
    
   cin >> a;
   cout << endl;
   switch (a) {
      case 0:
         cout << "a: 0" << endl;

      case 1:
         cout << "a: 1" << endl;
        
      case 2:
         cout << "a: 2" << endl;
        
      case 3:
         cout << "a: 3" << endl;

      case 4:
         cout << "a: 4" << endl;
        
      case 5:
         cout << "a: 5" << endl;
        
      case 6:
         cout << "a: 6" << endl;
        
      case 7:
         cout << "a: 7" << endl;

      case 8:
         cout << "a: 8" << endl;
        
      case 9:
         cout << "a: 9" << endl;
   }
   cout << endl;
    
   return 0;
}
 
/* 檔名: exercise0704.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0705.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a;
    
   cin >> a;
   cout << endl;
   switch (a) {
      case 0:
         cout << "a: 0" << endl;
         break;

      case 1:
         cout << "a: 1" << endl;
         break;
        
      case 2:
         cout << "a: 2" << endl;
         break;
        
      case 3:
         cout << "a: 3" << endl;
         break;

      case 4:
         cout << "a: 4" << endl;
         break;
        
      case 5:
         cout << "a: 5" << endl;
         break;
        
      case 6:
         cout << "a: 6" << endl;
         break;
        
      case 7:
         cout << "a: 7" << endl;
         break;

      case 8:
         cout << "a: 8" << endl;
         break;
        
      case 9:
         cout << "a: 9" << endl;
         break;
        
      default:
         cout << "NO CASE!!" << endl;
   }
   cout << endl;
    
   return 0;
}
 
/* 檔名: exercise0705.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0706.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a;
    
   cin >> a;
   cout << endl;
   
   if (a == 0) {
      cout << "a: o" << endl;
   }
   else if (a == 1) {
      cout << "a: 1" << endl;
   }
   else if (a == 2) {
      cout << "a: 2" << endl;
   }
   else if (a == 3) {
      cout << "a: 3" << endl;
   }
   else if (a == 4) {
      cout << "a: 4" << endl;
   }
   else if (a == 5) {
      cout << "a: 5" << endl;
   }
   else if (a == 6) {
      cout << "a: 6" << endl;
   }
   else if (a == 7) {
      cout << "a: 7" << endl;
   }
   else if (a == 8) {
      cout << "a: 8" << endl;
   }
   else if (a == 9) {
      cout << "a: 9" << endl;
   }
   else {
      cout << "NO CASE!!" << endl;
   } 
   cout << endl;
    
   return 0;
}
 
/* 檔名: exercise0706.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0707.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a;
    
   cin >> a;
   cout << endl;
   
   if (a < 60) {
      cout << "Bad!!" << endl;
   }
   else if (a >= 60 && a < 70) {
      cout << "Not Bad!!" << endl;
   }
   else if (a >= 70 && a < 80) {
      cout << "Good!!" << endl;
   }
   else if (a >= 80 && a < 90) {
      cout << "Great!!" << endl;
   }
   else if (a >= 80 && a < 100) {
      cout << "Wonderful!!" << endl;
   }
   else {
      cout << "Excellent!!" << endl;
   } 
   cout << endl;
    
   return 0;
}
 
/* 檔名: exercise0707.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

the end

沒有留言: