民國112年 地方四等 資訊處理 程式設計概要考古題

民國112年 地方四等 資訊處理 程式設計概要收錄考選部官方試題,共 4 題可線上瀏覽,考選部未公告本科目答案。

官方資料

題目與答案

第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 %d\n", 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; }

第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 . . . ?>

第3題

請說明下列程式設計概念的差異。(每小題5 分,共20 分) 請說明傳址(call-by-reference)與傳值(call-by-value)參數傳遞的差異。 請說明靜態及動態記憶體(static memory allocation vs. dynamic memory allocation)配置的主要差別。 請說明語法錯誤(syntax error)、語意錯誤(semantic error)、執行錯誤 (run-time error)的主要差別。 上述的錯誤,編譯程式過程中可以發現的是那一種錯誤(可複選)?

第4題

超商預計發展合併集點卡程式,說明如下。若有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 points\n", best_case()); printf ("Worst case: %d points\n", worst_case()); return 0; }