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.
Sample Input Download
Sample Output Download
Partial Judge Code
13058.cppPartial Judge Header
13058.hTags
Discuss
Description
You are a manager of a printery (印刷廠). There are 3 departments in the printery, Cyan department, Magenta department, Yellow department, which is charged in cyan dye, magenta dye, and yellow dye respectively.
Complete four existed classes CyanDepartment, MagentaDepartment, YellowDepartment, PrinteryManager.
Printery:
Protected Variables:
- cyan_storage(int) as the storage of cyan dye.
- magenta _storage(int) as the storage of magenta dye.
- yellow_storage(int) as the storage of yellow dye.
Public Methods:
- void info() – Should print out the storage of all kinds of dye.
CyanDepartment: virtual derived from Printery
Constructors:
- CyanDepartment(int c) – Should initialize the cyan_storage to c.
Public Methods:
- void buy(int l) – Should increase the cyan_storage by l.
- void use(int l) – Should decrese the cyan_storage by l.
- bool check(int l) – Return true if cyan_storage is more or equal than l; otherwise, return false.
So as to classes MagentaDepartment (handle magenta_storage), YellowDepartment (handle yellow_storage).
PrinteryManager: derived from CyanDepartment, MagentaDepartment, YellowDepartment
Constructors:
- PrinteryManager(int c, int m, int y) – Should initialize the cyan_storage to c, magenta_storage to m, yellow_storage to y.
Public Methods:
- void info() – Should call info() in Printery to print out the storage information.
- void buy(int c, int m, int y) – Should call buy() in CyanDepartment, MagentaDepartment, YellowDepartment to increase cyan_storage by c, magenta_storage by m, yellow_storage by y. And print out as below format.
Buy cyan:cL, magenta:mL, yellow:yL, total:tL
For example: Buy cyan:10L, magenta:20L, yellow:30L, total:60L
- void use(int c, int m, int y) – First, call check() to see whether all the dye have enough storage. If so call use() in CyanDepartment, MagentaDepartment, YellowDepartment to decrease cyan_storage by c, magenta_storage by m, yellow_storage by y. And print out as below format.
Use cyan:cL, magenta:mL, yellow:yL, total:tL
For example: Use cyan:10L, magenta:20L, yellow:30L, total:60L
Otherwise, than do nothing.
- bool check(int c, int m, int y) – Call check() in CyanDepartment, MagentaDepartment, YellowDepartment. Return true if all of them have enough storage. Otherwise, return false, and print as below format:
[ERROR] No enough color dye
For example:
[ERROR] No enough cyan dye
[ERROR] No enough yellow dye
note that print by followed order cyan -> magenta -> yellow.
main.cpp: download
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.