Name:_____________________
SID (Last 4):_____________________
Login:
_____________________
CS 10 - Fall
2004
Midterm
Wednesday, October
27
Be sure to read each problem carefully and follow the directions. Points may be taken off if you do not follow the directions. For example, if the problem asks you to write code or a statement, do not write an entire program. Please feel free to ask if you have any questions. Illegible answers will not be graded.
You will not be graded on commenting. You do not need to write any comments. If, however, you do something strange that you think may be hard for the grader to figure out what you are doing, you may want to comment that part. Partial credit will be given.
Please work wisely. Do not spend too much time on any one problem.
You will be required to show your student ID when you hand in your exam.
TOTAL POINTS = 100
Mark a for TRUE and mark b
for FALSE. (2 pts each)
TRUE
FALSE
FALSE
Line myline(m.get_start(), c.get_center());
TRUE
FALSE
FALSE
TRUE
Multiple Choice. (2
pts each)
Point p(4, 4);
Message m(p, “football”);
String s = m.get_text() + m.get_text().substr(4,4);
int a = 11, b = 4, c = 10, d = 2;
What will be the value computed for the expression (a % b + c - d * 3)?
a. 6
b. 30
c. 33
d.
7
e. None of the above
int a, b;
a = 5;
a++;
a = a + 1;
b = a;
b++;
a = b;
a. 5
b. 6
c. 7
d.
8
e. None of the above
int x = 3;
int a = 12;
while(x <= a)
{
x = x + 4;
a++;
}
a. 0
b. 2
c. 3
d.
4
e. none of the above
a. 3
b. 7
c.
19
d. 23
e. none of the above
a. 12
b. 13
c. 15
d.
16
e. none of the above
Fill in the blank. Clearly write in the correct answer. (2 pts each)
if (x = 0)
{
cout << “x is 0”;
}
else
{
cout << “x is not 0”;
}
What is the exact output of the following 3 code fragments? (6 pts each)
cout << fixed << setprecision(2);
while (x < 10.0)
{
x = x + 3.5;
cout << x << “ “;
}
cout << x << endl;
4.50 8.00 11.50 11.50
cout << fixed << setprecision(1);
while (x >= 2.0)
{
cout << x << “ “;
x = x / 3.;
}
cout << x << endl;
18.0 6.0 2.0 0.7
while (y < 100)
{
y = y * 2;
cout << setw(8) << y << endl;
}
cout << y << endl;
_______4
_______8
______16
______32
______64
_____128
128
if (score >= 60)
{
cout
<< “Passing score.”;
}
else
{
cout
<< “Failing score.”;
}
#include <iostream>
using namespace
std;
int main()
{
double
number;
double
sum = 0;
int
count = 0;
cout
<< “Enter a positive number (-1 to quit): “;
cin
>> number;
while
(number >= 0)
{
sum
= sum + number;
count++;
cout
<< “Enter another number (-1 to quit):
“;
cin
>> number;
}
double
ave;
ave
= sum / count;
cout
<< “The average is: “ << ave << endl;
return
0;
}