科目名稱:資訊系統 與網路導論 | 開課系所:資訊工程 學系 | 任課教師 |
吳坤熹 |
||
系所別: |
年級: |
學號: |
姓名: |
考試日期 |
2010.12.1 |
Open book; turn off computer & mobile phone
(考試時間: 14:10-14:45)
(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).
// This is similar to Quiz 2 in BASIC
#include <iostream>
using std::cout;
using std::endl;
int main()
{
const int MAX = 25;
int a[MAX+1] = { 0 };
int sum = 0;
for (int i=1; i<=MAX; i++)
for (int j=i; j<=MAX/i*i; j+=i)
switch (a[j])
{
case 0:
a[j] = 1;
break;
case 1:
a[j] = 0;
break;
}
for (int i=1; i<MAX; i++)
sum += a[i];
cout << sum << 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()
{
unsigned s = 1201;
int i = (s >> 4) & ~(~0 << 3);
cout << i << endl;
return 0;
}
#include <iostream>
using std::cout;
using std::endl;
int main()
{
char name[] = "NCNU";
int i = 0;
while (name[i] != '\0')
name[i++] |= 0x20;
cout << i << name << endl;
return 0;
}
#include <iostream>
using std::cout;
using std::endl;
int main()
{
int a[5] = {1, 2, 3};
int i = 0;
for (i=0; i<5; a[i++] = i++)
;
for (i=0; i<5; i++)
cout << a[i] << endl;
return 0;
}