2、 請以黑色或藍色鋼筆或原子筆書寫,並以橫式書寫(由左至右,由上而下)。
一、選擇題 (每題 4 分,共 40 分)
1. 在 Java 語言中,請問下列何者資料型別的變數,所需的儲存空間最少?
(a) char (b) float (c) double (d) int
2. 請問下列何者非 C 語言的關鍵字(key word)?
(a) const (b) default (c) dynamic (d) continue
3. 在 C 語言中,請問以下函數的設計中何者為錯誤?
(a) int Func1( ) { int a = 3; return a+2; } (b) int Func2( ) { return 5; }
(c) int Func3( ) { return 2+3; } (d) int Func4( ) { int x = 5; return; }
4. 編譯程式(Complier)無法找出以下何種錯誤?
(a) 語法錯誤 (b) 邏輯錯誤 (c) 資料型別不合 (d) 變數未定義
5. 在程式設計中,我們常利用檔案作為資料儲存之用。若現在有一組資料,其使用頻率 不高,但一使用則幾乎所有資料皆能被存取,請問此時應以何種結構之檔案儲存較為適 當?
(a) 索引檔 (b) 隨機檔 (c) 循序檔 (d) 執行檔
6. 一次只能讀取、翻譯,並執行一列程式敘述的程式為何?
(a) 鏈結程式( Linker) (b) 編譯程式(Compiler) (c) 直譯程式(Interpreter) (d)組合程式 (Assembler)
7. 在 C 語言中,宣告一整數陣列如下:int A={1, 2, 3, 4, 5}; 請問 A[3]的值為多少?
(a) 2 (b) 3 (c) 4 (d) 5
8. 請問 Android 的手機應用程式,採用以下何種程式語言開發?
(a) C# (b) C++ (c) Object C (d) Java
9. 若採用快速排序法 (quick sort) 執行 n 個資料的排序,請問其平均的執行效率為何?
(a) O(n) (b) O(log n) (c) O(n2) C (d) O(n log n)
10. 根據下列的程式碼,當 n=2 時,其輸出結果為何?
(a) b (b) ab (c) bc (d) bcd
switch (n) { case 1:
printf("a");
case 2:
printf("b");
case 3:
printf("c");
break;
default:
printf("d");
break;
}
二、填空題 I (每題 5 分,共 20 分) 請寫出以下程式的執行結果:
(a)
#include <iostream.h>
class CShape {
public:
virtual void display() { cout << "Shape \n"; } };
class CEllipse : public CShape {
public:
virtual void display() { cout << "Ellipse \n"; } };
class CCircle : public CEllipse {
public:
virtual void display() { cout << "Circle \n"; } };
第 2 頁,共 5 頁
背面尚有試題
void main() {
CShape aShape;
CEllipse aEllipse;
CCircle aCircle;
CShape* pShape[3] = { &aShape, &aEllipse, &aCircle,};
for (int i=0; i< 3; i++) pShape[i]->display();
}
(b)
#include <iostream.h>
class CShape {
public:
void display() { cout << "Shape \n"; } };
class CEllipse : public CShape {
public:
void display() { cout << "Ellipse \n"; } };
class CCircle : public CEllipse {
public:
void display() { cout << "Circle \n"; } };
void main() {
CShape aShape;
CEllipse aEllipse;
CCircle aCircle;
CShape* pShape[3] = { &aShape, &aEllipse, &aCircle,};
for (int i=0; i< 3; i++) pShape[i]->display();
}
(c)
#include <stdio.h>
#define GetValue(a, b) (a >= b) ? a : b void main()
{
printf("%d\n", GetValue(17,46));
}
(d)
#include <stdio.h>
void swap(int a, int b) {
int tmp;
tmp = a;
a = b;
b = tmp;
}
void main() {
int x = 29, y =60;
swap(x ,y);
printf(" x = %d , y = %d", x , y);
}
三、填空題 II (每題 5 分,共 20 分)
(a) 在 PHP 網頁設計中,___________為一個小小的檔案,其儲存在使用者端的電腦上,
用來紀錄使用者的資訊用。
(b) 在物件導向程式設計中,___________為物件誕生後第一個執行,並且是自動執行的 函式,且其函式名稱必須要與類別名稱相同。
(c) 在程式設計中,___________為以一步一步追蹤程式碼及其執行結果的除錯(debug) 工具。
(d) 在 C++或 Java 程式語言中,所謂__________為多個相同名稱的函式,但參數個數不 同,或是參數型別不同。
第 4 頁,共 5 頁
背面尚有試題
四、簡答題 (每題 10 分,共 20 分)
1. 請設計一個遞迴(Recursive)函數, int fractional (int n),來計算階層函數 n!的值,其 中 n 為一正整數。
2. 請設計一個函式來計算兩個浮點數(float)的比值,float ratio(float a, float b),其中程式 中必須使用例外處理(exception handling)來防止分母為零(divided by zero)的問題產生。
第 1 頁,共 1 頁
2、 請以黑色或藍色鋼筆或原子筆書寫,並以橫式書寫(由左至右,由上而下)。
一、選擇題:
1. (a) 2. (c) 3. (d) 4. (b) 5. (c)
6. (c) 7. (c) 8. (d) 9. (d) 10. (c)
二、填充題 I:
(a) Shape, Ellipse, Circle (b) Shape, Shape, Shape (c) 46
(d) 29, 60 三、填充題 II:
(a) cookie
(b) 建構式(constructor) (c) Trace
(d) 函數多載(function overloading) 四、簡答題:
1.
Int factorial(int n) {
if (n == 1) return 1;
else
return n * factorial(n-1) ; }
2.
#include <iostream.h>
float ratio(float a, float b) {
try {
if (b==0)
throw “分母為零”
} catch (const char* message) { cout<<message;
}
return a/b;
}