NTU-Exam 板


LINE

课程名称︰计算机概论 课程性质︰必修 课程教师︰陈敏璋 开课学院:工学院 开课系所︰材料系 考试日期(年月日)︰101.6.15 考试时限(分钟):180 分钟 是否需发放奖励金:是 (如未明确表示,则不予发放) 试题 : 1. (5%) do while 回圈 #include <iostream> #include <cstdlib> using namespace std; int main(void) { int i=0; do{ if(i%2==1) cout << i << "is an odd number" << endl; i++; }while(i<10); system("pause"); return 0; } 请写出此程式输出的结果 2. (5%) 指标 #include <iostream> #include <cstdlib> using namespace std; int main(void) { int x=1,y=2,z=3; int *ip; ip=&x; z=*ip; *ip=y; ip=&y; *ip=z; cout << "*ip=" << *ip << endl; system("pause"); return 0; } 请写出此程式输出的结果 3. (5%) 条件运算子 #include <iostream> #include <cstdlib> using namespace std; int main(void) { int a=1,b=11,z; z=(a>b)?a:b; cout << z << endl; system("pause"); return 0; } 请写出此程式输出的结果 4. (5%) 指标与阵列 #include <iostream> #include <ctsdlib> using namespace std; int main(void) { int a[5],i,f; for(i=0;i<=4;i++) a[i]=5-i; f=*a+a[1]+*(a+2)+(*a+3); cout << f << endl; system("pause"); return 0; } 请写出此程式输出的结果 5. (5%) 指标与动态记忆体配置 #include <iostream> #include <cstdlib> using namespace std; int main(void) { int array_size = 10; int *a; a = new int[array_size]; int i; for(i=0;i<array_size;i++) a[i]=i; while (*a<9) { a++ cout << *a+1 << " "; } cout << endl; delet []a; system(:pause"); return 0; } 请写出此程式输出的结果 6. (5%) 传址 #include <iostream> #include <cstdlib> using namespace std; void CallbyAddress(int*,int*); int main(void) { int a, b; a=100,b=200; cout << a << " " << b << endl; cout << &a << " " << &b << endl; CallbyAddress(&a,&b); cout << a << " " << b << endl; cout << &a << " " << &b << endl; system(:pause"); return 0; } void CallbyAddress(int *x,int *y) { *x=60; *y=*x+*y-30; cout << x << " " << y << endl; cout << *x << " " << *y << endl; } 若主程式中变数a和b的记忆体位址分别为1245064与1245060,请写出此程式输出的结果 7. (5%) break #include <iostream> #include <cstdlib> using namespace std; int main(void) { int s; for(x=1;x<=10;x++) { if(x==5) break; cout << x << endl; } system("pause"); return 0; } 请写出此程式输出的结果 8. (5%) coutinue #include <iostream> #include <cstdlib> using namespace std; int main(void) { int y; for(y=1;y<=10;y++) { if(y==5) continue; cout << y << endl; } system("pause"); return 0; } 请写出此程式输出的结果 9. (5%) for回圈与阵列 #include <iostream> #include <cstdlib> using namespace std; int main(void) { int array[4][4],x,y; for(x=0;x<4;x++) for(y=0;y<4;y++) array[x][y]=x+y; for(x=0;x<4;x++) { for(y=0;y<4;y++) cout << array[x][y] << " "; cout << endl; } system("pause"); return 0; } 请写出此程式输出的结果 10. (5%) 字元指标阵列 #include <iostream> #include <cstdlib> using namespace std; int main(void) { char *name[5]={"John","Kent","Mary","Jack","Tom"}; int score[5]={90,80,70,80,90}; int n, sum = 0; float avg; for(n=0;n<=4;n++) { sum=sum+score[n]; cout << name[n] << " " << score[n] << endl; } avg=(float)sum/5; cout << "Average=" << avg << endl; system("pause"); return 0; } 请写出此程式输出的结果 11. (5%) 巨集 #include <iostream> #include <cstdlib> using namespace std; #define x 5+3 int main(void) { int i=3,j=4; cout << i*x+j << endl; system("pause"); return 0; } 请写出此程式输出的结果 12. (5%) 函式传回值为指标 #include <iostream> #include <cstdlib> using namespace std; int *ABC(int *); int main(void) { int a[5]={3,1,7,2,6}; int *ptr; ptr = ABC(a); cout << "ptr << endl; system(:pause"); return 0; } int *ABC(int *arr) { int i, *k; k=arr; for(i=1;i<5;i++) if(*k<*(arr+i)) k=arr+i; return k; } 请写出此程式输出的结果 13. (5%) 二维阵列与指标 #include <iostream> #include <cstdlib> using namespace std; int main(void) { int num[3][4]={{12,23,42,18}, {43,22,16,14}, {31,13,19,28}}; int m,n; for(m=0;m<3;m++) { for(n=0;n<4;n++) { if( *(*(num+n)+n)>40) *(*num+m)+n)=40; cout << *(*(num+m)+n) << " "; } cout << endl; } system("pause"); return 0; } 请写出此程式输出的结果 14. (5%) 传递函数到其他函数中 #include <iostream> #include <cstdlib> using namespace std; double triangle(double, double), rectangle(double, double); void showarea(double, double, double (*pf)(double, double)); int main(void) { cout << "triangle(6,3.2)="; showarea(6,3.2, triangle); cout << "rectangle(4,6.1)="; showarea(4,6.1,rectangle); system("pause"); return 0; } double triangle(double base, double height) { return (base*height/2); } double rectangle(double height, double width) { return (height*width); } void showarea(double x, double y, double (*pf)(double,double)) { cout << (*pf)(x,y) << endl; return; } 请写出此程式输出的结果 15. (5%) 函数传回值为参照 #include <iostream> #include <cstdlib> using namespace std; int &max(int &, int &); int main(void) { int i=10,j=20; max(i,j)=100; cout << "i=" << i << ",j=" << j << endl; system("pause"); return 0; } int &max(int &a, int &b) { if(a>b) return a; else return b; } 请写出此程式输出的结果 16. (5%) 结构与函数 #include <iostream> #include <cstdlib> #include <string> using namespace std; struct mydata { string name; int age; }; void func(struct mydata); int main(void) { struct mydata woman = {"Mary Wu",5}; cout << "Before process..." << endl; cout << "Im main(), " << woman.name; cout << "'s age is " << woman.age << endl; cout << "After process..." << endl; func(woman); cout << "Inmain(), " << woman.name; cout << "'s age is " << woman.age << endl; system("pause"); return 0; } void func(struct mydata a) { a.age=a.age+10; cout << "In func(), " << a.name; cout << "'s age is " << a.age << endl; return; } 请写出此程式输出的结果 17. (5%) 类别 #include <iostream> #include <cstdlib> using namespace std; class CWin { private: char id; int width; int height; int area(void) { return (width*height-600); } public: void show_area(void) { cout << "Window " << id << ",area = " << area() << endl; } void set_data(char i,int w, int h) { id=i; if(w>0 && h>0) { width = w; height = h; } else cout << "input erroe" << endl; } }; int main(void) { CWin win1; win1.set_data('B',30,40); win1.show_area(); system("pause"); return 0; } 请写出此程式输出的结果 18. (10%) switch ... case 请用switch ... case叙述设计一完整的城市,依照分数给予相对的评语 分数 评语 80-100 You got A ! 70-79 You got B ! 60-69 You got C ! 0-59 You got D ! 其他 Error Input ! (0-100)! 19. (15%) 递回函数 以递回函数的方式设计一完整的程式,求1+2+......+100之值 (若使用回圈设计此程式则得一半的分数 (8%)) --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.243.14







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

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

TOP