Return to Topic Menu
|
Computer Science Main Page |
MathBits.com
|
Terms of Use
|
Resource CD
|
Review
Tracing Program Fragments |
|
What screen output
is produced by each of the following program fragments? |
| 1. |
cout<<
"W" << endl;
cout<< endl << "\n";
cout<< endl << "O" << endl;
cout<< "W" << endl; |
|
|
| 2. |
for(int i = 2;
i <=5; i++)
cout<< "*";
cout<< i; |
|
|
| 3. |
apstring hero
= "Indiana";
int count = 0;
while (count <=6)
{
if (hero[count] =="d")
continue;
cout<< hero[count];
count++;
} |
|
|
| 4. |
int growl = 5;
int meow = growl++ * 3;
cout<< growl
<< " "
<< meow
<< endl; |
|
|
| 5. |
int age = 30;
if (age <15)
cout<< "Skeeter";
else if (age>20)
cout<< "Duke";
else
cout<< "Wally"; |
|
|
| 6. |
cout<<
(10 - -8)/6 * 3 << endl;
cout<< 5 + -2*3 + 8/2 << endl;
cout<< 7/2 + 7%2; |
|
|
| 7. |
int x = 3;
int y = 6;
if(x>=3)
cout<< "Zip
Drive"<< endl;
if((x<=3) && (y>6))
cout<< "Scanner"
<< endl;
if((x<=3)||(y>6))
cout<< "CD Burner"; |
|
|
| 8. |
int a = 1, b =
2;
while (b < 8)
{
b += a;
a += 3;
}
cout<< a << " " << b; |
|
|
| 9. |
int i, j, sp;
for (i = 0; i <= 3; i++)
{
for(sp=0; sp<=15-i; sp++)
cout<<
" ";
for(j=1; j<=2*i+1; j++)
cout<<
"&";
cout<< endl;
} |
|
|
| 10. |
cout<<setprecision(2)<<3.567; |
|
|
| 11. |
x = 2;
switch(x)
{
case (1): cout<<
"A";
case (2): cout<<
"B";
case (3): cout<<
"C";
} |
|
|
| 12. |
if (!3)
{
cout<< "Trick";
}
cout<< "Yes"; |
|
|
| 13. |
#include <iostream.h>
void goodies(void);
void moreGoodies(int x, int y);
int grandGoodies(void);
int main(void)
{
goodies( );
int a = 2, b = 3;
moreGoodies(a, b);
cout<< a << " "
<< b << endl;
cout<< grandGoodies( );
return 0;
}
//**function definition
void goodies(void)
{
cout<< "Goodies! \n";
return;
}
//**function definition
int grandGoodies(void)
{
return (100);
}
//**function definition
void moreGoodies(int x, int y)
{
y = ++y - 1;
x = x-- * 2;
cout<< x << " "
<< y << endl;
return;
} |
|
|
| 14. |
What is WRONG
with this segment of code?
for ( int x = 6; x >
6; x--)
{
cout<< x;
} |
|
|
| 15. |
What
is WRONG with this segment of code?
int num = 7;
do
{
cout<< "LookOut!";
num -= 2;
}
while (num != 2); |
|
|
| 16. |
What's wrong
with this fragment of code?
int pop = 8;
do
{
cout<< "Howdy, partner!";
pop *= 2;
}
while (pop%2 == 0); |
|
|

Return to Topic Menu
|
Computer Science Main Page |
MathBits.com
|
Terms of Use
|
Resource CD
|
|