Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Point2D{
- private:
- // 資料 (變數部分)
- double x;
- double y;
- public:
- friend void OutputPoint2D(Point2D v);
- // 操作 (函式部分)
- Point2D(){
- x = 0;
- y = 0;
- }
- Point2D(double a, double b){
- x = a;
- y = b;
- }
- double getX(){
- return x;
- }
- double getY(){
- return y;
- }
- Point2D operator*(Point2D b){
- double i = x * b.x;
- double j = y * b.y;
- Point2D c( i, j );
- return c;
- }
- };
- void OutputPoint2D(Point2D v){
- cout << "(" << v.x << "," << v.y << ")" << endl;
- }
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment