程式語言
5
0
0
全文
(2) 公職王歷屆試題 (104 地方政府特考) 方法: binding 的差別與優缺點。 Java Script 的 syntax codes,請問執行 subl 之後,最後 x 的輸出(在 sub2)為 多少?請根據上述三種 binding 分別作答。 function sub1() { var x; function sub2() {altert(x);} // 輸出 x function sub3() {var x; x=3; sub4(sub2);} function sub4(subx) {var x; x=4; subx();} x=1; sub3();}; 【擬答】: :通常副程式變數取值都是用 shallow binging,副程式中如果沒有定義變數 ,就參考執行副程式的敘述當時環境的變數值 優點:執行程式時效率較高 缺點:程度可判讀性低,除錯不易 :副程式中如果沒有定義變數,就參考呼叫副程式的那一區取變數值 優點:可讀性高除錯容易 缺點:使用時因值是被設定住的較無彈興 -hoc binding:副程式中如果沒有定義變數,會參考呼叫副程式時的狀況來設定變數值 優點:可依實際狀況動態決定 缺點:程式效能較不好 Shallow binging:4 Deep binding:1 Ad-hoc binding:3. 公 職 王. 四、函數 f(n)定義如下:f(1) = 1, f(0) = 0, f(n) = f(n-2) + 2f(n-1),請問 f(5)等於多 少? 【擬答】: F(2)=f(0)+f(1)=0+1=1 F(3)=f(1)+f(2)=1+1=2 F(4)=f(2)+f(3)=1+2=3 F(5)=f(3)+f(4)=2+3=5 五、對於字串的長度,不同的語言有不同的設計方式,包括 static length string、limited dynamic length string、dynamic length string: Java、C 和 C++這三種語言,它們對字串長度設計的方式各採取那種方式或混和? 【擬答】: static length string:當宣告一個字串時,將該字串長度固定,使用者只可輸入該長度的字串 limited dynamic length string:當宣告一個字串時,將該字串長度固定,但使用者可輸入小於 或等於該長度的字串 dynamic length string:當宣告一個字串時,不將字串長度固定,依當時實際狀況決定 JAVA:static length string 與 dynamic length string C:static length string 與 limited dynamic length string C++:static length string 、limited dynamic length string 與 dynamic length string. 共5頁 第2頁. 全國最大公教職網站 http://www.public.com.tw.
(3) 公職王歷屆試題 (104 地方政府特考) 六、給定下列的文法(Grammar):. 請畫出右列字串:A=((A*B)+C*A),所對應 right-most derivation sequence 與對應的分析 樹(parse tree)。 【擬答】: <assign> <id>= <expr> <id>= (<expr>) <id> = (<expr>*<id>) <id> = (<expr>*A) <id> = (<expr>+<id>*A) <id> = (<expr>+C*A) <id> = ((<expr>)+C*A) <id> = ((<expr>*<id>)+C*A) <id> = ((<expr>*B)+C*A) <id> = ((<id>*B)+C*A) <id> = ((A*B)+C*A) A = ((A*B)+C*A) <assign> | <id>=<expr> A. =(<expr>) | <expr>*<id> | | <expr>+<id> A | | (<expr>) C | <expr>*<id> | | <id> B | A. 公 職 王. 七、請計算下列式子最後的 y 值: int x=3, y=2; y*=++x 3; int x=3, y=2; y/=x++; int x=10, y=1; y=x++ --y; int x=10, y=1; y/=++x y--; int y=0; for(int k=0; k<10; y+=k) {if(++k==6)continue; k++;} 【擬答】: int x=3, y=2; y*=++x 3;. 共5頁 第3頁. ANS:14. 全國最大公教職網站 http://www.public.com.tw.
(4) 公職王歷屆試題 (104 地方政府特考) y=2; y/=x++;. ANS:0 ANS:10 ANS:-1. --y; --; for(int k=0; k<10; y+=k) {if(++k==6)continue; k++;}. 八、若採取二種不同參數傳遞的方法:pass by reference、pass by value result,執行下列程 式,則 x 與 y 的值各為多少? int x=1, y=3; void fun(int a, int b); void main() { int x=2; fun(x,y); printf(“x=%d,y=%d”,x,y); } void fun(int a, int b){a=b+x; b=a+y;} 【擬答】: pass by reference:X=4 Y=7 pass by value result:X=4. 公 職 王. Y-=7. 如果有兩個整數 x,y,請寫出相對應的副程式碼,使得這兩數可以做交換。 Tc[10];int m=3, n=2;(T 為某種 type,可能為 int、float、double 等),請寫出相對 應的副程式碼 swap,當呼叫形式為 swap(c, m, n),可讓 c[m]跟 c[n]的值做交換,即使 T 的型態不同,此程式一樣可以正確處理。 【擬答】: Void swap(&x,&y) {int t=y Y=x; X=t; }. Main() { double a[]={1,2,3,4,5,6,7,8,9,10} Swap (a,3,6) } Void swap(*x,int m int n) { *x=c[m]; C[m]=c[n]; C[n]=*x }. 十、利用 template 的概念,寫出一個函數 power(x,n)可以計算 xn,不管 x 為實數、整數或自然 數,但假設 n 為整數。(10 分) 【擬答】: Template <class A>. 共5頁 第4頁. 全國最大公教職網站 http://www.public.com.tw.
(5) 公職王歷屆試題 (104 地方政府特考) T power(A x,int n) { if(n==0){return 1} If (n>0) {s=1 for (i=1;i<=n,i++) { s=s*i} Rerurn s } If (n<0) {n=-n; S=power(x,n) S=1/s Return s }. 共5頁 第5頁. 公 職 王 全國最大公教職網站 http://www.public.com.tw.
(6)
相關文件
依獎懲及 法定程序 予以書面 懲處 暫時讓學 生與其他 同學保持 距離..
第二級失能 生活補助金 滿第一年 15萬元 11.25萬元 滿第二年 20萬元 15.00萬元 滿第三年 25萬元 18.75萬元 滿第四年 30萬元
Instruction Set ...1-2 Ladder Diagram Instructions...1-2 ST Statement Instructions ...1-2 Sequence Input Instructions ...1-2 Sequence Output Instructions ...1-3 Sequence
General overview 1-2–1-3 Reference information 6-1–6-15 Emergency Power Off button 6-11 Focusing the video image 4-3 Foot Switches 6-14. General Overview 1-2
[r]
如圖,已知平行四邊形 EFGH 是平行四邊形 ABCD 的縮放圖形,則:... 阿美的房間長 3.2 公尺,寬
Quality kindergarten education should be aligned with primary and secondary education in laying a firm foundation for the sustainable learning and growth of
[r]