CSCI 116 Fall 2015 Exam #1

Directions: This test is closed book, closed notes, closed computer, closed cell phone, closed neighbor—in fact closed everything except open mind.  Write your answers legibly in the space provided.  If you need more space, use the back of one of the test pages and indicate where I can find your answer.  Write legibly—if I can’t read it, I assume it’s wrong.  You have 50 minutes to complete the test, so read through the test completely before answering any questions.  This way you can find the easiest questions and answer them first in order to maximize your score.  Each part is worth 5 points.  Not counting bonus questions, there are 100 points on the test.  Good luck and have fun.

 

1.     What are the five intrinsic data types C++ supports?

 

 

 

 

 

 

 

 

 

 

 

 

2. Which of the following variable names are legal?  _a_b_c_, A_B_C, 4h, lOoP-tEsT, TheBigOne

 

 

 

 

 

 

 

 

 

 

3.     Assume that at the start of each question x has the value 1 and y has the value 2.  What is the value for each of the following expressions?  If the expression is illegal, say so.

a.     x + y

 

 

 

 

 

 

b.     2 / 3 * 6

 

 

 

 

 

 

 

c.     3+4  *  2+5

 

 

 

 

 

 

 

d.     x < y

 

 

 

 

 

 

 

e.     x++

 

 

 

 

 

 

 

f.      2+++y

 

 

 

 

 

 

 

g.     ((3 > 5) && (7 < 9))

 

 

 

 

 

 

 

 

 

h.     (((2 > 4) && (10 < 20)) || (3 < 6))

 

 

 

 

 

 

 

i.       ++x == y++

 

 

 

 

 

 

 

j.       12.6 / 6

 

 

 

 

 

 

 

4.     Write an if statement that tests the value in x.  If it is 5, increment y by 1, if it is greater than 10, decrement y by 1, and if is less than 0, set y to be 12.

 

 

 

 

 

 

 

 

 

 

 

 

 

5.     Write a while loop that adds up the first n positive integers, where n was specified in a previous part of the program.

 

 

 

 

 

 

 

 

 

6.     Write a for loop that computes the sum of the first 50 multiples of 3.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7.     Write C++ code to declare fin to be an input file variable.

 

 

 

 

 

 

 

 

 

 

8.     Write C++ code to associate fin with the file data.txt.

 

 

 

 

 

 

 

 

 

 

9.     What file do you include to be able to use setw?

 

 

 

 

 

 

 

 

 

 

 

 

10.  Write C++ code to close and clean up the file associated with the variable fin.

 

 

 

 

 

 

 

 

 

 

 

11.  Give an example where short circuit evaluation can cause the output of a program to be undetermined until runtime.


BONUS: Sudoku…each row, column, and highlighted 3x3 square should have each of the digits 1 through 9 in it exactly once.  Fill in the empty squares to make it so.

 

 

 

 

 

5

 

9

 

 

 

3

 

4

 

1

5

6

 

6

 

 

9

 

3

 

1

8

 

6

 

 

 

 

2

9

 

3

 

 

8

 

2

 

 

7

 

5

4

 

 

 

 

8

 

4

2

 

5

 

9

 

 

6

 

8

9

3

 

7

 

2

 

 

 

6

 

8