Docsity

CS105 Spring 2010 Exercise Solutions - Prof. Thomas N. Gambill, Exams of Computer Science

Toggle sidebar
bg1
Final CS105 Spring 2010
May 7th, 2010
DO NOT START UNTIL INSTRUCTED TO DO SO. YOU WILL LOSE POINTS IF YOU START
WORKING ON THE TEST BEFORE WE TELL YOU. THIS IS A 150 MINUTE EXAM.
Do not leave this blank—fill it in now:
Name:
Discussion Section:
TA:
FORM
A
On the scantron:
Use only a #2 pencil; otherwise, your exam won't be graded.
Bubble in the Form Letter above!!! Bubble in your name and your NetID!!!
Write your TA's name (of the section you attend) in the instructor slot and your section number
in the section slot. Your section number is in the table provided at the bottom of this page.
About the test:
The exam consists of 33 pages. Check that your copy is complete, and ask for a replacement if it
is not. Make sure you look at all the pages.
You will have 2 hours and 30 minutes to FILL IN THE SCANTRON for the exam. You may
not use any books, notes, or other references for this exam.
NO QUESTIONS WILL BE ANSWERED DURING THE EXAM.
At the end of the exam, stop writing and put down your pencil when time is called. Hand in both
the scantron and all the pages of the exam booklet.
NO CALCULATORS OR ELECTRONIC DEVICES OF ANY KIND ARE ALLOWED. TURN
OFF CELL PHONES AND PAGERS. IF A CELL PHONE RINGS, DO NOT ANSWER IT!!
Discussion section numbers and name of the TA whose lab you attend:
Time
Wednesday
Thursday
Friday
9:00 am
105 – Ankeeth
113 – Damion
10:00 am
106 – Ankeeth
114 – Damion
11:00 am
107 – Aditya
115 – Yi-Shuan
12:00 pm
108 – Aditya
116 – Yi-Shuan
1:00 pm
109 – Chaitanya
117 – Ankit
2:00 pm
101 – Minas
110 – Chris
118 – Ankit
3:00 pm
102 – Minas
111 – Chris
119 – Chaitanya
4:00 pm
103 – Boonrod
112 – Bhagath
5:00 pm
104 – Onur
NOTES:
1. Always choose one answer, the most correct choice of the answers offered.
2. For all questions with code fragments, the line numbers on the left are NOT part of the code.
3. Assume that any VBA variables shown have been declared according to the course convention.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21

Partial preview of the text

Download CS105 Spring 2010 Exercise Solutions - Prof. Thomas N. Gambill and more Exams Computer Science in PDF only on Docsity!

May 7

th

DO NOT START UNTIL INSTRUCTED TO DO SO. YOU WILL LOSE POINTS IF YOU START WORKING ON THE TEST BEFORE WE TELL YOU. THIS IS A 150 MINUTE EXAM.

Do not leave this blank—fill it in now:

Name: Discussion Section: TA:

FORM

A

On the scantron:

 Use only a #2 pencil; otherwise, your exam won't be graded.  Bubble in the Form Letter above!!! Bubble in your name and your NetID !!!  Write your TA's name (of the section you attend) in the instructor slot and your section number in the section slot. Your section number is in the table provided at the bottom of this page.

About the test:

 The exam consists of 33 pages. Check that your copy is complete, and ask for a replacement if it is not. Make sure you look at all the pages.  You will have 2 hours and 30 minutes to FILL IN THE SCANTRON for the exam. You may not use any books, notes, or other references for this exam.  NO QUESTIONS WILL BE ANSWERED DURING THE EXAM.  At the end of the exam, stop writing and put down your pencil when time is called. Hand in both the scantron and all the pages of the exam booklet.  NO CALCULATORS OR ELECTRONIC DEVICES OF ANY KIND ARE ALLOWED. TURN OFF CELL PHONES AND PAGERS. IF A CELL PHONE RINGS, DO NOT ANSWER IT!!

Discussion section numbers and name of the TA whose lab you attend:

Time Wednesday Thursday Friday 9:00 am 105 – Ankeeth 113 – Damion 10:00 am 106 – Ankeeth 114 – Damion 11:00 am 107 – Aditya 115 – Yi-Shuan 12:00 pm 108 – Aditya 116 – Yi-Shuan 1:00 pm 109 – Chaitanya 117 – Ankit 2:00 pm 101 – Minas 110 – Chris 118 – Ankit 3:00 pm 102 – Minas 111 – Chris 119 – Chaitanya 4:00 pm 103 – Boonrod 112 – Bhagath 5:00 pm 104 – Onur

NOTES:

1. Always choose one answer, the most correct **choice of the answers offered.

  1. For all questions with code fragments, the line numbers on the left are NOT part of the code.
  2. Assume that any VBA variables shown have been declared according to the course convention**.

Computer Concepts and Logic

  1. Which of the following is NOT computer hardware?

a. DVD/CD-RW Drive b. SQLYog c. Hard Drive d. Keyboard

  1. Which of the following is NOT a valid logical equivalence of formulas (where we have used the

equal sign “=” to denote logical equivalence)?

