fork(3) download
  1. #include <iostream>
  2. #include<iomanip>
  3. using namespace std;
  4. class Point
  5. {
  6. private:
  7. int x,y;
  8. public:
  9. Point();
  10. Point(int x_a,int y_a);
  11. int getx()const;
  12. int gety()const;
  13. void setdata(int ,int );
  14. friend istream& operator>>(istream &input, Point &p1);
  15. friend ostream& operator<<(ostream &output,const Point &p1);
  16. Point operator+(const Point &x2);
  17. Point operator-(const Point &x2);
  18. };
  19. Point::Point()
  20. {
  21. x=0;
  22. y=0;
  23. }
  24. Point::Point(int x_a,int y_a)
  25. {
  26. x_a=x;
  27. y_a=y;
  28. }
  29. int Point::getx()const
  30. {
  31. return x;
  32. }
  33. int Point::gety()const
  34. {
  35. return y;
  36. }
  37. void Point::setdata(int x_c,int y_c)
  38. {
  39. x_c=x;
  40. y_c=y;
  41. }
  42. istream& operator>>(istream &input, Point &p1)
  43. {
  44. input>>setw(1)>>p1.x;
  45. input.ignore();
  46. input>>p1.y;
  47. return input;
  48. }
  49. ostream& operator<<(ostream &output,const Point &p1)
  50. {
  51. output<<"("<<p1.x<<","<<p1.y<<")";
  52. return output;
  53. }
  54. Point Point::operator+(const Point &x2)
  55. {
  56.  
  57. int x3=x+x2.getx();
  58. int y3=y+x2.gety();
  59. return Point(x3,y3);
  60. }
  61. Point Point::operator-(const Point &x2)
  62. {
  63. int x3=x-x2.getx();
  64. int y3=y-x2.gety();
  65. return Point(x3,y3);
  66. }
  67. int main()
  68. {
  69. Point point1,point2;
  70. cin>>point1;
  71. cin>>point2;
  72. cout<<point1<<" + "<<point2<<" = "<<point1+point2<<endl;
  73. cout<<point1<<" - "<<point2<<" = "<<point1-point2;
  74. return 0;
  75. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
(0,0) + (0,0) = (134516496,134516498)
(0,0) - (0,0) = (134516496,134516498)