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

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

官方資料

題目與答案

第1題

針對以下Java 程式,執行後輸出為何?(25 分) public class Count { public static int A(int x) { if (x < 20) x = A(x+5) + B(x); return x; } public static int B(int x) { System.out.print("*"); return 3 * x; } public static int C(int x) { System.out.print("*"); return 3 * A(x-3); } public static boolean D(boolean x, boolean y) { return ((x || !y) || (x && y)); } public static boolean E(boolean x, boolean y) { return (!x && (x && y)); } public static void main(String[] args) { System.out.println(A(3)); // (I) System.out.println(B(3)); // (II) System.out.println(C(3)); // (III) System.out.println(D(true, true)); // (IV) System.out.println(E(true, false)); // (V) } }

第2題

以下JavaScript 程式,其功能為驗證輸入密碼是否合法,其合法規則為: ⑴密碼不為空; ⑵密碼長度必須是6 或7 或8; ⑶密碼包含至少一個大寫與一個小寫英文字母; 若違反規則⑴,跳出視窗顯示"Empty",若違反規則⑵,跳出視窗顯示"6~8char", 若違反規則⑶,跳出視窗顯示"Uppercase and lowercase",若無違反規則, 則在頁面密碼後面顯示「ok」。 完成程式碼空格(I)、(II)、(III)、(IV)、(V),使執行正確。(25 分) <html> <head> <title> Verification</title> </head> <script> function verifyPass() { var password = document.getElementById("password"). (I) ; if(password == (II) ) { alert("Empty"); return false; } else if ((password.length < (III) ) || (password.length > (IV) )) { alert("6~8 char"); return false; } else if (!(password.match(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/))) { alert("Uppercase and lowercase"); return false; } else { document.getElementById("M"). (V) = "ok"; return false; } } </script> <body> <h1 style="color:blue">Password</h1> <h3>Password Verification </h3> <form onsubmit ="return verifyPass()"> <td> Enter Password : </td> <input type = "password" id = "password" value = ""> <span id = "M" style="color:red"> </span> <br><br> <input type = "submit" value = "Submit"> </form> </body> </html>

第3題

針對以下C 程式,其輸出為下列表格,說明compress 函式的功能,並完 成程式碼(I)、(II)、(III)、(IV),使之執行正確。(25 分) 程式輸出 2 4 6 5 2 4 6 6 5 4 1 4 8 3 5 4 6 #include <stdio.h> #define SIZE 10 int op(int data[][SIZE], int x, int y, int n) { int value = 0; for (int i = x; i < x+n; i++) for (int j = y; j < y+n; j++) value = value + data[i][j]; return value/(n*n); } void print(int target[][SIZE], int size) { for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) printf("%d ", target[x][y]); printf("\n"); } } void compress(int data[][SIZE], int (I) [][SIZE], int size, int n) { int cSize = (II) ; for (int x=0; x< cSize; x++) for (int y=0; y<cSize; y++) target (III) =op(data, x*n, y*n, n); (IV) (target, cSize); } int main() { int data[][SIZE] = {{1, 2, 3, 4, 5, 6}, {3, 4, 5, 6, 7, 8}, {5, 6, 1, 2, 3, 4}, {7, 7, 9, 9, 5, 5}, {2, 2, 4, 4, 8, 8}, {1, 1, 5, 5, 9, 9}}; int target[SIZE][SIZE]; compress(data, target, 4, 2); compress(data, target, 6, 2); compress(data, target, 6, 3); return 0; }

第4題

針對以下C#程式,其輸出為80, 85,完成程式碼(I)、(II)、(III)、(IV)、 (V),使之執行正確。(25 分) public (I) class Score { protected int [] data; protected int value; public Score(int [] d) { data = new int[d.Length]; value = 0; for (int i = 0; i < d.Length; i++) data[i] = d[i]; } private void print() {Console.WriteLine(""+value); } protected abstract void compute(int[] weight); public void getValue(int[] weight) { compute(weight); (II) (); } } public class WeightScore:Score { public WeightScore(int [] data): (III) (data) {} protected (IV) void compute(int [] weight) { int totalWeight = 0; for (int i = 0; i < data.Length; i++) { value = value + data[i] * weight[i]; totalWeight = totalWeight + weight[i]; } value = value / (V) ; } } public class Test { static void Main(string[] args) { int[] data1 = {90, 80, 70, 85}; int[] data2 = {90, 80, 80, 85}; int[] weight1 = {1, 2, 3, 4}; int[] weight2 = {4, 2, 1, 3}; Score x = new WeightScore(data1); Score y = new WeightScore(data2); x.getValue(weight1); y.getValue(weight2); } }