- (10%) Determine whether the following code has syntax erros or
not. If it is correct, predict its output. If it is
incorrect, point out the mistake(s).
#include <iostream>
using std::cout;
using std::endl;
void test(char p[])
{ cout << ++p << endl;
}
int main()
{
char *name = "ABCD";
test(name++);
cout << ++name << endl;
}
- (10%) Determine whether the following code has syntax erros or
not. If
it is correct, predict its output. If it is incorrect, point out
the
mistake(s).
// Pass-by-reference
#include <iostream>
using std::cout;
using std::endl;
void print(int i, int j)
{
cout << "i = " << i << "\t j = " << j << endl;
}
void swap1(int a, int b)
{ int temp;
temp = a; a = b; b = temp;
}
void swap2(int &a, int &b)
{ int temp;
temp = a; a = b; b = temp;
}
void swap3(int &a, int b)
{ int temp;
temp = a; a = b; b = temp;
}
int main()
{
int i=20, j=11;
swap1(i,j); print(i,j);
swap2(i,j); print(i,j);
swap3(i,j); print(i,j);
}
- (10%) What will be the output of the following program?
#include <iostream>
using std::cout;
using std::endl;
struct Node
{
char value;
Node* left;
Node* right;
};
void print(Node* r)
{
if (r->left != NULL) print(r->left);
cout << r->value;
if (r->right != NULL) print(r->right);
return;
}
int main(void)
{
Node a = { 'A', 0, 0 };
Node b = { 'B', 0, 0 };
Node h = { 'H', &a, &b };
Node c = { 'C', 0, 0 };
Node d = { 'D', 0, 0 };
Node g = { 'G', &c, &d };
Node i = { 'I', &h, &g };
Node f = { 'F', 0, 0 };
Node e = { 'E', &i, &f };
print(&e);
cout << endl;
return 0;
}
- (10%) Determine whether the following code has syntax erros or
not. If it is correct, predict its output. If it is
incorrect, point out the mistake(s).
#include <iostream>
using std::cout;
using std::endl;
struct Node
{
char value;
Node* left;
Node* right;
};
void print(Node* r)
{
if (r->left != NULL) print(r->left);
if (r->right != NULL) print(r->right);
cout << r->value;
return;
}
int main(void)
{
Node a = { 'A', 0, 0 };
Node b = { 'B', 0, 0 };
Node h = { 'H', &a, &b };
Node c = { 'C', 0, 0 };
Node d = { 'D', 0, 0 };
Node g = { 'G', &c, &d };
Node i = { 'I', &h, &g };
Node f = { 'F', 0, 0 };
Node e = { 'E', &i, &f };
print(&i);
cout << endl;
return 0;
}
- (10%) Determine whether the following code has syntax erros or
not. If it is correct, predict its output. If it is
incorrect, point out the mistake(s).
// Importance of the "break" statement in the "switch" statement
#include <iostream>
using std::cout;
using std::endl;
int main(void)
{
char str[] = "TAIWAN";
char *p = str;
int vowel = 0;
int consonant = 0;
for ( ; *p != '\0'; p++)
switch (*p)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
vowel++;
default:
consonant++;
}
cout << vowel << '\t' << consonant << endl;
return 0;
}
- (10%) Determine whether the following code has syntax erros or
not. If it is correct, predict its output. If it is
incorrect, point out the mistake(s).
// Matrix
Multiplication
#include <iostream>
using std::cout;
using std::endl;
int main(void)
{
int A[][5] = { { 0, 0, 0, 0, 1},
{ 0, 0, 0, 1, 0 },
{ 0, 0, 1, 0, 0 },
{ 0, 1, 0, 0, 0 },
{ 1, 0, 0, 0, 0 } };
int B[5][5] = { 0 };
int i, j, k;
for (i=0; i<5; i++)
for (j=0; j<5; j++)
for (k=0;
k<5; k++)
B[i][j] += A[i][k] * A[k][j];
for (i=0; i<5; i++)
{
for (j=0; j<5; j++)
cout <<
B[i][j];
cout << endl;
}
return 0;
}
- (10%) Determine whether the following code has syntax erros or
not. If
it is correct, predict its output. If it is incorrect, point out
the
mistake(s).
#include <iostream>
using std::cout;
using std::endl;
int main()
{
char str[10] = "December";
char* p = str;
cout << str << endl;
cout << *(++p) << endl;
for ( ; *p != '\0'; p++)
*p ^= 0x20;
cout << sizeof(*p) << endl;
cout << str << endl;
}
- (10%) Determine whether the following code has syntax erros or
not. If
it is correct, predict its output. If it is incorrect, point out
the
mistake(s).
// Manipulator hex
#include <iostream>
using std::cout;
using std::endl;
using std::hex;
int main(void)
{
int c1 = 'A', c2 = 'a';
c1 ^= c2; cout << hex << c1 << c2 << endl;
c2 ^= c1; cout << hex << c1 << c2 << endl;
c1 ^= c2; cout << hex << c1 << c2 << endl;
return 0;
}
- (10%) Determine whether the following code has syntax erros or
not. If
it is correct, predict its output. If it is incorrect, point out
the
mistake(s).
// Linked-List
#include <iostream>
using std::cout;
using std::endl;
struct Node
{
int value;
Node* next;
};
Node* insert(Node* head, int n)
{
Node* p = new Node;
p->value = n;
p->next = head;
return p;
}
void print_list(Node* p)
{
int n = 0;
while (p)
{
cout << "Line " << ++n << ":" << p->value << endl;
p = p->next;
}
return;
}
int main(void)
{
int A[] = { 1, 3, 5, 7, 2, 4, 6 };
int n = sizeof(A) / sizeof(A[0]);
Node* head = NULL;
for (int i=0; i<n; i++)
head = insert(head, A[i]);
print_list(head);
return 0;
}
- (10%) Determine whether the following code has syntax erros or
not. If
it is correct, predict its output. If it is incorrect, point out
the
mistake(s).
//
Structure array
#include <iostream>
using std::cout;
struct POINT
{
int x;
int y;
}
int Area(POINT p1, POINT p2)
{ return (p2.x - p1.x) * (p2.y - p1.y);
}
int main()
{
POINT p[2] = { { 10, 40 } , { 50, 60 }
};
cout << Area(p[0], p[1]) << "\n";
return 0;
}
- (10%) Determine whether the following code has syntax erros or
not. If
it is correct, predict its output. If it is incorrect, point out
the
mistake(s).
//
Linked-List
#include <iostream>
using std::cout;
using std::endl;
struct Node
{
int value;
Node* next;
};
Node* insert(Node* head, int n)
{
Node* p = new Node;
p->value = n; p->next = NULL;
Node* p2 = head;
Node* p1 = p2;
if (p2 == NULL)
return p;
while (p2->value < p->value &&
p2->next != NULL)
{
p1 = p2;
p2 = p2->next;
}
if (p2->value < p->value)
{
p->next = p2->next;
p2->next = p;
return head;
}
else
if (p1==p2)
// n is less than the first element
{
p->next =
p1;
return p;
}
else
{
p->next =
p2;
p1->next =
p;
return head;
}
}
void print_list(Node* p)
{
int n = 0;
while (p)
{
cout << p->value
<< endl;
p = p->next;
}
return;
}
int main(void)
{
int A[] = { 1, 3, 5, 7, 2, 4, 6 };
int n = sizeof(A) / sizeof(A[0]);
Node* head = NULL;
for (int i=0; i<n; i++)
head = insert(head, A[i]);
print_list(head);
return 0;
}
- (5%)
依台灣現行的著作權法來計算,一個著作權的平均有效時間大約是多久?
- 75年
- 85年
- 100年
- 110年
- (5%) 請
問以下哪個項目需要登記後,才具有法律效用?
- 專
利
- 著
作權
- 以
上兩者皆是
- (5%) 請
問創用CC(Creative Commons)的Some Rights Reserved授權,是屬於哪種授權方式?
- 保
留著作人的部分權利
- 保
留著作人的所有權利
- 開
放所有權利
- (5%) 有
關創用CC授權的四個核心授權要素,並未出現在圖中的是哪一項?
- 姓
名標示
- 非
商業性
- 禁
止改作
- 相同方式分享