lawpalyer logo

資訊處理 96 年程式語言概要考古題

民國 96 年(2007)資訊處理「程式語言概要」考試題目,共 10 題 | 資料來源:考選部

0 題選擇題 + 10 題申論題

請用中文描述下列文法所定義的語言:(20 分) <S> -> <A> <B> <C> <A> -> a<A> | a <B> -> b<B> | b <C> -> c<C> | c
有些語言是靜態型態(static typed)語言,如C 和Java。靜態型態語言的程式必須 宣告(declare)變數(variables)的型態(types)。有些語言是動態型態(dynamic typed)語言,如Lisp 和Prolog。動態型態語言的程式不需宣告變數的型態。請敘 述這兩類語言的優缺點。(20 分)
命令語言(imperative language)中的變數(variable)是電腦什麼元件的抽象描述? (10 分)
一個語法分析樹(parse tree)可以用來描述一個程式結構(construct)的語法分析 過程。根據下列文法 E → T | T + E T → F | F * T F → digit | ( E ) 這裡E、T 和F 是非終端符號(nonterminals),而 +、*、(和)是終端符號 (terminals)。請畫出運算式7 * (4 + 6) + 9 的語法分析樹。(15 分)
有下列JAVA 程式片段,請寫出執行結果。(20 分) String s4 = new String(“restful”) ; String s5 = new String(“restful”) ; String s6 = new String(“peaceful”) ; String s7 = s4 ; String s8 = “restful” ; String s9 = “restful” ; System.out.println(s4.equals(s5)) ; System.out.println(s4.equals(s6)) ; System.out.println(s4 == s5) ; System.out.println(s4 == s7) ; System.out.println(s4 == s8) ; System.out.println(s8 == s9) ;
執行下列C 語言程式: int *f(int x) { int y; y = x + 10; return &y; } int g(int y) { int x; x = y – 10; return x; } void main( ) { int *x, y; x = f(10); y = g(*x); printf(“%d %d\n”, *x, y); } 請畫出程式執行時的活動記錄(activation record)的變化。(10 分) 程式的輸出為何?(5 分) 為什麼?(5 分) 96 年交通事業公路人員升資考試試題 代號: 級 別: 佐級晉員級 科 別: 資訊管理、資訊處理 全一張 (背面) 20450、21750
(10) 10 分
有下列Java 虛擬碼片段: try {statement-list1} catch (exception-class1 variable1) {statement-list2} catch (exception-class2 variable2) {statement-list3} finally {statement-list4} 若try 區段無exception 產生,請依序指出那些statement list 會被執行。(10 分) 若try 區段有exception-class1 的exception 產生,請依序指出那些statement list 會 被執行。(10 分) 若try 區段有exception-class2 的exception 產生,請依序指出那些statement list 會 被執行。(10 分) 96 年公務人員特種考試關務人員考試試題 代號: 科 別: 資訊處理 全一張 (背面) 60350
C 程式語言提供三種迴圈(loop):for-迴圈、while-迴圈和do-while-迴圈。請說明 這三種迴圈使用的時機。(15 分)
輸入34 於下列getBinary 遞迴程式,請問回傳值為何?(20 分) /** getBinary returns a String representation of the binary * equivalent of a specified integer n. * The worstTime(n) is O(log n).* * @param n – an int in decimal notation. * @return the binary equivalent of n, as a String * @throws IllegalArgumentException, if n is less than 0 */ public static String getBinary (int n) { if (n < 0) throw new IllegalArgumentException( ); if (n <= 1) return Integer.toString (n); return getBinary (n / 2) + Integer.toString (n % 2) } // getBinary
使用任一程式語言 應用遞迴(recursion)寫一個利用二分搜尋法(binary search)在一個由小至大排 列好的整數陣列中搜尋的函式(function)。(15 分) 應用迴圈(loop)寫一個利用二分搜尋法在一個由小至大排列好的整數陣列中搜 尋的函式。(15 分)