民國110年 普通考試 資訊處理 程式設計概要考古題

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

官方資料

題目與答案

第1題

PHP 是網際網路應用系統常用之程式語言。 請寫出以下PHP 程式的執行結果,並說明得到此結果的原因。(10 分) <?php $a = array("a" => 1, "b" => 0); if($a["b"] == NULL) echo "null"; else echo "not null"; ?> 以下PHP 程式(檔名input.php)以瀏覽器初次執行會顯示右下畫面。 在「Your name」欄位輸入資料後按OK 鈕,會顯示輸入資料;若未輸 入資料按OK 鈕,則會再次顯示右下畫面。請完成程式(I)~(III) 指令,使程式正確執行上述功能。(15 分) <html> <head><title>Input Data</title></head> <?php if(is_null( (I) )||( (I) === "")){ ?> <form method=" (II) " action="input.php"> <p>Your name: <input type="text" name="name"></p> <input type="submit" value="OK"> </form> <?php } else { ?> <p>Thank you, <? (III) $_GET['name'] ?></p> <?php } ?> </html>

第2題

程式語言C 的程式碼是由許多函式(Function)組成。 #include <stdio.h> int memo[20][20], number=0; int B(int n, int k){ if((n >= 0)&&(k >= 0)&&(n >= k)) if((k == 0)||(k == n)){ memo[n][k] = 1; return 1; } else if(memo[n][k] > 0) return memo[n][k]; else{ memo[n][k] = B(n-1, k-1)+ B(n-1, k); number+=2; return memo[n][k]; } else return 0; } void f(int N, int M){ int sum=0; for(int i=1; i<=N; i++){ if(i>=10)break; if(i%3==0)continue; sum = sum + B(i, 2); } printf("%d %d ", sum, number); } int g(int N, int M){ if((N<=0)||(M<0))return 1; else return(M + N + g(M-2, N-3)); } int main(){ f(20, 10); printf("%d\n", g(20, 10)); return 0; } 請說明上述程式執行的結果。(15 分) 請說明上述程式中break 與continue 指令行的意義,並比較兩個指令 之功能差異。(5 分) 請說明C 程式使用遞迴(Recursion)與迴圈(Loop),在時間、空間 與程式可讀性之優缺點。(5 分)

第3題

Java 是常用的物件導向程式語言。 請寫出以下三個Java 程式的執行結果。(15 分) ⑴ class square { int edge; square(int e){ edge = e; } } public class app { public static void main(String args[]) { square s1 = new square(10); square s2 = new square(10); if(s1 == s2) System.out.print("Equal square"); else System.out.print("Not equal square"); } } ⑵ public class app { public static void main(String args[]) { int a[] = {1,2,3,4,5}; show(a); } public static void show(int i){ System.out.println(i); } public static void show(int b[]){ for(int i = 0; i < b.length; i++) System.out.print(b[i] + " "); } } ⑶ class Circle { protected double radius; Circle(double r){ radius = r; } void show(){ System.out.print(radius); } } class Coin extends Circle { private int value; Coin(double r, int v){ super(r); value = v; } void show(){ System.out.print(radius+" "+value); } } public class app { public static void main(String args[]){ Circle coin = new Coin(3.0, 10); coin.show(); } } 下列Java 程式之需求為:設定變數color 的值並輸出。請指出其編譯錯 誤原因,並針對該錯誤原因說明程式如何修正使之能正確執行。(10 分) class Car { private String color; void showcolor() { System.out.println(color); } } public class app { public static void main(String args[]) { Car c1 = new Car(); c1.color = "blue"; c1.showcolor(); } }

第4題

程式語言C 可使用不同資料型別的變數存取資料與傳遞函式的參數。 #include <stdio.h> #include <stdlib.h> #include <string.h> void myFunction(int *a, int b, int *c, char *d){ c[1] = *a + b; d[*c] = d[2]; b = 17; int *r = c + 1; c = a; *c = *a + 1; printf("during:%s %d %d %d %d\n", &d[1], *a, b, *c, *r); } int main(){ char animal[7] = "cat"; int x = strlen(animal); int z[3] = {1, 3, 5}; int * y =(int *)malloc(sizeof(int)*3); int *p = &x; int *q = &z[1]; q[1] = *p + 10; printf("before:%s %d %d %d %d\n", animal, *z, z[1], z[2], x); myFunction(p, x, q, animal); printf("after:%s %d %d %d %d\n", animal, z[0], z[1], z[2], x); return 0; } 請說明上述程式執行的結果。(15 分) 請說明比較C 程式宣告一個陣列時,如上述程式變數y、z,使用一般 陣列變數與指標變數的異同。(5 分) 請說明比較C 程式語言中,函式參數傳遞方法,傳值呼叫(call by value) 與傳址呼叫(call by address)異同。(5 分)