國立暨南國際大學 100 學年度第一學期小考試卷
(考試時間: 8:50-9:30)
科目名稱:資訊系統
與網路導論 |
開課系所:資訊工程
學系 |
任課教師
|
吳坤熹
|
系所別:
|
年級:
|
學號:
|
姓名:
|
考試日期
|
2012.1.6
|
- (10%) Determine
whether the following code has syntax errors or not. If
it is correct, predict its output. If it is incorrect, point out
the mistake(s).
#include <iostream>
using std::cout;
int main()
{
int i, n = 0102; // Is "0102" different from "102"?
for (i=1; i<7; i++)
{
int n = 0;
for (int j=1; j<=i; j++)
n += j; // scope of variable n
cout << n << "\n";
}
cout << n << "\n";
return 0;
}
- (10%) Determine
whether the following code has syntax errors or not. If
it is correct, predict its output. If it is incorrect, point out
the mistake(s).
// modulus
#include
<iostream>
using std::cout;
using std::endl;
int mod(int a, int b)
{
do a -= b;
while
(a >= b);
return
a;
}
int main()
{
cout
<< mod(0106, 7) << endl;
return
0;
}
- (10%)
Consider
the following code to decrypt the Caesar Cipher. If you want to
corrently obtain the answer "HELLO NCNU", what statement should be in
the blank (1)?
- *a = (*a - 'A' + key) % 26 + 'A';
- *a = (*a - 'A' - key) % 26 + 'A';
- *a = (*a - 'A' + key) % 26 - 'A';
- *a = (*a - 'A' - key) % 26 - 'A';
// Caesar Cipher
#include <iostream>
using std::cout;
using std::endl;
void decrypt(char* a, int key)
{
while (*a)
{
if (*a >= 'A' && *a <='Z')
(1)
a++;
}
}
int main()
{
char msg[] = "KHOOR QFQX";
decrypt(msg, 3);
cout << msg << "\n";
return 0;
}
- (10%)
Determine
whether the following code has syntax errors or not. If
it is correct, predict its output. If it is incorrect, point out
the mistake(s).
#include <iostream>
using std::cout;
float average(float a, float b);
float average(float a, float b, float c); // overloading
int main()
{
cout << average(1.2, 5.2, 7.2) << "\n";
cout << average(3.0, 5.0) << "\n";
return 0;
}
float average(float a, float b)
{ return (a+b)/2.0; }
float average(float a, float b, float c)
{ return (a+b+c)/3.0; }
- (10%)
Determine
whether the following code has syntax errors or not. If
it is correct, predict its output. If it is incorrect, point out
the mistake(s).
// binary tree
#include <iostream>
using std::cout;
struct Node
{
char label;
Node* left;
Node* right;
};
void postorder(Node* p);
int main()
{
Node Second = { 'B', NULL, NULL };
Node Third = { 'C', NULL, NULL };
Node Fifth = { 'E', NULL, &Second };
Node Sixth = { 'F', &Third, };
Node Seventh = { 'G', &Fifth, &Sixth };
postorder(&Seventh);
return 0;
}
void postorder(Node* p)
{
if (p)
{
cout << p->label;
postorder(p->left);
postorder(p->right);
}
}