---
tags: Computer Programming II
image: https://i.imgur.com/Ngut6cI.png
---
:::info
大家可以來幫忙整理 QA!(要登入才能編輯哦)
如果該問題已寄信但尚未回覆,請打上「助教xxx: :mailbox_with_mail:」
:::
# 程設二 作業 2 QA 整理
[TOC]
作業連結:[hw02](https://drive.google.com/file/d/1PqoiU1tPi4x0MWsLUJcdipgtnTCDaBQt/view)
## 1 Wildcard Matching
Q: `pStr` 各字串判斷會由什麼隔開?
A: 空格隔開 (運用 `mysplit` 切開) ,若多個空格可將切出來的字串視為 `""` 來進行判斷,回傳符合 `pPattern` 的個數
Q: `pppList` `pStr` `pParttern` 任一個參數為 `NULL` 都是視為錯誤輸入嗎?
A: `NULL` 都是錯誤輸入
Q:`pStr` `pParttern` 任一字串為空字串是否為合法輸入?
A: `pStr` 可以是空字串,`pPattern` 為空字串是錯誤輸入
## 2 IEEE 754
## 3 Puella Magi Madoka Magica
Q: 在第三題有許多後綴為 `ctor` 的 function ,我猜測那個是創建腳色的 function,但為何需要先讀入一個參數,回傳值也需要一個參數?照例說要麼是讀入地址讓我們直接更改參數,或是像第五題不需任何讀入參數不就行了嗎?兩個分別是做甚麼用的?
A: 這提出的目的是讓大家體驗用 C 寫 C++ 的 class,再加上我原本有用些 macro 黑魔法但被老紀拔了,所以才長這樣,參數的部分就是要傳入一個空間,回傳就是把傳入空間的指標再回傳就好,雖然是蠻蠢的,但就這樣做就好
Q: 在 `Mahoushoujo` 中有一個叫 `attack` 的 function pointer 的類型是 `(Mahoushoujo *this, Entity *enemy)`,但是在下方的 `Mahoushoujo_attack` 中,類型卻是 `(Mahoushoujo *this, void *enemy)`,我的理解是要把 `attack` 指向 `Mahoushoujo_attack`,但這樣會報錯,打錯還是這樣是正常的?
A: 喔喔,這就是我的失誤了,抱歉,改成 `Entity` 好了
<!-- 問到的 header file 資訊可以用註解加上去,比較方便看 -->
```diff=
// modoka.h (Copyright TA Peng)
#pragma once
typedef struct {
int hp;
int (*is_dead)(void* this);
} Entity;
typedef struct {
Entity base;
char* name;
char* wish;
int kimoji;
int (*is_dead)(void* this);
int (*is_despair) (void* this);
void (*do_wish) (void* this);
void (*despair) (void* this);
} Shoujo;
typedef void (*Skill) (void* this, void* target);
typedef struct _mhsj Mahoushoujo;
struct _mhsj {
Shoujo base;
int atk;
int (*is_dead)(void* this);
void (*do_wish) (void* this);
void (*attack) (Mahoushoujo* this, Entity* enemy);
Skill skill;
};
typedef struct _mj Majo;
struct _mj {
Shoujo base;
int atk;
int (*is_dead)(void* this);
void (*attack) (Majo* this, Entity* enemy);
void (*kekkai) (Majo* this, Shoujo* sj);
};
Entity* Entity_ctor(Entity* this);
void Entity_dtor(Entity* this);
int Entity_is_dead(void* this);
Shoujo* Shoujo_ctor(Shoujo* this, const char* name, const char* wish);
void Shoujo_dtor(Shoujo* this);
int Shoujo_is_despair(void* this);
void Shoujo_do_wish(void* this);
void Shoujo_despair(void* this);
Mahoushoujo* Mahoushoujo_ctor(Mahoushoujo* this, const char* name, const char* wish, Skill skill);
void Mahoushoujo_dtor(Mahoushoujo* this);
void Mahoushoujo_do_wish(void* this);
- void Mahoushoujo_attack(Mahoushoujo* this, void* enemy);
+ void Mahoushoujo_attack(Mahoushoujo* this, Entity* enemy);
void Mahoushoujo_despair(void* this);
Majo* Majo_ctor(Majo* this, const char* name, const char* wish);
void Majo_dtor(Majo* this);
void Majo_attack(Majo* this, void* enemy);
void Majo_kekkai(Majo* this, Shoujo* sj);
void Majo_despair(void* this);
Majo* mhsj_to_mj(Mahoushoujo* mhsj);
void Madoka_skill(void* this, void* target);
void Homura_skill(void* this, void* target);
void Sayaka_skill(void* this, void* target);
void Kyoko_skill(void* this, void* target);
#include <stdlib.h>
#include <stddef.h>
```
## 4 Mixed Fraction Arithmetic
Q: 是否需要考慮各種莫名其妙的錯誤測資?像是/沒寫、frac 打錯、大括號只打一邊等各種莫名其妙的錯誤輸入?
A: 不用,輸入不會搞你
## 5 Vector
Q: 為啥 `myvector_print` 還需要輸入一個 type 呢?是指若目前儲存的型別需 `myvector_print` 輸入的型別不同,我們必須將目前儲存的資料轉為 `myvector_print` 輸入的 type 類型再輸出是嗎?
A: 在這題確實是沒有必要,原因就跟你想的一樣,但在其他情況有時候可以當作強制轉型使用,所以有些時候確實這是必要的,但這題就按造 arg 傳入的 print 吧
Q: 想請問如果型別是極座標,`distance` 是否有可能為負數,如果有可能為負數,那麼在輸出 `myvector_print` 時,是要輸出 `distance` 為負的還是為正的,還是皆可?
A: `distance` 不會有負數。如有負數即為錯誤輸入
Q: `myvector_set` 的錯誤輸入條件有哪些? `angle` 若為負的算是錯誤輸入嗎?`angle` 若大於 2 pi 算也算是錯誤輸入嗎?
A: `angle` > 2 pi or `angle` < 0 可以判定為錯,也可以判定為對。但 `distance` 就必須為非負數,否則為錯
Q: 如果輸入是極座標,那麼單位是 Pi 還是度?
A: 應為弧度
## 6 Bonus: Bit Operation