15% I. Briefly answer the following questions. (1) What are the differences between DRAM and SRAM ? (2) What are the differences between mask ROM and PROM ? (3) What are the differences between PROM and EPROM ? (4) What are the differences between EPROM and EEPROM ? (5) What are the differences between compiler and interpreter? (6) What is a PCMCIA compliant device? (7) Explain overflow and underflow with examples. (3%) 15% II. 各 5% (1)說出要如何在本系做 HomePage? 包括 directory以及 files 及其存取權限設定(2.5%); 並舉例說明三個 HTML Tag 之功能。(2.5%) (2)舉例(寫成簡單procedure)說明Pascal語言中procedure/function parameters: pass by value 和 pass by reference 參數的差別。 (3)舉例(寫成兩個簡單函數)說明C語言中 static 和不是 static 的 local 變數之差別。 10% III. What is the output of each of the following programs? (a) Program xx3a(Output); var K,L: integer; function P ( X : integer ) : integer; var K: integer; begin K := K+1; L := X+1; P := X + L; X := X+1 end; function Q (var X : integer ) : integer; var K: integer; begin (*note that "var X" means X uses same address as it's argument*) K := K+1; L := L+1; Q := X + L; X := X+1 end; Begin (*main*) K := 1; L := 1; writeln(P(K):3,K:3,L:3); writeln(P(L):3,K:3,L:3); writeln(Q(K):3,K:3,L:3); writeln(Q(L):3,K:3,L:3); End. (b) program xx3b; var k:integer; var x:string[10]; (* 這只有 Turbo Pascal 認得 *) begin x := 'Ndv Xdar'; for k:= 2 to 6 do (* 注意是 2 to 6, 沒寫錯 *) if(x[k]<> ' ')then x[k]:= chr( ord(x[k]) + 1 ); writeln('=',x,'='); end. 10% IV.不使用內建的 Upcase()函數, 寫一個Turbo Pascal procedure可將傳入 的字串(string)中所有小寫字母都轉為大寫, 但其它character都不變, 當然是要能將該字串參數傳回來。 (寫成Procedure, 不是 function) 寫好後(7%), 再寫一可測試該procedure的主程式(3%)將三個含不同長度 之字串傳給它, 當然要印出叫用前後各字串內容。 Hint: Pascal 有函數 ord 和 chr 可用: ord('A') 會傳回 65 chr( 32 + ord('A') ) 會傳回 'a' Turbo Pascal procedure的字串參數要宣告為 string 才可接受任意長度之字串 Turbo Pascal 中字串s的長度可用 length(s) 取得 15% V. 寫一 Pascal或 C或C++ 程式, 先問 user 要算到小數點以下第幾位, 然後問 x, 讀入 x 並求出 x 的立方根到 user 要求那位後印出, 然後再問 x, 再...直到輸入的x是負的就停掉。 注意: (1) 一輸入負的就停掉, 不要計算, 包括第一次若輸入負數則立即停掉。 (2) 不用考慮輸入不正確數值會當掉程式的問題。 (3) 用 double 算就好, 若是 user 要求連double無法handle的準確度 則程式要能在適當的 loop 次數後停, 不要loop不完 (3) 印出的答案要較接近正確答案 例如2的立方根算到小數點以下第3位, 要印 1.260而不是 1.259 因為 1.260*1.260*1.260 比較接近 2 25% VI.Suppose that IEEE floating standard(IEEE 754/854) is used to represent single precision floating number. (Note that Exponent is excess 127) (a) What does "IEEE" stand for? 寫出中文和英文全稱 4%(中英文各2%) (b) What is "Little endian" ? What is Big endian? (2%) (c) Sun 工作站採用Big endian還是Little endian? (2%) (d) Convert the decimal number 2000.3 into binary (3%) (e) Dipict the 32-bit pattern for the decimal number 2000.3 in IEEE floating format. In addition to the binary representation, also give the hexadecimal representation of your answer(寫成8位數).(4%)(注意實數存電腦中並不存小數點) (f) Write a Pascal or C/C++ program that can find and print out the answer for (e). (10%) hint: 設一實數變數存放 2000.3 想辦法讓一32-bit整數變數與該實數共用相同位置 (可利用pointer, 或用 Pascal 的 variant record, 或 C 的 union) 然後把該整數的 bit pattern 印成二進位以及十六進位 25% VII. Consider the Fibnacci function FIB(n):=FIB(n-1)+FIB(n-2), (a) Suppose that FIB(0) is 3 and FIB(1) is 4 then what is the value of FIB(5)? (3%) (b) The following function FIB() is used to solve the problem for (a). Complete the following function FIB(n) using while loop. (5%) (No array variable allowed) (Note that Do NOT write it as recursive function. No credit in that case.) function FIB(n:integer): integer; var ans:integer; k1,k2,k3:integer; (* No any further variable allowed!*) begin if (N <= 0) then (*...*) (*... else ... else ...*) (*...using while loop to *) (*...complete this part... *) FIB:= ans; end; end; (c) 用中文說明該兔子問題的原意。 (3%) 要說明為何 FIB(0) 是 3, 而 FIB(1)是 4 是怎麼回事? (d) 若該兔子問題改為幼兔需兩個月才能長大為成兔(懷孕仍為一個月,) 也就是說每對 成兔在每個月候都會生出一對幼兔, 則其 recursive 公式應為如何? (4%) (e) 依據 (d), 假設 FIBN(0) 是 1 表示有一對幼兔, 請用 while loop 方式寫出可傳 回第 n 個月有幾對兔子的函數 FIBN(n:integer):integer; 注意, 仍不能寫成 recursive function. (5%) (f) 用 C 或 C++ 且以 recursive 方式重寫(e)的程式 (5%) 15%VIII. 用 Pascal 或 C/C++ 寫出一個整數函數idstatus(id)可檢查所傳入的字串id是否為 台灣人民的合法身份證字號: 若合法則傳回 0, 否則傳回一不是 0 之值表示不同錯誤原因: 1 = 表示第一個字不是英文字母 2 = 表式第二字非1也非2 (1是男生, 2是女生) 4 = 表式字串長度不為 10 8 = 表示第一和第二個字之外含有非數字符號(第二字為非數字算在錯誤2) 16 = 表示檢查碼雖為數字但不符編碼規則 注意, 除編碼規則外, 其它錯若同時都有要傳回其錯誤值和 例如, 第一字非字母且其它含非數字則傳回9 注意字母大寫和小寫都算對! 先用中文說明身份證號碼之編碼方法(3%), 再寫出函數(9%)並舉例說明要如何 使用你寫的函數(3%)。 Hint: rule to convert the "letter" to 2 digit numbers: A ==> 10, B ==> 11, ... H ==>17, J ==> 18, K ==> 19, LMN PQRSTUV XYWZIO ==> 10..35