作者unmolk (UJ)
看板NTU-Exam
标题[试题] 107-1 林达德 计算机程式语言 期中考
时间Fri Nov 30 02:00:57 2018
课程名称︰计算机程式语言
课程性质︰大一必修
课程教师︰林达德
开课学院:生农学院
开课系所︰生机系
考试日期(年月日)︰2018.11.08
考试时限(分钟):120
是否需发放奖励金:是
试题 :
Problem 1:(20 points)
Briefly explain the following terms:
(1) ASCII
(2) pass by reference
(3) coercion
(4) function overload
(5) machine language
(6) syntax error
(7) function prototype
(8) nested loops
(9) continue
(10) global varaible
Problem 2:(10 points)
What is output by the following code segment?
for( int i=0; i<5; i++){
for( int j=0; j<9; j++){
if( j%3 == 0)
cout << '#';
else
cout << '$';
}
cout << endl;
}
Problem 3:(10 points)
What is the output of the following program?
#include <iostream>
using namespace std;
void teststat();
int k = 20;
int main()
{
int count;
int k=60;
for(count=0; count<5; count++)
teststat();
cout MM "The value of k is " << k << endl;
return 0;
}
void teststat()
{
static int num = 0;
cout << "The value of num is " << num << endl;
cout << "The value of k is " << k << endl;
num++;
k++;
return;
}
Problem 4:(10 points)
Write a program that calculates and outputs the prime numbers from 2 tp N.
The number N is to be input by the user and the output is on the screen.
Problem 5:(10 points)
Write a function that computes and returns the value of cos(x) by using the
following formula. The arguments of this function are the value of x (in
radians) and the number of terms, n, of the series.
x^2 x^4 x^6
cos(x) = 1 - ----- + ----- - ----- + .......
2! 4! 6!
Problem 6:(10 points)
A positive integer is a perfect number if it is equal to the sum of all of its
factors, including one but excluding itself. For example, 6 is a perfect numb-
er, since 6 = 1 + 2 + 3, and 1, 2, and 3 are factors of 6.
Design a PerfectNumber(long int Num) function that determines whether the sup-
plied number Num is a perfect number. Write a progrma to find all perfect num-
bers between 1 and 10000 by calling the function PerfectNumber(long int Num).
What is the greatest perfect number you can find?
Problem 7:(10 points)
The greatest common divisor(GCD) of two integers is the largest integer that
evenly divides into each of the two integers. Writhe a function gcd that retu-
rn the greatest common divisor of two integers.
Problem 8:(10 points)
Write a program that takes an 5-digit integer value and returns the number
with its digit reversed. For simplicity, use integer numbers that do not cont-
ain zeros. For example, given the number 32768, the program should return
86723.
Program 9:(10 points)
Write a function that will merge the contents of two sorted (ascending order)
arrays of type double values, storing the results in an array output parameter
(still in ascending order). The function should not assume that both its input
parameter arrays are the same length but can assume that one array does not
contain two copies of the same value. The result array should also contain no
duplicate values.
First array Second array
-10.3 | -1.7 | 3.6 | 7.2 | 8.9 -1.7 | 3.1 | 7.2 | 8.1
Result array
-10.3 | -1.7 | 3.1 | 3.6 | 7.2 | 8.1 | 8.9
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.25.99
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/NTU-Exam/M.1543514461.A.F9E.html
1F:推 obCHU724ov : 修课学生推~~~ 11/30 07:44
2F:→ SeanLyee : 1-8是nested吧 12/05 17:27
※ 编辑: unmolk (140.112.94.113), 12/06/2018 16:48:36
3F:→ unmolk : 已更正Q 12/06 16:48