본문 바로가기
프로그램/C++ 1000제

C++ 117제] 어서와! C++은 처음이지! CHAPTER 09. PROGRAMMING EXERCISE 4. p394

by 건티 2024. 11. 11.
728x90

출처 : 반크_백제역사 유적지구와 이스탐블 역사지구

 

참고풀이]

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

class Point {
private:
   double xval, yval;
public:
   Point(double x=0.0, double y=0.0)
   {
      xval = x; yval = y;
   }
   double getX() { return xval; }
   double getY() { return yval; }
   void Swap(Point& other1, Point& other2);
   void Print();
};

void Point::Swap(Point &other1, Point &other2)
{
   Point temp;

 

   temp = other1;
   other1 = other2;
   other2 = temp;
}

void Point::Print()
{
   cout << "(" << getX() << "," << getY() << ")" << endl;
}

int main()
{
   Point p1(1.2, -2.8);
   Point p2(3, 6);

   p1.Print();
   p2.Print();

   p1.Swap(p1, p2);

   p1.Print();
   p2.Print();

   return 0;
}

 

참고풀이 결과]

 

 

 

 

 

대한민국의 아름다운 영토, 독도의 봄

 

반응형

댓글