Visual C CSIM PU q q q q

  • Slides: 12
Download presentation
開始使用Visual C++ CSIM, PU

開始使用Visual C++ CSIM, PU

程式範例 q q q q q CSIM, PU // A program to check the

程式範例 q q q q q CSIM, PU // A program to check the size of data types #include <iostream> main() { cout << " Size of int is : " << sizeof(int) << " bytes" << endl; cout << " Size of short is : " << sizeof(short) << " bytes" << endl; cout << " Size of unsigned is: " << sizeof(unsigned) << " bytes" << endl; cout << " Size of long is : " << sizeof(long) << " bytes" << endl; cout << " Size of float is : " << sizeof(float) << " bytes" << endl; cout << " Size of double is : " << sizeof(double) << " bytes" << endl; cout << " Size of char is : " << sizeof(char) << " bytes" << endl; cout<< " Size of 3. 8 is : " << sizeof(3. 8) << " bytes" << endl; cout<< " Size of 3. 8 + a is : " << sizeof(3. 8 + a) << " bytes" << endl; cout<< " Size of 3. 8 f is : " << sizeof(3. 8 f) << " bytes" << endl; cout<< " Size of a is : " << sizeof(a) << " bytes" << endl; cout<< " Size of 3. 8 f + a is: " << sizeof(3. 8 f + a) << " bytes" << endl; }

q q q // x的3次方計算 #include <cmath> #include <iostream> main() { q float x

q q q // x的3次方計算 #include <cmath> #include <iostream> main() { q float x ; q cout << "請輸入一個數值: n "; q cin >> x; q cout << "它的3次方是: " q << pow(x, 3) << endl ; q } CSIM, PU

C++的資料型態 q 基本資料型態 q 整數 int, short, long q 浮點數 float, double, long double

C++的資料型態 q 基本資料型態 q 整數 int, short, long q 浮點數 float, double, long double q 字元 char q 邏輯值 bool (bool b 1, b 2, b 3; b 1=true; b 2=false; b 3=1) q 衍生資料型態 q 與位址相關的資料型態 q指標 q參照 q 有結構的資料型態 qstring qenum qaray qstruct qunion qclass CSIM, PU

範例程式 q #include <iomanip> q //-----函數C 2 F的宣告-------------q float C 2 F(float); q int

範例程式 q #include <iomanip> q //-----函數C 2 F的宣告-------------q float C 2 F(float); q int main() q { q float CTemp; q cout << " 攝氏 華氏 " << endl ; q cout << "---------" << endl ; q for ( int i = 1 ; i <= 10 ; i++ ) q { q CTemp = 10. 0*i; q cout << setw(5) << CTemp << " " q << setw(5) << C 2 F(CTemp) << endl ; q } q cout << "---------" << endl ; q return 0; q } CSIM, PU q q q q //-------函數C 2 F的定義-----float C 2 F(float C) { float F; F = C*9. 0/5. 0 + 32. 0; return F; }