a. A = NOT(NOT A) b. NOT(A OR B) = (NOT A) AND (NOT B) c. A = A AND A d. A OR B = A AND B

  1. What is a file?

a. The work done by a CPU. b. A named collection of data that exists on a storage medium. c. A hardware storage device. d. Precisely those computer programs that are not currently running on a computer.

  1. What is the decimal number 63 in binary?

a. 101010 b. 110011 c. 111111 d. 101101

  1. What is the total in decimal after adding the binary numbers 110011 + 101010?

a. 93 b. 89 c. 59 d. 25

Use the following diagram for the NEXT question.

  1. Which of the following is NOT a valid pair of values for A and B in the above diagram?

a. A = 1 and B = 1 b. A = 1 and B = 0 c. A = 0 and B = 1 d. A = 0 and B = 0

A B A B

OR OR

AND

Excel

Use the following figure for the NEXT question.

  1. What are A , B , C and D?

A B C D

a. Name box Fill handle Active cell Formula bar b. Name box Formula bar Fill handle Active cell c. Active cell Formula bar Fill handle Name box d. Active cell Fill handle Formula bar Name box

A

B

C

D

Use the following figure for the NEXT THREE questions.

  1. Which of the following will give a different result from the other three answer choices if entered into

cell B6?

a. =SUM(B5,B4,B3,B2)/ b. =SUM(B2:B5)/COUNT(B1:B5) c. =AVERAGE(B2:B5) d. =(B$2+B$3+B$4+B$5)/COUNTA(B1:B5)

  1. Given the contents of the spreadsheet shown in the figure above what is the result of the formula, =COUNTIF(B2:B5,">"&AVERAGE(B2:B5))

a. 1 b. 2 c. 3 d. 4

  1. Given the contents of the spreadsheet shown in the figure above what is the result of the formula, =SUMIF(B2:B5,">"&40,C2:C5) (Hint: the SUMIF function is defined as: SUMIF(RANGE, CRITERIA, SUM_RANGE))

a. 140 b. 141 c. 175 d. 181

Use the following screenshot for the NEXT question.

  1. Refer to the above screenshot. When using Goal Seek for cell B4 , which of the cells CANNOT be used in the “By Changing Cell:” field?

a. B b. B c. B d. B

Use the following figure for the NEXT question.

  1. In the above figure what value would the cell B1 display if the formula =MIN(A3:D3,B3:B5)+MAX(C3:C5,A5:D5) was typed in cell B1?

a. 75 b. 77 c. 65 d. 90

Use the following figure for the NEXT question.

  1. Which of the following formulas entered in cell C2 would display the value “B”?

a. =VLOOKUP(B2,B5:D8,3) b. =VLOOKUP(B2,B5:D8,2) c. =HLOOKUP(B2,B5:D8,3) d. =VLOOKUP(B2,C5:D8,2)

  1. Which of the following formulas would produce a different result than the other three?

a. =IF(A1<10, IF(A1>5, 0, 1), 0) b. =IF(A1>5, IF( A1<10, 1, 0), 0) c. =IF(AND(A1<10, A1>5), 1, 0) d. =IF(OR(A1<=5, A1>=10), 0, 1)

  1. Suppose we have a workbook with two spreadsheets named Price and Surcharge. We want to compute the sum of cell A2 in the Price worksheet and cell B3 in the Surcharge worksheet and display the result in cell D1 in the Surcharge worksheet. What is the correct formula to enter in cell D1 in the Surcharge worksheet?

a. = A2 + B b. = A2 + Surcharge!B c. = A2 + 'Surcharge'!B d. = Price!A2 + B

VBA

  1. Suppose that cell C7 is selected. Which are the correct values after executing the following two lines of code?

Cells(1, 2).Value = ActiveCell.Row Cells(4, 5).Value = ActiveCell.Column

a. A2 = 3 E4 = 7 b. A2 = 7 E4 = 3 c. B1 = 7 D5 = 3 d. B1 = 7 E4 = 3

  1. Assume that B1 is the active cell before the statement below is executed. How many cells do the

statement below select?

ActiveCell.Offset(2,0).Range("A1:B2").Select

a. 1 b. 2 c. 3 d. 4

  1. Which of the following is NOT true about the variable named mintScore as per the CS105 naming convention?

a. It is a module level variable. b. It stores an integer. c. It needs to be declared in every subprocedure. d. Its value can be changed in any subprocedure.

Use the following code fragment to answer the NEXT question. (Remember the course convention for declaring variables.)

Public Function MonthName(intChoice As Integer) As String

  1. Which of the following is a valid way to call the function named MonthName?

a. MonthName(5) = intMonth b. strName = MonthName("Jan") c. intMonth = MonthName(5) d. strName = MonthName(5)

Use the following two code fragments to answer the NEXT question.

Select Case intNumber Case 1, 2, 3, 4 MsgBox "Green" Case Is < 10 MsgBox "Blue" Case Else MsgBox "Red" End Select

