NTOU CSE C++ Programming
本次作業主題是 C++ 的模板。
教學文件和作業說明文件: https://hackmd.io/@kogiokka/ntou-cse-cpp-nav
範例程式和範例專案:Google Drive
用 function template 改寫函式,讓數列陣列 array
的類別可變化。
請改寫下列函式宣告,並撰寫函式的定義:
/**
* 找出陣列中的最大值。
*
* @param array 儲存一個數列的陣列
* @param size 陣列長度
* @return 陣列中的最大值
*/
int max(int array[], int size);
對應的範例程式:
template_function.cpp
int a1[] = {1, 2, 3, 5, 4};
double a2[] = {1.2, 3.4, 5.6, 2.3, 4.5};
用 struct template 寫一個 stack(array 版本)。template 接受 2 個參數:
利用 function template 定義下列函式:
函式名稱 | 回傳值型態 | 回傳值意義 |
---|---|---|
push |
bool |
true 代表成功,false 代表失敗。 |
pop |
bool |
true 代表成功,false 代表失敗。 |
isEmpty |
bool |
true 代表成功,false 代表失敗。 |
isFull |
bool |
true 代表成功,false 代表失敗。 |
printStack |
void |
無回傳值 |
對應的範例程式:
template_function.cpp
template_struct.cpp
int
20
float
15
依序執行下列步驟:
isEmpty
isFull
push
: 15 data (1 - 15)isEmpty
isFull
printStack
pop
: 15 dataisEmpty
isFull
printStack
格式:<學號>-<姓名>.zip
,例如:11057022-江柏毅.zip
如果你是用 Visual Studio,請刪除下列資料夾再上傳:.vs
、out
、Debug
、x64
。
使用其他 IDE 的同學也請刪掉建置資料夾再上傳,例如:build
、out
。