Midterm 1 Review Quiz 08

while x 1 h for int i 0 i 2 i for

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: more
unspecified
C++
 statements,
some
of
which
may
change
the
values
of
program
variables.
 
 
 Problem
1:
25
points.
 
 What
is
the
output
of
each
of
the
following
segments
of
code?
 
 (a) int a = 2; cout << a;
 (b) 
 int a = 2; cout << “a”;
 
 
 
 (c) 
 int a = 2.5; cout << a;
 
 
 
 (d) 
 bool b = (5 > 4) && (2 != 0); cout << b;
 
 
 
 (e) 
 int a = 99; cout << a++;
 
 
 
 
 (f) 
 if (5 % 4) { cout << “Baa!”; } else { cout << “Moo!”; }
 
 
 
 
 
 
 
 (g) 
 int x = 1; do { cout << “Woof!”; } while (x > 1);
 
 
 
 
 (h) 
 for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { cout << i*j << ‘t’; } cout << endl; }
 Problem
2:
25
points.
 
 State
whether
each
segment
of
code
is
valid
C++.

If
it
is
not
valid
C++,
fix
it
so
that...
View Full Document

This note was uploaded on 02/08/2014 for the course CS 115 taught by Professor Staff during the Fall '08 term at Sonoma.

Ask a homework question - tutors are online