精華區beta NTUEE107HW 關於我們 聯絡資訊
計算機程式 期中考參考解答 November 19, 2003 1. (5%) i=0; while(i<N){ a+=i; i+=2; } 2. (10%) 642211431136 3. (10%) int binarySearch(int array[], int first, int last, int value){ int middle; // Mid point of search if (first > last) return -1; middle = (first + last) / 2; if (array[middle] == value) return middle; if (array[middle] < value) return binarySearch(array, middle+1,last,value); else return binarySearch(array, first,middle-1,value); } 4. (10%) 91 5. (5%) 172135352171 6. (15%) 5 4 3 3 4 5 7. (a) (10%) Since, the computer must save where it left off in the calling function, allocate memory for any parameters being passed by value, pass all the parameter values or addresses, and jump to the instructions for the function being called. Upon returning, it must de-allocate memory, perform the built-in return procedure, and jump back to where it left off in the calling function. (b) (5%) by value : value of variable passed by reference : address of variable passed by value : copy of value is stored in the called function by reference : value changes as the address is referenced by value : int calsum(int, int, int) // function prototype declaration by reference : void swap( float&, float&); (c) (10%) Input device Output device ALU CPU Memory Storage unit 8. (10%) a=3b=4c=3 9. (10%) #include <iostream> using std::cout; int main(){ const double PI=3.14; double t,u; double &g; //'g' : references must be initialized int i,j,k; cout>>i; //There should be "cin>>i;" int a[i]; //Expected constant expression for(j=i-1;j>=0;j--) cin>>a[i]; //'cin' : undeclared identifier int * const ptr=&x; //'x' : undeclared identifier ptr=&y; //'y' : undeclared identifier and 'ptr' is a const variable g++; cout<<g; return 0; } -- ㄏㄏㄏ ㄨㄛ ㄐㄧㄠ ㄖㄨㄢ ㄐㄧㄚ ㄏㄨㄟ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.239.182
Parhelia:嗯 好像人體compiler的部份都對了 |o/ 推 140.112.18.71 11/23
whxu:我 7-(c) 爆光了... 推 218.184.80.205 11/23
kafai:強者 =_= -> >.<" -> >O< 推140.112.239.182 11/23