- (10%) What would the following code show on the screen?
// Ncurses Library
#include <curses.h>
int main()
{
const int HEIGHT = 3;
int y;
initscr();
for (y=0; y<=HEIGHT; y++)
{
move(y, y); addch('*');
move(y, 2*HEIGHT - y); addch('*');
}
refresh();
endwin();
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// switch (P.135)
#include <iostream>
int main()
{
int i(0), a(0), b(0);
for (i=1; i<=6; i++)
switch(i % 2)
{
case 0:
a += 2;
break;
case 1:
b++;
break;
}
std::cout << a << b << std::endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// continue (P.146) vs. break (P.136)
#include <iostream>
using std::cout;
using std::endl;
int main()
{
int i, j, k, m;
m=0;
for (i=1; i<6; i++)
{
if (i==3)
continue;
cout << i << endl;
}
cout << "After the loop, i = " << i << endl;
return 0;
}