112年 地方特考 四等 資訊處理 程式設計概要 試卷

pdf
116.19 KB
3 頁
windows10
侵權投訴
加載中. ..
PDF
112
等考試
訊處理
式設計概要
考試時間
1
小時
30
座號
禁止使用電子計算器。
本科目除專門名詞或數理公式外,應使用本國文字作答。
代號
頁次
3
1
一、撰寫遞迴函式是重要程式設計技巧之一。
請說明下列遞迴函式 findnum 的為何?(5
請將 findnum()函式改寫成非遞迴的函式。10
請說明下列非遞迴程式目的為何?(5分)
請將 convert()函式改寫成以遞迴運算的函式且函式內不可新增變
10 分)
int items, price[100];//全域變數
int findnum (int i, int num) {
if (i < items) {
if (num < price[i])
num = price[i];
num = findnum (i+1, num);
}
return num;
}
int main () {
int i, num;
// 讀入數量及所有正整數價錢
scanf("%d", &items);
for (i=0; i<items; i++)
scanf ("%d", &price[i]);
num = findnum (0, -1);
printf ("The ... is %dn", num);
return 0;
}
void convert (long m) {
long count=-1, n=0;
while (0 < m) {
n = n*10 + m%2;
m = m / 2;
count++;
}
while (0 < count) {
printf ("%ld", n%10);
n = n / 10;
count--;
}
printf ("%ld", n%10);
return;
}
int main() {
long m;
scanf("%ld",&m);
printf(" The ... value is ");
convert (m);
printf ("n");
return 0;
}
代號
頁次
3
2
二、請說明下 PHP 程式設計的觀念。
Class Interface 的差異為何?請從可否宣告屬性、可否實例化、可
否有實作方法 3面相加以說明。5
若前端網頁以 HTML 程式上傳一個檔案到後端,請以 PHP 寫出後端
要處理的部分,包括檢查檔案是否上傳成功、檢查檔案是否存在(不
可覆蓋)、將上傳的檔案搬移到指定位置。15 分)
前端:
<form method="post" enctype="multipart/form-
data" action="upload.php">
<input type="file" name="to be uploaded">
<input type="submit" value="Upload">
</form>
後端:
<?php
. . .
?>
三、請說明下列程式設計概念的差異。(每小題 5分,共 20 分)
call-by-referencecall-by-value
請說明靜態及動態記憶體static memory allocation vs. dynamic memory
allocation)配置的主要差別。
請說明語法錯誤syntax error意錯誤semantic error行錯誤
run-time error的主要差別。
上述的錯誤,編譯程式過程中可以發現的是那一種錯誤(可複選)?
代號
頁次
3
3
四、超商預計發展合併集點卡程明如若有 n集點卡要合併
n-1 才能把點數全集中一張卡。2
1/10 (無條件
例如,若有 A, B, C 3 張集點卡要合併,且點數分別為 25, 30, 51
。若先合併 A, B再合併 C則會扣掉 3+6 點,因此合併後剩 97
這也剛好是最差合併策略下的合併總點數;但在最佳的合併策略下(先
合併 B, C,再合併 A,則可有 100 點。(每小題 15 分,共 30 分)
請寫 best_case() 式,計算 n張集點卡合併過後最多可有多少點數。
請寫 worst_case() 函式計算 n張集點卡合併過後最少可有多少點
#include <stdio.h>
int a[101], n; // 100 n
int best_case () {
...
}
int worst_case () {
...
}
int main () {
scanf ("%d", &n);
for (i=0; i<n; i++)
scanf ("%d", a[i]);
printf ("Best case: %d pointsn", best_case());
printf ("Worst case: %d pointsn", worst_case());
return 0;
}
收藏 ⬇️ 下載