第五周閱讀程式

2021-06-29 14:54:38 字數 1564 閱讀 7059

(1)

#include using namespace std;

class base

; base(int m)

int get()

void set(int m)

};//base_end

int main()

; cout

ptr=ptr-1;

cout

執行結果:

執行結果:

(4)

#include #include using namespace std;

class student

student( const string& nm, int sc = 0 ): name(nm), score(sc){}

//(1)下面的const幹神馬?宣告常資料成員

void set_student( const string& nm, int sc = 0 )

//(2)下面的const分別幹神馬?

const string& get_name() const

int get_score() const

private:

string name;

int score;

};//(3)下面的const幹神馬?

void output_student(const student& student )

int main()

執行結果:

執行結果:

學習心得:

第六個程式中,在輸出result2時,忘記了靜態成員是類中所有物件的公共元素。

第五周 閱讀程式(5)

問題描述 本週再補充三個和指標有關的閱讀程式,進一步掌握指標工作的原理。可以在上機時通過單步執行,進一步和你在人腦中執行程式的過程進行對照。5 閱讀程式,寫出程式的執行結果並理解 include using namespace std class myclass myclass static int...

第五周 閱讀程式(2)

檔名稱 test.cpp 作 者 呼亞萍 完成日期 2015年4月6日 版 本 號 v1.0 問題描述 閱讀程式,寫出程式的執行結果並理解 程式輸入 相應的程式 程式輸出 不同程式的結果 include includeusing namespace std class student student...

第五周程式閱讀

include using namespace std class base base int m int get void set int m base end int main cout ptr ptr 1 cout 執行結果 學習心得 這個程式很好理解,this指標指向形參並複製,main函式...