// C4_7.cpp : Defines the entry point for the console application. // 表格的顯示 #include "stdafx.h" #include #include using namespace std; int main(int argc, char* argv[]) { const int size = 3; // 設定變數--字元數 int i = 0, j = 0; // 設定初始值 cout << endl // 輸出表格標題 << "長度單位轉換" << endl << endl; cout << endl << " |"; cout << setw(12) <<"公尺" << " "; // 輸出標頭內容 cout << setw(12) <<"英寸" << " "; cout << setw(12) <<"英呎" << " "; cout << setw(12) <<"英哩" << " "; cout << endl; // 換行 for(i=0; i<=12; i++) cout << "_____"; // 建立分隔線 cout << endl << " |"; cout << setw(12) <<1000 << " "; // 輸出表格內容 cout << setw(12) <<39370<< " "; cout << setw(12) <<3280.83 << " "; cout << setw(12) <<0.62136 << " "; // *** 下一列 cout << endl << " |"; cout << setw(12) << 1 << " "; // 輸出表格內容 cout << setw(12) << 39.37 << " "; cout << setw(12) << 3.28083 << " "; cout << setw(12) <<0.0006214 << " "; cout << endl; // 換行 cout << endl; return 0; }