NTU-Exam 板


LINE

课程名称︰计算机程式 课程性质︰农 课程教师︰林达德 开课学院: 开课系所︰ 考试日期(年月日)︰ 考试时限(分钟): 是否需发放奖励金: (如未明确表示,则不予发放) 要谢 试题 : 【九十八学年度上学期】 第一题:(10分) 解释名词 (1) stack 堆叠的结构,符合LIFO(Last-in, first-out)的特性, 最後放入记忆体位置的资料会最先被取出。 2) function overloading 函式重载。╴为类似功能的函式提供一个统一的名称,但是 根据参数列各数或型态的不同,而自动呼叫对应的函式。╴╴╴╴╴ (3) ASCII American Standard Code for Information Interchange,是基於拉丁 字母的一套电脑编码系统,每一个字元与符号都有一对应的数字码。 (4) variable scope 变数可视范围。就是定义变数可被识别与使用的范围,可 藉此将变数分为全域变数(Global variable),区域变数(Local variable),区块变 数(Block variable)。╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴ (5) pass by reference 传址。将变数记忆体位置直接传入函式中,运算完值间将结果放 入同一记忆体位置中。╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴ 第二题:(10分) 下列叙述执行後变数A,B,C,D,E之值分别为何? int A=0, B=0, C=0, D=0, E=0; while( B <= 20 ) { A = A + 2; B = B + A; C++; D = B + C%2; E *= 2.0; } ─────────────────────────────────── 答案栏: A = ˍ10ˍ B = ˍ30ˍ C = ˍ5ˍ D = ˍ31ˍ E = ˍ0ˍ 第三题:(10分)   下列程式片段执行後的结果请列於答案栏中 for( int i=1; i<=6; i++ ) { for( int j=1; j<=10; j++ ) { if( i%3 == 0 ) cout << ‘%’; else cout << ‘=’; } cout << endl; } ─────────────────────────────────── 答案栏: ========== ========== %%%%%%%%%% ========== ========== %%%%%%%%%% 第四题:(10分)   请将下列程式在个人电脑上执行後之输出仔细地填入右侧答案栏中。 #include <iostream> using std::cout; using std::endl; int funct1(int a); int funct2(int a); int a = 0, b = 1; void main() { int count; for( count = 1; count <=5; ++count) { b += funct1(a+1) + 1; cout << “b = “ << b << endl; } } int funct1( int a ) { b = funct2( a+2 ) + 2; return b; } int funct2( int a ) { return(b+a); } 答案栏: b = 13 b = 37 b = 85 b = 181 b = 373 第六题:(10分)   请写出一个程式计算出符合下式的最小n值,并将结果输出至电脑萤幕。 ─────────────────────────────────── 答案栏:(空间不够时请写於背面) #include "iostream" using namespace std; int main() { int n = 0; //代表的次方项变数 int m = 1; //储存的n次方後的运算结果 do { n = n+1; //次方加 m *=3; //3的n次方运算 }while( m<=30000); //如果的n次方<=30000,则继续寻找;否则跳出回圈 cout<<m; //显示结果 system ("pause"); return 0; } 第七题:(10分)   请计算并列印出费朋纳西序列(Fibonacci sequence)之前二十项,列印之每一行共有 五个数(合计四行)。   提示:费朋纳西序列为 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,..... ─────────────────────────────────── 答案栏:(空间不够时请写於背面) #include "stdafx.h" #include "iostream" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int a = 0; int b = 1; int c; cout << a << "\t" << b << "\t"; //直接输出前二项 for (int i=2; i<=19; i++){ c = a + b; //费氏数列核心 a = b; b = c; cout << c << "\t"; if(i%5==4) //依题目要求换行 cout << endl; } system("pause"); return 0; } 第八题:(10分) 请设计一个程式,其功能为找出整数1至N之间的质数,整数N之值由使用者输入,找到的 质数请输出至萤幕上。 ─────────────────────────────────── 答案栏:(空间不够时请写於背面) #include "stdafx.h" #include "iostream" #include "cmath" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int N, temp=0; cout << "请输入范围:"; cin >> N; //使用者输入范围 for (int i=2; i<=N; i++){ //检查~N for (int j=2; j<=sqrt((double)i); j++){ //检查是否可 //被其他数字可整除 if (i%j == 0){ temp++; //有整除情况,将暂存值增加 } } if (temp) //若暂存值不为零,表示有整除,非质数, //不输出并且将暂存值归零 temp = 0; else cout << i << " "; //暂存值为零,i为质数,输出 } system("pause"); return 0; } 第九题:(10分)   指数函数ex 可以下式计算之        请你设计一个函式计算指数函数(至第20项),同时在主程式中呼叫此函式计算e1, e2, e3, e4,...,至e10,并将结果输出至萤幕。 ─────────────────────────────────── 答案栏:(空间不够时请写於背面) #include "stdafx.h" #include "iostream" #include "iomanip" #include "cmath" using namespace std; double e(int x); int _tmain(int argc, _TCHAR* argv[]) { for (int i=1; i<=10; i++) cout << "e^" << i << " = "<< setprecision(10) <<e(i) << endl; //呼叫十次e函 数 system("pause"); return 0; } double e(int x) { double result = 1; double factorial = 1; for (int i=1; i<20; i++){ factorial *= i; //阶乘 result += pow((double)x,i) / factorial; //e的指数次方公式 } return result; } 第十题:(10分) 若一个整数等於除了自己以外所有因数之总和,则称之为perfect number。请你撰写一个 函式PerfectNumber(long int Num)来判断传进去的参数是否为一perfect number。并设 计一个主程式呼叫这个PerfectNumber(long int Num)函式来判断自1到10000有哪些整数 是perfect number,将它们显示在萤幕上。 ─────────────────────────────────── 答案栏:(空间不够时请写於背面) #include "iostream" using namespace std; bool PerfectNumber(long int); //定义函式PerfectNumber int main() { for (int i=1 ; i<=10000 ; i++) //回圈寻找到之间的perfect number { if (PerfectNumber(i) == true) //如果函式判断放入的数为 //perfect number,则输出至萤幕 cout<<i<<endl; } system("pause"); return 0; } bool PerfectNumber(long int n) { int m = 0; //储存因数累加结果的变数 for (int j=1 ; j<n ; j++) //回圈寻找到n之间,n的因数 { if (n%j==0) //如果j为n的因数,则将因数累加至m中 m = m + j ; } if (n == m)//如果因数和m 等於输入的数n ,则回传true,否则回传false return true; else return false; } --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.115.224 jasonfghx:转录至看板 NTUCH-101HW 12/10 23:27 fanif:转录至看板 NTUBIME104HW 11/11 03:54







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

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

TOP