|
Time |
Memory |
| Case 1 |
1 sec |
32 MB |
| Case 2 |
1 sec |
32 MB |
| Case 3 |
1 sec |
32 MB |
| Case 4 |
1 sec |
32 MB |
| Case 5 |
1 sec |
32 MB |
Description
Complete an existed class Vector2, which is used to store and calculate 2-dimentional vectors.
Vector2
Private Variables:
- x(double) as the x component of a vector.
- y(double) as the y component of a vector.
Constructors:
- Vector2(int i) – Should initialize both x and y to I.
- Vector2(int _x, int _y) – Should initalize x to _x and y to _y.
Public Methods:
- Vector2 operator+(const Vector2 &other) – Should return a vector2 which is the addition of the two input vectors.
- Vector2 operator-(const Vector2 &other) – Should return a vector2 which is the subtraction of the two input vectors.
- Vector2 operator*(const double db) – Should return a vector2 which is the db times scaling multiple vector.
- Vector2 operator/(const double db) – Should return a vector2 which is the 1/db times scaling multiple vector.

- bool operator>(const Vector2 &other) – Should return true if the length of vector is bigger than others; otherwise return false.
note that you may use dist() to get the length a vector.
- bool operator<(const Vector2 &other) – Should return true if the length of vector is smaller than others; otherwise return false.
- bool operator>(const double db) – Should return true if the length of vector is bigger than db; otherwise return false.
- bool operator<(const double db) – Should return true if the length of vector is smaller than db; otherwise return false.
- bool operator==(const Vector2 &other) – Should return true if the length of vector is equal to others, in addition, x and y vector component are equal to other’s x and y vector component; otherwise return false.
- bool operator==(const double db) – Should return true if the length of vector is equal to db; otherwise return false.
- friend ostream &operator<<(ostream &os, const Vector2 &v) – For print out a Vector2 variable directly (No need to implement).
Private Methods:
- double dist() – Return the length of a vector (
)
Input
No need to handle input. (Input would be number 1~5 to represent the index of test-case)
Output
Depend on test case show in main.cpp.
Partial Judge Code
13058.cpp
Partial Judge Header
13058.h
Tags