If intNumber < 5 Then MsgBox "Green" ElseIf intNumber < 10 Then MsgBox "Blue" Else MsgBox "Red" End If

  1. For any given integer value (positive, negative, or zero) for intNumber, which of the following is

TRUE regarding the two code fragments?

a. For some integer values, the IF statement will display a Message Box while the CASE statement will not display anything. b. They will never display the same Message Boxes for any value of intNumber. c. For some integer values, they will display different Message Boxes. d. They will always display the same Message Boxes for any value of intNumber.

Use the following code fragment for the NEXT question.

Dim intCounter As Integer intCounter = 1 Select Case intCounter Case Is <= 1 Range("A1").Value = "CS105" Case 1 Range("A1").Value = "VBA" Case 2 Range("A1").Value = "SQL" Case Else Range("A1").Value = "EXCEL" End Select

  1. What is displayed in cell A1 after the above code fragment is executed?

a. CS b. VBA c. SQL d. EXCEL

Use the following code fragment for the NEXT question.

Private Sub cmdAnswer_Click() Dim vntAnswer As Variant

vntAnswer = InputBox("Please type your answer.", "Answer") If IsNumeric(vntAnswer) Or vntAnswer = "" Then MsgBox "Your answer is a number or empty" ElseIf vntAnswer <= 100 Then MsgBox "Your answer is equal to or less than 100" ElseIf vntAnswer = 100 Then MsgBox "Correct answer" Else MsgBox "Totally incorrect answer" End If End Sub

  1. In the subprocedure above, what message will be displayed in a Message Box when a user enters 100 in the Input Box?

a. Your answer is a number or empty b. Your answer is equal to or less than 100 c. Correct answer d. Totally incorrect answer

  1. Which of the following code fragments correctly implements the logic of the flowchart below?

a. If^ intCustomers^ >^50 Then MsgBox "Sorry, the restaurant is full." End If If intSize > 50 Then MsgBox "Sorry, our tables are not large enough." Else MsgBox "Welcome and enjoy your meal" End If b. If^ intCustomers^ >^50 Then MsgBox "Sorry, the restaurant is full." Else MsgBox "Welcome and enjoy your meal" End If If intSize > 50 Then MsgBox "Sorry, our tables are not large enough." Else MsgBox "Welcome and enjoy your meal" End If c. If^ intCustomers^ >^50 Then MsgBox "Sorry, the restaurant is full." ElseIf intSize > 50 Then MsgBox "Sorry, our tables are not large enough." Else MsgBox "Welcome and enjoy your meal" End If d. If^ intCustomers^ >^50 Then MsgBox "Sorry, the restaurant is full." If intSize > 50 Then MsgBox "Sorry, our tables are not large enough." Else MsgBox "Welcome and enjoy your meal" End If End If

Use the following code fragment for the NEXT question.

Dim intArr() As Integer Dim intN As Integer, intX As Integer, intI As Integer

intX = 0 intN = 4 ReDim intArr(1 To intN)

For intI = 1 To intN intArr(intI) = intI Next intI

For intI = 1 To intN intX= intX + intArr(intI) Next intI

  1. What is the value of intX after the code above has been executed?

a. 7 b. 8 c. 9 d. 10

Use the following code fragment for the NEXT TWO questions.

intSum = 0 For intRow = 1 To 10 Step 3 intSum = intSum + intRow Next intRow Range("A1").Value = intRow Range("A2").Value = intSum

  1. What would be the value of cell A1 after the above code is executed?

a. 10 b. 35 c. 13 d. 22

  1. What is the value of cell A2 after the above code is executed?

a. 12 b. 22 c. 35 d. 40

Use the following code fragment to answer the NEXT question.

Sub cmdTable_Click() Dim intX As Integer Dim intY As Integer

For intX = 1 To 4 For intY = 1 To 4 Cells(intX, intY).Interior.Color = vbBlue Next intY Next intX End Sub

  1. After the command button cmdTable is clicked how many cells are painted blue?

a. 4 b. 8 c. 16 d. 32

Use the following code fragment to answer the NEXT question.

For intX = 1 To 3 For intY = 1 To 4 Cells(intY, intX).Interior.Color = vbBlue Next intY Next intX

  1. What is the last cell to be painted blue?

a. C b. D c. C d. D

Use the following code fragment for the NEXT question.

Sub cmdTable_Click() Dim intY As Integer Dim intX As Integer

For intX = 1 To 4 For intY = 1 To 4 Cells(intX, intY).Value = intX * intX * (-intY) Next intY Next intX End Sub

  1. What is the value of cell D3 after the above code is executed?

a. - b. - c. - d. 48

Use the following code fragment for the NEXT TWO questions.

1: Dim intA As Integer 2: Dim intB As Integer 3: intA = 1 4: Do While intA < 5 5: For intB = 1 to 5 Step 2 6: intA = intA + 1 7: Next intB 8: Loop 9: [A1].Value = intA

  1. How many times does line 6 get executed?

a. 3 b. 4 c. 5 d. 6

  1. What would be the value of cell A1 after the code fragment above has been executed?

a. 4 b. 5 c. 6 d. 7