favorite We need a little bit of your help to keep things running, click on this banner to learn more

PP2. Week 5: April 5 - 11


The point is given with its x and y coordinates: (x, y).

Two points (a, b), (c, d) and an integer n are given. Add them.

  • Adding two points means to add the corresponding coordinates: (1, 2) + (3, 4) = (4, 6).

  • Adding point and a number means to add a number to both point coordinates: (1, 2) + 10 = (11, 12).

Write the code according to the next interface:

class Point // C++
  int x, y;
  Point(int x = 0, int y = 0); // Constructor
  void Read(void); // Read vector coordinates
  void Print(void); // Print vector coordinates
  Point operator +(int v); // Overload operator +: return the sum of point and integer v
  Point operator +(Point &p); // Overload operator +: return the sum of two points
  int getX(void); // Return x coordinate
  int getY(void); // Return y coordinate
  void SetX(int x); // Set x coordinate
  void SetY(int y); // Set y coordinate


class Point // Java
  private int x, y;
  Point(int x, int y); // Constructor
  public String toString(); // Return the string with point coordinates
  public Point Add(int v); // Add to both point coordinates the value of v, return the point
  public Point Add(Point p); // Add point p, return the sum of to points
  public int getX(); // Return x coordinate
  public int getY(); // Return y coordinate
  public void SetX(int x); // Set x coordinate
  public void SetY(int y); // Set y coordinate


The first line contains the coordinates a and b of the first point. The second line contains the coordinates c and d of the second point. The third line contains an integer n. All values do not exceed 10000 by the absolute value.


Print the sum of two points and a number.

Time limit 1 second
Memory limit 128 MiB
Input example #1
1 2
3 4
Output example #1
14 16
Author Mykhailo Medvediev
Source C++, Java