資訊處理 95 年程式語言概要考古題(共 5 題) 資料來源:考選部歷屆試題|法律人 LawPlayer 整理 https://lawplayer.com/exam/information-processing/95-%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80%E6%A6%82%E8%A6%81 第 1 題 寫出下面C 程式的執行結果。(執行結果共有五列輸出,請標明每列輸出的列號與 內容)(20 分) #include int x=5; void f(int x) { printf(“%d\n”,x++); } void g(void) { static int x = 0; printf(“%d\n”,x++); } void main() { printf(“%d\n”,++x); { int x = 4; printf(“%d\n”,x++); } g(); f(x); g(); } 第 2 題 完成下面找到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 (______) { median = a; } else { median = ________; } } else { if ( b>= c) { median = ________; } else { median = ________; } } return median; // 傳回中位數 } 第 3 題 請說明物件導向式程式設計裡繼承(inheritance)的概念與好處。(20 分) 95 年公務人員特種考試關務人員考試試題 科 別: 資訊處理 第 4 題 寫出下面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(); } 第 5 題 寫出下面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(); } } } 題目為考試當年公告版本,實務標準請以現行規範為準。