Name:_____________________
SID (Last
4):_____________________
Login:
_____________________
CS 10 - Winter
2005
Midterm
Friday,
February 4
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)
FALSE
FALSE
FALSE
FALSE
4.321 = x;
FALSE
5 == y
TRUE
Line side_top = Line( (4,5), (5,5) );
FALSE
Multiple Choice. (2 pts each)
(0 == (a % 2))
a. 0
b. 5
c. 10
d.
true
e. invalid expression (syntax error)
f. None of the above
Time t1 = Time(4,5,30);
t1.add_seconds(60);
cout << t1.get_seconds();
a. 0
b. 6
c.
30
d. (4,6,30)
e. 90
f. None of the above
Use the following code fragment for the next 3 questions.
int x = 10;
int a;
cout << “Enter an integer”;
cin >> a;
if (x < a)
{
x = x * 4;
}
else if (x == a)
{
x = x + 4;
}
else
{
x++;
a = x;
}
a. 10
b. 11
c.
14
d. 15
e. 40
f. none of the above
a. 10
b. 14
c. 20
d.
40
e. 45
f. none of the above
a. 0
b. 10
c.
11
d. 14
e. 40
f. none of the above
Fill in the blank. Clearly write in the correct answer. (2 pts each)
What is the exact output of the following 3 code fragments? (6 pts each)
cout << fixed << setprecision(1);
if (x <= 10.0)
{
cout << x << “ “;
x = x + 10.275;
}
cout << x << “\n”;
1.0 11.3
cout << fixed << setprecision(3);
if (x > 2.0)
{
cout << x << “ “;
x = x + 10.275;
}
cout << x << “\n”;
1.000
if (y < 10)
{
y = y % 5;
cout << y << “\n”;
}
else
{
y = y % 10;
cout << y << “\n”;
}
cout << y << “\n”;
8
8
if
(temperature < 70 or rainfall > 0.2)
{
cout << “Grab your
jacket”;
}
else
{
cout << “No jacket
required”;
}
#include
<iostream>
using namespace std;
int
main()
{
int score;
cout << “Enter the exam
score”;
cin >> score;
cout << “Grade: “;
if (score >= 100)
{
cout
<< “A+ ”;
}
else if (score >= 90)
{
cout
<< “A ”;
}
else if (score >= 80)
{
cout
<< “B ”;
}
else if (score >= 70)
{
cout
<< “C ”;
}
else if (score >= 60)
{
cout
<< “D ”;
}
else
{
cout
<< “F “;
}
if (score >= 70)
{
cout
<< “Great Job!\n”;
}
else
{
cout
<< “Study harder.\n”;
}
return 0;
}