110年 高普考 普通考試 資訊處理 程式設計概要 試卷

pdf
181.59 KB
4 頁
windows10
侵權投訴
加載中. ..
PDF
110年公務人員普通考試試題
資訊處理
程式設計概要
考試時間
1
小時
30
座號
禁止使用電子計算器。
本科目除專門名詞或數理公式外,應使用本國文字作答。
代號
45150
頁次
一、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 分)
l>
Input<span class="_"> </span>D<span class="_ _8"></span>ata
if(is_null( (I) )||( (I) === "")){
?>
method=" (II) " action="input.php">

Your name: type="text" name="name">

type="submit" value="OK">
}
else {
?>

Thank you, (III) $_GET['name'] ?>p>

}
?>
代號
45150
頁次
二、程式語 C的程式碼是由許多函式Function)組成。
#include
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("%dn", g(20, 10));
return 0;
}
請說明上述程式執行的結果。15 分)
請說明上述程式中 break continue 指令行的意義,並比較兩個指令
之功能差異。5
請說明 C程式使用遞迴(Recursion)與迴圈(Loop,在時間、空間
與程式可讀性之優缺點。5分)
代號
45150
頁次
三、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();
}
}
代號
45150
頁次
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();
}
}
四、程式語 C可使用不同資料型別的變數存取資料與傳遞函式的參數
#include
#include
#include
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 %dn", &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 %dn", animal, *z, z[1], z[2], x);
myFunction(p, x, q, animal);
printf("after:%s %d %d %d %dn", animal, z[0], z[1], z[2], x);
return 0;
}
請說明上述程式執行的結果。15 分)
請說明比較 C程式宣告一個陣列時如上述程式變數 yz使用一般
陣列變數與指標變數的異同。5分)
請說明比較C程式語言中函式參數傳遞方法傳值呼叫call by value
與傳址呼叫(call by address)異同。5分)
收藏 ⬇️ 下載