110年 高普考 高考三級 資訊處理 程式語言 試卷

pdf
183.45 KB
4 頁
windows10
侵權投訴
加載中. ..
PDF
110年公務人員高等考試三級考試試題
資訊處理
程式語言
考試時間
2
小時
座號
禁止使用電子計算器。
本科目除專門名詞或數理公式外,應使用本國文字作答。
代號
37940
頁次
4
1
一、語意分析Semantics Analysis對於程式語言的正確執行非常重要。
以下是 Java C++程式請說明程式編譯執行結果與其原因以及
程式指令之意義或影響。18 分)
Java 程式
static void test1(){
int n;
int [] x = new int[n];
}
Java 程式
static void test2(){
int n=0;
int [] x = new int[n];
}
Java 程式
static void test3(){
int n=0;
int [] x = new int[n];
x[0]=0;
}
C++程式
void test4(){
int n;
int x[n];
}
C++程式
void test5(){
int n=0;
int x[n];
x[0] =0;
}
C++程式
void test6(){
int n=0;
int *x = new int[n];
x[0] =0;
}
請說明 Java C++言在陣列宣告上的語意分析的方法,與其優缺
點。7分)
代號
37940
頁次
4
2
二、程式驗證的應用。
請說明「測試驅動發展方法Test Driven Development, TDD的概
及優點。7
有一 MySort 類別的方法 int[] binarySort(int data[])將陣列 data 內的
資料由小到大排序後回傳請依據 TDD 的概念設計測試案例10 分)
請以 Java/JUnit 語言完成以下測試程式(I~II8分)
@Test
public void testBinarySort(MySort (I) ){
int[] source = {2, 3, 5, 9, 12, 7};
int[] target = obj.binarySort(source);
for(int i=0; ie.length-1; i++){
assertTrue(target[i] < (II) );
}
}
三、建構股票交易資料庫(Stock,請寫出 SQL 指令。
客戶表格(Customer
客戶編號(cid
[整數、主鍵]
[自動增加]
客戶姓名(cname
[10 ]客戶帳戶餘額
balance
[整數、非空值]
客戶融資餘額
margin
[整數、非空值]
證券交易表格(StockTrade
id
[]
[]
sid
[]
price
[]
share
[]
cid
[]
造出 Customer, StockTrade 表格10 分)
CREATE TABLE Customer ( _____________________ );
CREATE TABLE StockTrade ( _____________________ );
查詢客戶姓名是"Tom"所有購買股票編號與購入總股數。5分)
撰寫 Store Procedure造出一個暫時的資料表 Report,含兩個整數資
料欄位(證券編號 sid, 券價格 price加入 10 筆資料根據證券
價格由小到大排序,查詢列出此 10 筆資料。10 分)
delimiter $$
CREATE PROCEDURE x()
BEGIN
DECLARE i INT DEFAULT 1;
____________________
END$$
代號
37940
頁次
4
3
四、程式例外處理的設計對於資訊系統的可靠性非常重要。
請完成以下 C++I~V指令處理兩數相除的例外狀況使
輸出為:15 分)
Exception:empty
Exception:not a number
Quotient:Exception:divided by zero
Quotient:2.4
#include
#include
#include
#define N 10
using namespace std;
class EmptyException:public exception {
public:
virtual const char* what()const throw(){
(I) ;
}
};
class NotNumberException:public exception {
public:
virtual const char* what()const throw(){
(II) ;
}
};
class DividedByZeroException:public exception {
public:
virtual const char* what()const throw(){
(III) ;
}
};
int valid(const char x[N]){
int result=0;
if(strlen(x)==0)throw EmptyException();
for(int i=0; itrlen(x); i++){
if(!isdigit(x[i]))
throw NotNumberException();
result = (IV) ;
}
return result;
} double quotient(int n1, int n2){
if( (V) )
throw DividedByZeroException();
return static_castouble>(n1/n2);
}
代號
37940
頁次
4
4
void test(const char x1[N], const char x2[N]){
int n1, n2;
try {
n1=valid(x1);
n2=valid(x2);
cout<<"Quotient:"<uotient(n1, n2);
}
catch(EmptyException &e){
cout<<"Exception:"<< e.what();
}
catch(NotNumberException &e){
cout<<"Exception:"<< e.what();
}
catch(DividedByZeroException &e){
cout<<"Exception:"<< e.what();
}
cout<
}
int main(){
test("","");
test("a","12");
test("10","0");
test("12","5");
return 0;
}
請說明使用 try-catch if-else處理例外狀況的優缺點。5分)
請說明 C++Java try-catch finally 設計的異同與其理由5分)
收藏 ⬇️ 下載