開發平台(Platform): (Ex: Win10, Linux, ...)
win10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
Dev C++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
這個class目的是輸入兩個數列 最後會印出交集跟聯集
交集聯集的函式就沒貼了 主要是class宣告看不太懂
都寫在程式碼裡 希望有人能幫忙解惑 謝謝
餵入的資料(Input):
class Set {
private:
int *s, n;
public:
Set(int _n = 1) {//1. 這邊應該是同載? 為何這邊要設1呢
n = _n;
s = new int[n];
}
Set(int *a, int _n) {
setSet(a, _n);
}
void setSet(int *a, int _n) {
n = _n;
s = new int[n];
for (int i = 0; i < n; i++) s[i] = a[i];
}
int getN() { return n; }
int getSet(int *a) {
for (int i = 0; i < n; i++) a[i] = s[i];
return n;//2. 為何這邊只回傳n 而不是整個s 所以這個函式是為了得到n?
}
string str() {
ostringstream out; // output string stream
out << "{";
for (int i = 0; i < n - 1; i++) out << s[i] << ", ";
out << s[n - 1] << "}";
return out.str();
}
};
Set read_set(char *line) {
int a[SIZE], i = 0;
char *p = strtok(line, " ");//3. 這個*p是什麼? 感覺不是指標
a[i++] = atoi(p); //4. a本來就是int 為何這邊還要atoi呢
while((p = strtok(NULL, " ")) != NULL) a[i++] = atoi(p);
int n = i;
return Set(a, n);
}
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):