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灯, 水草

请输入看板名称,例如:Soft_Job站内搜寻

TOP