阿摩線上測驗
登入
首頁
>
程式語言
> 95年 - 95 關務特種考試_四等_資訊處理:程式語言概要#34397
95年 - 95 關務特種考試_四等_資訊處理:程式語言概要#34397
科目:
程式語言 |
年份:
95年 |
選擇題數:
0 |
申論題數:
5
試卷資訊
所屬科目:
程式語言
選擇題 (0)
申論題 (5)
一、寫出下面 C 程式的執行結果。(執行結果共有五列輸出,請標明每列輸出的列號與 內容)(20 分) #include
int x=5; void f(int x) { printf(“%d ”,x++); } void g(void) { static int x = 0; printf(“%d ”,x++); } void main() { printf(“%d ”,++x); { int x = 4; printf(“%d ”,x++); } g(); f(x); g(); }
二、完成下面找到 a,b,c 三個整數裡中位數的 C 函式。例如 a 為 5,b 為 6,c 為 3, 則 a 是中位數,find_median 會回傳 5。(20 分) int find_median(int a, int b, int c) { int median; if(a <= b) { if (___(1)___) { median = a; } else { median = ____(2)____; } } else { if ( b>= c) { median = ____(3)____; } else { median = ____(4)____; } } return median; // 傳回中位數 }
三、請說明物件導向式程式設計裡繼承(inheritance)的概念與好處。(20 分)
四、寫出下面 C++程式的執行結果。(執行結果共有五列輸出,請標明每列輸出的列號 與內容)(20 分) #include
class A { private: static int count; public: A() {++count; }; virtual void methodOne() { cout << "A's methodOne" << endl; } void methodTwo() { cout << "A's methodTwo" << endl; } static void numberOfinstanceOfA() { cout<< “# of A’s instances:” << count << endl; } ~A() { --count; } }; class B : public A{ public: B() {}; virtual void methodOne() { cout << "B's methodOne" << endl; } void methodTwo() { cout << "B's methodTwo" << endl; } }; int A::count = 0; void main() { A::numberOfinstanceOfA(); A *ptr = new B(); ptr->methodOne(); ptr->methodTwo(); A::numberOfinstanceOfA(); delete ptr; A::numberOfinstanceOfA(); }
五、寫出下面 Java 程式的執行結果。(執行結果共有五列輸出,請標明每列輸出的列號 與內容)(20 分) import java.io.*; public class Main { public static void main(String [] args) { int x = 5; for(int i = 0; i< x; i++){ for(int j = i; j < x; j++){ System.out.print(j); } System.out.println(); } } }