lawpalyer logo

資訊處理 106 年程式設計概要考古題

民國 106 年(2017)資訊處理「程式設計概要」考試題目,共 17 題 | 資料來源:考選部

0 題選擇題 + 17 題申論題

試問以下C++程式若輸入believe,則輸出結果各為多少?(25 分) #include<iostream> using namespace std; char* POP_A(char*d){ char*p=d; for(;*p;p++) *p=*(p+1); return d; } char* POP_B(char*d){ char*p=d; while(*p) p++; *(p-1)=0; return d; } int main(){ char d[1024]; cin>>d; POP_A(d); cout<<d<<endl; POP_A(d); cout<<d<<endl; POP_B(d); cout<<d<<endl; POP_B(d); cout<<d<<endl; return 0; }
用C 語言撰寫一個函式void bit_pattern(unsigned num),它能將一個32-bit 整數數值0 與1 的bit pattern 列印出來。例如數值是444 所列印出來的bit pattern 應 該是00000000 00000000 00000001 10111100?(15 分)
就下列Java 程式片斷中加入一個for 迴圈,使其印出右側結果。(15 分) public class AllNumbers number square cube 0 0 0 1 1 1
試問下列C++程式碼的輸出為何?(25 分) #include <iostream> using std::cout; using std::endl; int main() { int a[10][20][30][40]; cout<<"a="<<a[5][5]-a[0][0]<<endl; cout<<"b="<<&a[5][5]-&a[0][0]<<endl; cout<<"c="<<a[5]-a[0]<<endl; } 106年特種考試地方政府公務人員考試試題 全一張 (背面) 等 別: 四等考試 類 科: 資訊處理 科 目: 程式設計概要
用C 語言撰寫一個函式,能反轉一單向鍊結串列(singly linked list): struct node* reverse(struct node *h)。 單向鍊結串列範例如圖一。(25 分) 函式內請勿複製結點,其中節點的資料結構為 struct node { int d; struct node *next; } 圖一、單向鍊結串列範例
4 8
下列C++程式執行後,試問A、B、C 值分別為多少?(25 分) int F2(int &f, int f1) { int sum = (f1 + f++); return sum; } void F1(int &a, int b, int* c) { for (int i = a, j = b; j >= 0; i++, j--) { if (c[j] % 2 == 0) c[j] = F2(a, b); else c[j] = F2(b, a); } } void main() { int A = 5, B = 3, C[4] = { 1,4,7,6 }; F1(A, B, C); system("pause"); }
用C 語言撰寫反覆結構(for-loop)及遞迴(recursive)2 個版本的函式,分別計算出 費式數列(Fibonacci Sequence):int F(int n),其數學定義如下: F0 = 0, F1 = 1, and Fn = Fn–1 + Fn–2 for n >1。(25 分) 例如: 呼叫 F(6) 計算出 8 and F(7) 計算出13。
(6)
(7)
9 27
試問下列C++程式碼逐一執行後,Value 與list 輸出結果各為多少?(25 分) void swap_ref(int &a, int &b) { int temp; temp = a; a = b; b = temp; } void swap(int a, int b) { int temp; swap_ref(a, b); temp = a; a = b; b = temp; } void main() { int Value = 5, list[3] = { 1,2,3 }; swap(Value + list[2]++, ++list[0]); swap_ref(list[0], ++list[2]); }
在物件導向語言(JAVA or C++),宣告變數為public, private, protected,其差異性為 何?(10 分) 3
16 64
8 h h 反轉 8 5 3 106年公務人員普通考試試題 全一張 (背面) 類 科:資訊處理 科 目:程式設計概要 五、AJAX 即「Asynchronous JavaScript and XML」(非同步的JavaScript 與XML 技術) 為一重要且普遍用來產生高互動網頁的技術,可讓使用者在執行AJAX 網頁時就像 在執行桌上電腦程式(desktop application)一樣順暢(如圖二)。 請說明AJAX 三個主要技術為何並說明其目的。(9 分) 並請以以下網頁為例,當使用者輸入字元後的網頁反應,說明傳統非AJAX 與AJAX 網頁不同之處。(10 分) 請說明網頁程式碼中‘xmlhttp.readyState==4’,‘xmlhttp.status==200’ 及‘"gethint.php?q="+str’代表的意義為何?(6 分) <html lang="en-US"> <head><script> function showHint(str) { if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } else { var xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } }; xmlhttp.open("GET","gethint.php?q="+str, true); xmlhttp.send(); } } </script></head> <body> <div class="w3-example"> <h3>Example</h3> <form action="javascript:void(0);" class="w3-code-result"> <p><b>Start typing a name in the input field below:</b></p> <p> Name: <input type="text" id="txt1" onkeyup="showHint(this.value)" size="20"> &nbsp;&nbsp;Suggestions: <span id="txtHint"></span> </p> </form> </div></body></html> 圖二、2 個AJAX 範例程式執行結果
(0)
25 125
36 216
49 343
64 512 9 81 729 10 100 1000 { public static void main( String[] args ) { // print a header for the table System.out.printf( "%s\t%s\t%s\n", "number", "square", "cube" ); // 加入一個for 迴圈 // // } // end main } 二、承題一,試於for 迴圈內加入if 判斷敘述,以顯示下列結果:(10 分) number square cube 3 9 27 6 36 216 9 81 729 三、下列程式能將輸入的字串input=”abcdef”,反向列印為”fedcba”。試以遞迴的方式撰 寫副程式stringReverseHelper,且其參數宣告必須與stringReverse 方法內的呼叫一 致。(25 分) public class Reverse { public static void stringReverse( char[] array ) { stringReverseHelper( array, 0 ); System.out.println(); } //stringReverseHelper 副程式的放置處 public static void main( String args[] ) { String input = "abcdef"; stringReverse( input.toCharArray() ); } // end main } // end class Reverse 106年公務人員特種考試警察人員、一般警察 人員考試及106年特種考試交通事業鐵路 人員、退除役軍人轉任公務人員考試試題 全五頁 第二頁 考試別: 鐵路人員考試 等 別: 員級考試 類科別: 資訊處理 科 目: 程式設計概要 四、下列網頁按button 鍵前、後瀏覽器顯示的結果為何?(10 分) <!DOCTYPE html> <html> <body> <h2>What Can JavaScript Do?</h2> <p id="demo">JavaScript can change HTML content.</p> <button type="button" onclick='document.getElementById("demo").innerHTML="Hello JavaScript!" '>Click Me!</button> </body> </html> 五、根據下列程式回答問題: Employee, HourlyEmployee, SalariedEmployee 三個類別的關係為何?(5 分) 試指出一個建構子,並說明它的作用。(5 分) 試說明SalariedEmployee 中super(n)的作用。(5 分) 試指出多型(polymorphism)出現的地方。(5 分) 執行PayrollSystemTest 後印出的結果為何?(10 分) public abstract class Employee { private String name; public Employee( String n ) { name = n; } public void setName( String str ) { name = str; } public String getName() { return name; } @Override public String toString() { return String. format( "%s", getName() ); } public abstract double earnings(); } (請接第三頁) 106年公務人員特種考試警察人員、一般警察 人員考試及106年特種考試交通事業鐵路 人員、退除役軍人轉任公務人員考試試題 全五頁 第三頁 考試別: 鐵路人員考試 等 別: 員級考試 類科別: 資訊處理 科 目: 程式設計概要 (請接第三頁) public class HourlyEmployee extends Employee { private double wage; // wage per hour private double hours; // hours worked for week public HourlyEmployee( String n, double hourlyWage, double hoursWorked ) { super( n ); setWage( hourlyWage ); setHours( hoursWorked ); } public void setWage( double hourlyWage ) { if ( hourlyWage >= 0.0 ) wage = hourlyWage; else throw new IllegalArgumentException("Hourly wage must be >= 0.0" ); } public double getWage() { return wage; } public void setHours( double hoursWorked ) { if ( ( hoursWorked >= 0.0 ) && ( hoursWorked <= 168.0 ) ) hours = hoursWorked; else throw new IllegalArgumentException("Hours worked must be >= 0.0 and <= 168.0" ); } public double getHours() { return hours; } @Override public double earnings() { if ( getHours() <= 40 ) // no overtime return getWage() * getHours(); else return 40 * getWage() + ( getHours() - 40 ) * getWage() * 1.5; } @Override public String toString() { return String. format( "hourly employee: %s\n%s: $%,.2f; %s: %, .2f", super.toString(), "hourly wage", getWage(),"hours worked", getHours() ); } } (請接第四頁) 106年公務人員特種考試警察人員、一般警察 人員考試及106年特種考試交通事業鐵路 人員、退除役軍人轉任公務人員考試試題 全五頁 第四頁 考試別: 鐵路人員考試 等 別: 員級考試 類科別: 資訊處理 科 目: 程式設計概要 public class SalariedEmployee extends Employee { p rivate double weeklySalary; public SalariedEmployee( String n, double salary ) { super( n ); setWeeklySalary( salary ); } public void setWeeklySalary( double salary ) { if ( salary >= 0.0 ) weeklySalary = salary; else throw new IllegalArgumentException( "Weekly salary must be >= 0.0" ); } public double getWeeklySalary() { return weeklySalary; } @Override public double earnings() { return getWeeklySalary(); } // end method earnings @Override public String toString() { return String. format( "salaried employee: %s\n%s: $%,.2f", super.toString(), "weekly salary", getWeeklySalary() ); } // end method toString } // end class SalariedEmployee public class PayrollSystemTest { public static void main( String[] args ) { // create subclass objects SalariedEmployee salariedEmployee = new SalariedEmployee( "Smith", 800.00 ); HourlyEmployee hourlyEmployee = new HourlyEmployee( "Price", 16.75, 40 ); System.out.println( "Employees processed individually:\n" ); System.out.printf( "%s\n%s: $%,.2f\n\n", salariedEmployee, "earned", salariedEmployee.earnings() ); System.out.printf( "%s\n%s: $%,.2f\n\n",hourlyEmployee, "earned", hourlyEmployee.earnings() ); Employee[] employees = new Employee[ 2 ]; employees[ 0 ] = salariedEmployee; employees[ 1 ] = hourlyEmployee; for ( Employee currentEmployee : employees ) { S ystem.out.println( currentEmployee ); System.out.printf( "earned $%, .2f\n\n", currentEmployee.earnings() ); } // end for } // end main } // end class PayrollSystemTest (請接第五頁) 106年公務人員特種考試警察人員、一般警察 人員考試及106年特種考試交通事業鐵路 人員、退除役軍人轉任公務人員考試試題 全五頁 第五頁 考試別: 鐵路人員考試 等 別: 員級考試 類科別: 資訊處理 科 目: 程式設計概要 (請接第五頁) 六、說明瀏覽器開啟下列網頁後顯示的訊息與可能的互動。(10 分) <!DOCTYPE html> <html> <body> <p>Creating a JavaScript Object.</p> <p id="demo"></p> <p>Show something.</p> <script> var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}; window.alert( person.firstName + " is " + person.age + " years old."); </script> </body> </html>