精華區beta NTU-Exam 關於我們 聯絡資訊
課程名稱︰計算機程式 課程性質︰系必修 課程教師︰魏宏宇 開課學院:理學院 開課系所︰物理系 考試日期(年月日)︰2008/01/15 考試時限(分鐘):120 是否需發放獎勵金:是 (如未明確表示,則不予發放) 試題 : Format: closed book Notice: Please write your C++ with "proper style"(程式寫太亂是會被扣分的) 1.(26%)[Bubble Sorting] In this sorting algorithm, small values gradually move to the top of the array (like bubble rising water), and large valuse sink to the bottom of the array. The basic idea is to compare two neighboring elements, and to swap them if they are in the wrong order. The bubble sort makes several passes. One each pass, succcessive pairs of elements are compared. If a pair is in decreasing order, we will swap them. After the first pass, the largest element is guaranteed to be at the end of the array, after the second pass, the second largest element is in position, and so on. In this program, define a constant variable ArraySize equals to 5. Declare an array A that includes 56, 34, 4, 10, 77. Use bubble sort for sorting array A in increasing order. The results are like: After pass 1: 4 56 34 10 77 After pass 2: 4 10 56 34 77 After pass 3: 4 10 34 56 77 2.(56%)Write C++ statement to do the following tasks: ● You can assume that we already have 'using' statement ● You can assume that all required standard library are included (a)[10%] Use recursive method to create a function to compute f(x) = x * (x - 1) * ... * 4 * 3, for x > 3, f(x) = 3 for x <= 3. (b)[14%] Randomly generates a 3 by 5 2-D array(3乘5的二維陣列). Fill in the array with non-duplicated random numbers between 14 ~ 52 (c)[6%] Enumerate the 4 seasons of an year (Spring = 1, Summer = 2, Fall = 3, Winter = 4) (d)[10%] Create a function swap_three() that input 3 character variables In1, In2, and In3(thay have the same size), and swap three 3 characters (In1 becomes In2, In2 becomes In3, In3 becomes In1). In main function, call the swap_three() to swap 3 character variables char A1, A2, A3. (e)[10%] Use & tp implement a pass-by-referance function to return the summation of a float array X. Input of the function is float array X, and the size of the array sizeX. The output of function is sumX. (f)[6%] Use for loop, and/or break, countinue commands to display 1,2,3,4,5,7,8,9,10(skip 6) on screen. 3.(18%)What are the output of the following programs? If you think there is error, just write 'ERROR' in your answer. If cout displays an unknown address, please answer with "address of variable X". (a) Assume the address of x is 600000. The size to store an address is 4 bytes. The size to store an integer is 4 bytes.(10%) int x[] = {1,3,5,7}; int *y = x; int i = 1; cout << "\n(a1) = " << &x[3]; cout << "\n(a2) = " << y; cout << "\n(a3) = " << *x + 2; cout << "\n(a4) = " << *(y + 1); *(y++) = 2; x[2] = 4; x[3] = 0; cout << "\n(a5) = " << x[++i]; cout << "\n(a6) = " << *(x + 1); cout << "\n(a7) = " << x; cout << "\n(a8) = " << *(*(&y)); cout << "\n(a9) = " << *(&(*y)); cout << "\n(a10) = " << ++y; (b) Assume the address of N is 500000. The size to store an address is 4 bytes. The size to store a character is 4 bytes.(8%) char *N[4] = {"Seven","Eight","Nine","Ten"}; cout << "(b1) = " << N[1][2] << endl; cout << "(b2) = " << N << endl; cout << "(b3) = " << &N[3][1] << endl; cout << "(b4) = " << *N[2] << endl; cout << "(b5) = " << &N[1] << endl; cout << "(b6) = " << &N << endl; cout << "(b7) = " << *N << endl; cout << "(b8) = " << N[2] << endl; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.102.7
spiral1226:真神速XD 01/15 19:32
※ 編輯: qazwsxerdfcv 來自: 140.112.102.7 (01/15 19:57)
qazwsxerdfcv:在考試結束前題目就公佈了XD 01/15 21:24