NCCU_Exam 板


LINE

課程名稱:計算機程式設計(一) 課程性質:必修 課程範圍:1~7章 (introduction ~ pointer) 開課教師:蔡銘峰 開課學院:理學院 開課系級:資科一 考試日期(年月日):2011/11/16 考試時限(Mins):180分 附註: 試題本文: 1. Basic Unix Commands [5%] ( 1 point for each ) Write Unix command for the following situations: a) Create a directory named nccucs b) Rename a file from a.txt to b.txt c) Display the line-by-line difference between MRU.txt and GTR.txt d) Display the on-line manual pages about the cp command e) List all the files whose filename starts with assign, and store the result into a file named result.txt 2. Basic C statements [12%] ( 2 points for each ) Write a "single" C statement to accomplish each of the following: (Note that in C each statement should end with a semicolon.) a) Define the variables c, thisVariable, q76354 and number to be of type int. b) Print "The product is" followed by the value of the integer variable result. c) Define a variable x and initialize the variable to 1. d) Add variable x to variable sum and assign the result to variable sum e) Cauculate the reminder after q is divided by divisor and assign the result to q. f) Print the value 123.4567 with 2 digits of precision. 3. Write down the output of the following programs. a) #include <stdio.h> int main(){ int i; for( i = 1; i <= 100; i++ ){ if( i % 9 != 0 ) continue; if( i >= 80 ) break; printf("%d", i); } printf("\n"); return 0; } b) #include <stdio.h> int main() { int i = 20; while (1) { switch(i % 2){ case 0: printf("even"); break; case 1: printf("odd"); break; default: printf("Not a number!"); } i -= 2; if (i < 10) break; } printf("\n"); return 0; } 4. Operator Priority and Logical Operations [10%] (5 points for each) Please write down the values of each variable in the following programs: a) What are the values of i, j, k, x, y, and z? (1 point for each answer) #include <stdio.h> int main(){ int i = 2; int j = 3; int k = 4; int x = i+++j; int y = 0; if(j=k<<1) y = j + k; else y = k - k; int z = k + (k+=1); printf("i=%d,j=%d,k=%d,x=%d,y=%d,z=%d\n",i,j,k,x,y,z); return 0; } b) What are the values of x and y? (2.5 points for each answer) #include <stdio.h> int main(){ int a = 4, b = 7, x = 0, y = 0; x = a & b; if(a && b) y = (!a||!b)+(a&&!b); else y = (!a||b)+(!a&&b); return 0; } 5. Function Prototype [8%] (2points for each) Write down the function prototype for each of the following: (Note that a function prototype should end with a semicolon.) a) Fuction hypotenuse that takes two double arguments: side1 and side2, and returns a double result b) Fuction smallest that taskes three integers: x, y, z, and returns an integer c) Function instructions that does not receive any arguments and does not return a value. d) Function intToFloat that takes an integer argument: number, and returns a floating-point result 6. Call-by-Value and Call-by-Reference [12%] What is the result of the following program? (3 points for each answer) #include <stdio.h> void callBy Value( int number ){ number = number * 10; } void callByReference( int *nPtr ) { *nPtr = *nPtr * *nPtr * *nPtr; } int main( void ) { int number = 2; callByValue( number ); printf( "%d ", number ); callByReference( &number ); printf( "%d ", number ); callByValue( number ); printf( "%d ", number ); callByReference( &number ); printf( "%d\n", number ); return 0; } 7. Write down the output of the program: #include<stdio.h> int love, hate; int fp(int x){ int life=1; love++; hate=x+1; life+=love+hate; x++; return life; } int f2(int x){ static int life=1; love++; hate=x+1; life+=love+hate; x++; return life; } int main(){ int life; love=hate=1; life=fp(love); printf("%3d %3d %3d\n", life, love, hate); life=fp(love); printf("%3d %3d %3d\n", life, love, hate); love=hate=1; life=fp(love); printf("%3d %3d %3d\n", life, love, hate); life=fp(love); printf("%3d %3d %3d\n", life, love, hate); life=fp(love+1); printf("%3d %3d %3d\n", life, love, hate); return 0; } 8. Pointer [8%] (2 points for each) #include<stdio.h> int main(){ int *a; int b = 2, c = 5; a = &c; b = *a; int *d = &b; return 0; } Suppose that the address of b is at 3000 and that of e at 4000. What is the result of following questions? (Note that the space of an integer is 4 byte) a) ++*a = ? b) (++b)*2 = ? c) (c+2) = ? d) (d+1) = ? 9. Pointer and Array [12%] (2 pts for each) An array of integers is stored starting at address 1000. int arr[] = {12, 15, 32, 14, 66}; /* the address of the first in in the array is 1000*/ /* arr:[1000] ---> [12][15][32][14][66] */ What is the value pruduced by each of the following expressions. The value will either be an address like 1004 or an integer value inside the array, like 15 or 66 etc. (Note that the space of an integer is 4 byte.) a) arr + 1 = ? b) arr + 3 = ? c) arr[2] = ? d) &arr[2] = ? e) *arr = ? f) *(arr + 3) = ? 10. Pointer and Swap [10%] (1 point for each blank) Add * and & to the following code so that it implements a swap function. At the end of the function, x should contain y, and y should contain x, and those changes should remain when the function returns to main. Then show a function call to swap in the main function provided. #include <stdio.h> void swap (int ___x, int ___y) { int ___temp=___x; ___x=___y; ___y=___temp; } int main() { int x=3, y=4; swap(___x, ___y); return 0; } 11. const Qualifer [5%] Bonus Identify the errors in the following program, and explain the reason of causing the error in details. 1. #include <stdio.h> 2. int main( void ) { 3. int x = 5; 4. int y; 5. const int *const ptr = &x; 6. printf( "%d\n", *ptr ); 7. *ptr = 7; 8. ptr = &y; 9. return 0; 10. } --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.119.27.46 ※ 編輯: dibery 來自: 140.119.27.46 (07/10 11:16) ※ 編輯: dibery 來自: 140.119.27.46 (07/10 11:28) ※ 編輯: dibery 來自: 140.119.27.46 (07/10 11:29)







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:BuyTogether站內搜尋

TOP