阿摩線上測驗 登入

申論題資訊

試卷:110年 - 110-2 國立清華大學期末考試題_電機工程學系:計算機程式設計#112945
科目:程式設計
年份:110年
排序:0

題組內容

3. (15%) Consider the access of dynamically allocated data structure.
63c0b6613025d.jpg

申論題內容

(c) Fill in Statement-2 in the following program that calls the member function show() properly so that the screen will display “Everybody is somebody”. (5%)

詳解 (共 1 筆)

詳解 提供者:hchungw

If ptr_s is a pointer to an S_record object and you want to call the show() member function using this pointer, you should use the arrow operator (->). The arrow operator is used in C++ to access members of a structure or a class through a pointer.

Given the context, Statement-2 should be:

 
ptr_s->show();

This line will call the show() member function of the object that ptr_s points to. If the show() function is implemented such that it displays "Everybody is somebody" on the screen, this statement will achieve the desired output.

 

如果ptr_s是指向一個S_record對象的指針,並且你想使用這個指針來調用show()成員函數,你應該使用箭頭運算子(->)。箭頭運算子在C++中被用來通過指針訪問結構體或類的成員。

根據上下文,Statement-2應該是:

 
ptr_s->show();

這行代碼將調用ptr_s所指向的對象的show()成員函數。如果show()函數實現為在屏幕上顯示“Everybody is somebody”,這個語句將實現預期的輸出。