C++ 入門指南 4.01
練習 10.13 參考程式 - 練習設計乒乓球類別
// 引入標準程式庫中相關的輸入、輸出程式
#include <iostream>
// 使用 to_string()
#include <string>
// std 為標準程式庫的命名空間
using namespace std;
// 宣告 Point 類別
class Point {
// 宣告 public 成員
public:
int x, y;
int Distance(Point);
};
// 宣告 Ball 類別
class Ball {
// 宣告 public 成員
public:
Point p;
};
int main(void) {
// 宣告建立 Ball 物件
Ball b;
b.p.x = 0;
b.p.y = 0;
// 印出座標
cout << endl;
cout << "(" + to_string(b.p.x) + ", " + to_string(b.p.y) + ")" << endl;
cout << endl;
// 最後回傳 0 給作業系統
return 0;
}
/* 《程式語言教學誌》的範例程式
http://kaiching.org/
檔名:exercise1013.cxx
編譯:g++ exercise1013.cxx
執行:./a.out
功能:C++入門指南單元十的練習
作者:張凱慶 */
回到練習題目