You are on page 1of 3

CS 010 Intro to Computer Science I

Midterm 1 Wednesday 4/24

Spring - 2013

solution

Always choose one BEST answer for each question.


1. An operating system _____________________________.
a.
b.
c.
d.
e.

is the chief hardware unit in a computer


is loaded into the computer each time it needs to carry out an operation
ensures that programs will not run on the computer at the same time
allocates resources like memory to programs that are running
ALL OF THE ABOVE.

2. A byte in memory is identified by a unique number called its _____________.


a. instruction

b. operation

c. identity

d. address

3. _____________ is a named location in memory used to store data.


a. An expression

b. A variable

c. A statement

d. A function

4. Forgetting to put a semicolon at the end of a cout statement is an example of a _________ error.
a. logic

b. syntax

c. runtime

5. The C++ statement:

cout << "She said, "Call me maybe".";


is supposed to output:
She said, "Call me maybe".
This cout statement has _______________.
a. a runtime error

b. a syntax error

c. no errors

6. Assuming the int variables m and n store the values 1 and 0 respectively, the C++ statement:

m = m / n;
has ________________.
a. a runtime error

b. a syntax error

c. no errors

7. What value is stored in the variable n after the following statements?


a. 2

int n = 2;
n = n + 10 / n;
b. 6

c. 7

d. 12

8. What value is stored in the variable n after the following statements?


int n = 10;
cout << n / n;

a. 1

b. 10

9. What is the value of the C++ expression: (486 / 10)?


a. 4.86

b. 48.6

c. 48

d. 49

e. 86

f.

e. 514

f.

10. What is the value of the C++ expression: (486 % 10)?


a. 4.86

b. 48.6

c. 48

d. 4

11. What is the value of the C++ expression: static_cast<double>(7 / 4)?


a. 1.75

b. 7

c. 2

d. 1.0

e. 2.0

f.

0.0

12. What is the value stored in s after the following statements execute if when prompted for input

the user enters the characters in the box and then presses the Enter key.
string s = "default";
cout << "What's your name? ";
cin >> s;

a. Kobe Bryant
b. Kobe

user input
Kobe Bryant

c. Bryant
d. k

e. t
f. default

13. What is the value stored in n after the following statements execute if when prompted for input

the user enters the characters in the box and then presses the Enter key.
int n = 0;
cout << "Enter a number: ";
cin >> n;

a. 0

b. 1

user input
12abc

c. 2

d. 12

e. 12abc

f.

'c'

14. What is output by the following statements if when prompted for input the user enters the

characters in the box and then presses the Enter key.


int n1 = 10, n2 = 20;
char c = 'a';
cout << "Enter 2 integers: ";
cin >> n1 >> c >> n2;
cout << n1 << " " << n2 << "

a. 10

20

b. 34

978

user input
34 978

" << c << endl;

c. 34

20

d. 34

78

15. What is output by the following code fragment?


string s = "Lakers vs. Spurs";
for (int pos = 0; pos < s.size() && s.at(pos) != '.'; ++pos)
cout << s.at(pos/2);

a. Lakers vs
b. LLaakkeer

c. Lakers vs.
d. LLaakkeerrss

vvss

e. Lake
f. Laker

16. What is the value of the following expression assuming the int variable n stores the value -5 and

the bool variable more stores the value true?


(n >= 0 && more)
a. true

b. false

17. What is the value of the following expression assuming the int variable n stores the value 20?

(n >= 0 || n <= 10)


a. true

b. false

18. What will be output by the following code fragment?


int n = 0;
for (int i = 100; i >= 2; i = i / 2)
++n;
cout << n << endl;

a. 100

b. 98

c. 50

d. 48

e. 6

f.

19. What is output by the following statements?


int n = 10;
string s = "xyz";
if (n < 100)
s = "ab";
else if (n < 50)
s = "bc";
else
s = "ac";
cout << s << endl;

a. ab

b. bc

c. ac

d. abbc

e. bcac

f.

abac

d. abbc

e. bcac

f.

xyz

20. What is output by the following statements?


int n = 10;
string s = "xyz";
if (n < 100)
s = "ab";
if (n < 50)
s = "bc";
else
s = "ac";
cout << s << endl;

a. ab

b. bc

c. ac

21. What is output by the following statements?


int n = 10;
string s = "xyz";
if (n > 10)
{
if (n < 100)
s = "ab";
else if (n < 50)
s = "bc";
else
s = "ac";
}
cout << s << endl;

a. ab

b. bc

c. ac

d. xyz

22. What is the value stored in sum after the following statements execute if when prompted for

input the user enters the characters in the box and then presses the Enter key.
int sum = 0;
int entry = -1;
cout << "Enter several integers all on one line: ";
while (entry <= 10)
{
cin >> entry;
sum = sum + entry;
}

a. 2

b. 12

c. 19

d. 31

user input
1 5 8 3 2 12 7 0

e. 38

f.

37

You might also like