Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Point2D.h */
- #include <iostream>
- using namespace std;
- class Point2D{
- private:
- // 資料(變數部分)
- int _x; // 加底線 避免名稱上衝突
- int _y;
- public:
- // 方法;功能(函式部分)
- friend void OutputPoint2D(Point2D p);
- Point2D(){
- _x = 0;
- _y = 0;
- }
- Point2D(int x, int y){
- _x = x;
- _y = y;
- }
- Point2D operator*(Point2D v2){
- int newX = _x * v2._x;
- int newY = _y * v2._y;
- Point2D v3(newX, newY);
- return v3;
- }
- };
- void OutputPoint2D(Point2D v){
- cout << "(" << v._x << "," << v._y << ")" << endl;
- }
- /* Point2D.h */
- int main(){
- int x, y;
- cin >> x >> y;
- Point2D p1(x, y);
- cin >> x >> y;
- Point2D p2(x, y);
- Point2D p3;
- p3 = p1 * p2;
- OutputPoint2D( p3 );
- return 0;
- }
Add Comment
Please, Sign In to add comment