2014年9月24日 星期三

(綠色皮) 最新C++程式語言, 施威銘研究室 著, 旗標 第三章 變數 '參考' 答案

==============================================
/* 程式檔名:Test_C3-42-1.cpp */
/* 程式目的:定義巨集長數SIZE長為10然後從螢幕輸出SIZE*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140924 */
   
#include<iostream>
#define SIZE 10 
using namespace std;   //使用 std 名稱空間 
int main()
{
      
     cout << " SIZE = " << SIZE << endl;
     system("PAUSE");
     return 0;    
}
==============================================
/* 程式檔名:Test_C3-42-2.cpp */
/* 程式目的:由螢幕輸出三個變數的值*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140924 */
   
#include<iostream>
using namespace std;   //使用 std 名稱空間 
int main()
{
     int a=10;
     double b=101.7;
     char c='c'; 
     cout << " a = " << a << endl;
     cout << " b = " << b << endl;
     cout << " c = " << c << endl;
     system("PAUSE");
     return 0;    
}
==============================================
/* 程式檔名:Test_C3-42-3.cpp */
/* 程式目的:唯獨變數定義 長寬*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140924 */
   
#include<iostream>
using namespace std;   //使用 std 名稱空間 
int main()
{
     const int i_long=5,i_weight=10;
     
     cout << "長 = " << i_long << endl; 
     cout << "寬 = " << i_weight << endl; 
     system("PAUSE");
     return 0;    
}
==============================================
/* 程式檔名:Test_C3-42-4.cpp */
/* 程式目的:計算3+2總和*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140924 */
   
#include<iostream>
using namespace std;   //使用 std 名稱空間 
int main()
{
     cout << "3+2 = " << 3+2 << endl; 
     system("PAUSE");
     return 0;    
}
==============================================
/* 程式檔名:Test_C3-42-5.cpp */
/* 程式目的:計算 f=1*2*3*4*5*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140924 */
   
#include<iostream>
using namespace std;   //使用 std 名稱空間 
int main()
{
     int f;
     f=1*2*3*4*5;
     cout << "f = " << f << endl; 
     system("PAUSE");
     return 0;    
}
==============================================
/* 程式檔名:Test_C3-42-6.cpp */
/* 程式目的:計算 y=2*x 使用者輸入 x 顯示y的值*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140924 */
   
#include<iostream>
using namespace std;   //使用 std 名稱空間 
int main()
{
     double x,y;
     cout << "請輸入 x 的值  " << endl;
     cin >> x;
     y=2*x;
     cout << "y = 2 * x =" << y << endl; 
     system("PAUSE");
     return 0;    
}
==============================================
/* 程式檔名:Test_C3-42-7.cpp */
/* 程式目的:顯示單引號'的ASCII碼*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140924 */
   
#include<iostream>
using namespace std;   //使用 std 名稱空間 
int main()
{
     char a=39;
     cout << " '的ASCII = " << a << endl; 
     system("PAUSE");
     return 0;    
}
==============================================
/* 程式檔名:Test_C3-42-8.cpp */
/* 程式目的:在螢幕顯示以下訊息*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140924 */
   
#include<iostream>
using namespace std;   //使用 std 名稱空間 
int main()
{
     char a=39;
     cout << " 我正在學習 \" C++ \" 程式語言 " << endl; 
     system("PAUSE");
     return 0;    
}
==============================================
/* 程式檔名:Test_C3-42-9.cpp */
/* 程式目的:在螢幕輸出結果*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140924 */
   
#include<iostream>
using namespace std;   //使用 std 名稱空間 

int main()
{
     int a=10, b=20, c=30;
     int temp;
     
     cout << "交換前 a = " << a  << "\tb= " << b << "\tc= " << c<< endl;
     
     temp = a;
     a = c;
     c = b;
     b = temp;
     
     cout << "交換後 a = " << a  << "\tb= " << b << "\tc= " << c << endl;
     
     system("PAUSE");
     return 0;    
}
==============================================
/* 程式檔名:Test_C3-42-10.cpp */
/* 程式目的:利用ASCII碼,將小寫字母z轉換成大寫字母Z,然後從螢幕輸出*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140924 */
   
#include<iostream>
using namespace std;   //使用 std 名稱空間 

int main()
{
     char upper= 'z',lower;
     lower = upper - 32;
     cout << upper << " 的小寫是 " << lower << endl; 
     
     system("PAUSE");
     return 0;        
}
==============================================

沒有留言:

張貼留言