資訊處理 112 年程式設計考古題(共 4 題) 資料來源:考選部歷屆試題|法律人 LawPlayer 整理 https://lawplayer.com/exam/information-processing/112-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88 第 1 題 關於下列C 程式碼,請說明程式執行後,程式碼編號27~33 的輸出,以 及其運算邏輯。(25 分) 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #include #define SIZE 30 typedef enum direction {North, South, East=3, West} dir_t; int f1(int a, int b) { int x = 3.0/a; double y = (a/2)*(b%3) + x; return y; } int f2(dir_t d) { d= (North+East)/2 > d? East: West; return d; } int f3(int a, int b) { if (b==a || b<=1) return a+b; else if (a<=1) return b-a; else return f3(a-b, a-1)+b+a; } int f4(int a, int b) { int data[SIZE]; for (int i=1, k=0; i #include #include using namespace std; class Except{ public: void f1(int c); void f2(); void f3(); void f4(); void f5(); void f6(); }; int main() { Except e; e.f1(1); e.f2(); e.f3(); e.f4(); e.f5(); e.f6(); return 0; } void Except::f1(int c) { if (c<0) throw out_of_range("large"); cout<<"exc1"<name:') print('send: ' + name) s.send(name.encode()) indata = s.recv(1024) s.close() print('>' + indata.decode()) if 'quit' in name: break (5) print('wait for connection...') while True: conn, addr = s.accept() print('connected by ' + str(addr)) indata = conn.recv (1024) print('recv: ' + indata.decode()) if 'quit' in indata.decode(): outdata = 'bye ' else: outdata = 'hi ' + indata.decode() conn.send(outdata.encode()) conn.close() if 'quit' in indata.decode(): break print('listen...') s.close() #client.py import socket while True: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('127.0.0.1', 7000)) name = input('>name:') print('send: ' + name) s.send(name.encode()) indata = s.recv (1024) s.close() print('>' + indata.decode()) if 'quit' in name: break 題目為考試當年公告版本,實務標準請以現行規範為準。