Name:_____________________
SID (Last
4):_____________________
Login:
_____________________
CS 10 - Spring
2005
Midterm
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
Bubble in the answers to questions 1 – 17 using your personalized answer sheet.
Mark a for TRUE and mark b for FALSE. (2 pts each)
TRUE
TRUE
TRUE
TRUE
FALSE
FALSE
TRUE
Multiple Choice. (2 pts each)
a. cout << “Enter 2 integers separated by a space and then hit Enter\n”;
b. int num1;
c. int num2;
d. cin >> num1 >> num2;
e. cout << “Average: “ << (num1 + num2 / 2.0);
f.
There
are no syntax errors.
a. a
b. b
c. c
d. d
e.
e
f. There are no logic errors.
a. n != m
b. (n * m / 2 < 10) && (n % 2 != 0)
c. n * 2
d. n
e. p.get_x()
f.
p.move(n,m)
double x = 10.333;
cout << fixed << setprecision(1) << x << “ “;
x = x * 2;
cout << setprecision(3) << x;
a. 10.3 20.6
b. 10.3 20.600
c.
10.3
20.666
d. 10.333 20.666
e. 10.3 20.7
f. none of the above
a + b % 3
a. 0
b.
6
c. true
d. false
e. 5
f. none of the above
e.
a.
Circle(Point(5,3), 2.5)
Time now;
What is the exact output of the following 3 code fragments? (6 pts each)
if (temp < 70)
{
cout << “Too Cold\n”;
}
else if (temp > 90)
{
cout << “Too Hot\n”;
}
else
{
cout << “Right On\n”;
}
Too Cold
if (temp < 70)
{
cout << “Too Cold\n”;
}
if (temp > 90)
{
cout << “Too Hot\n”;
}
else
{
cout << “Right On\n”;
}
Too Cold
Right On
if (y < 10)
{
cout << y;
y = y * 2;
cout << setw(y) << y << “ “;
}
cout << y;
8 16 16
if (str1.length() < str2.length())
{
cout
<< str1;
}
else if (str2.length() < str1.length())
{
cout
<< str2;
}
else
{
cout
<< str1 << endl << str2;
}
#include <iostream>
using namespace
std;
int main()
{
int
num1, num2;
cout
<< “Enter 2 positive integers separated by a space: “;
cin
>> num1 >> num2;
if
(num1 <= 0 || num2 <= 0)
{
cout << “Invalid Input\n”;
}
else
if (num1 % 2 == 0 && num2 % 2 == 0)
{
cout << “Both even\n”;
}
else
if (num1 % 2 == 1 && num2 % 2 == 1)
{
cout << “Both odd\n”;
}
else
{
cout << “One even and one
odd\n”;
}
return
0;
}