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