科目名稱:程式設計 | 開課系所:資訊工程 學系 | 考試日期 | 2017.3.29 | ||
系所別: |
年級: |
學號: |
姓名: |
考試時間 | 08:30-10:30 |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 |
(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).
// Letter Grouping
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
const int MAX_SIZE = 80;
char plaintext[] = "It's easy to read this sentence";
char buffer[MAX_SIZE];
char* p = plaintext;
char* p2 = buffer;
while (*p)
if ('A' <= *p & *p <= 'Z' || 'a' <= *p & *p <= 'z')
*p2++ = (*p++ & 0xDF);
else
p++;
*p2 = '\0';
p=buffer;
while (*p)
{
cout << *p++;
if ((p - buffer) % 5 == 0)
cout << ' ';
}
cout << endl;
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).
// Transposition Cipher
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
char cipher[] = "CFITSLINMEOVGECCEAERKOTTE";
int i, j, p=0;
char matrix[5][5];
for (j=0; j<5; j++)
for (i=4; i>=0; i--)
matrix[i][j] = cipher[p++];
for (i=0; i<5; i++)
for (j=0; j<5; j++)
cout << matrix[i][j];
cout << endl;
return 0;
}