熱門推薦罰單破解實戰交通警察名師 25 年經驗,親授警察臨檢、檢舉魔人、科技執法、車禍糾紛的執法邏輯看課程介紹
購物車我的課程我的書籤免費註冊
資訊處理·106·程式設計概要1/8

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

8 題申論題資料來源:考選部下載 .txt
跨年同科91-115

題目為考試當年公告版本,實務標準請以現行規範為準。

試題8
106
1

試問以下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; }

106
2

試問下列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年特種考試地方政府公務人員考試試題 等 別: 四等考試 類 科: 資訊處理 科 目: 程式設計概要

106
3

下列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"); }

106
4

試問下列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]); }

106
5

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);" 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 範例程式執行結果
106
6

36 216

106
7

49 343

106
8

64 512 9 81 729 10 100 { 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>

同年其他科目106 · 29