13367 - Struct - Vector2   

Description

Struct – Vector2

 

Description:

給定一個名為Vector2的struct,如下列所示:

Vector2

          - int x

          - int y

 

再給定主要執行程式main.c (題號.c)、以及Header檔function.h (題號.h);請試著完成Header檔中未實現的函式:SetValue()Add()Sub()Mul()Div()

Methods:

- void SetValue(Vector2 *v1, double _x, double _y) - Should set v1’s x value to _x, v1's y value to _y

- Vector2 Add(Vector2 v1, Vector2 v2) - Should return a Vector2 which is addition of v1 and v2

- Vector2 Sub(Vector2 v1, Vector2 v2) - Should return a Vector2 which is subtraction of v1 and v2

- Vector2 Mul(Vector2 v1, double d) - Should return a Vector2 which is multiplication of v1 and d

- Vector2 Div(Vector2 v1, double d)) - Should return a Vector2 which is division of v1 and d

 

function.c

#include "function.h"
 
void SetValue(Vector2 *v1, double _x, double _y)
{
    // TODO
}
 
Vector2 Add(Vector2 v1, Vector2 v2)
{
    // TODO
}
 
Vector2 Sub(Vector2 v1, Vector2 v2)
{
    // TODO
}
 
Vector2 Mul(Vector2 v1, double d)
{
    // TODO
}
 
Vector2 Div(Vector2 v1, double d)
{
    // TODO
}

Input

輸入符合以下格式

op

x1 y1

(x2 y2 or d)

 

Note:

  1. 如果op是’+’或是’-‘,則會再給一組x2, y2用來代表另一個向量的值
  2. 如果op是’*’或是’/‘,則會再給一個浮點數d
  3. 不會出現不合理的數值運算,例如除以0
  4. 運算後的結果不會超過doubledata range

Output

輸出符合以下格式:

(x, y)

 

Note:

  1. 輸出的最後必須要有一個換行符號 ('\n')
  2. 無需處理輸出

Sample Input  Download

Sample Output  Download

Partial Judge Code

13367.c

Partial Judge Header

13367.h

Tags




Discuss