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

Class Vector

Create the class Vector with three members x, y, z - private integers.

Implement in the class three constructors:

  • default constructor that sets to 0 the class members.

  • constructor with parameters, the parameters are the vector coordinates

  • copy constructor.

Implement the methods:

  • double length() - return the length of the vector;

  • void setX(int), void setY(int), void setZ(int) - methods that change the corresponding values of the vector;

  • int getX(), int getY() int getZ() - methods that return the corresponding coordinates of the vector.

  • void Out() - print the coordinates of the vector, separated by a space, then print a new line symbol.

Submit the class only.

class Vector // Java
  private int x, y, z;
  Vector(); // default constructor, set to 0 the members of the class
  Vector(int x, int y, int z); // constructor with parameters, the parameters are the vector coordinates
  Vector(Vector v); // copy constructor

  void setX(int x); // change the value of x
  void setY(int y); // change the value of y
  void setZ(int z); // change the value of z

  int getX(); // return the x coordinate
  int getY(); // return the y coordinate
  int getZ(); // return the z coordinate

  public double length(); // return the length of the vector
  public String toString(); // return the string - vector coordinates space separated
Time limit 1 second
Memory limit 128 MiB