Computer Science Midterm Exams Questions With
Complete Solutions
A program that Thomas has written is complete. It has been
tested thoroughly, and some outputs were not as expected.
Thomas is now going through the code carefully attempting to
establish the cause of these errors and change the code to
remove them. What is this procedure called? Correct Answer
Debugging
A statistics teacher wishes to create a program on her calculator
that generates a random even integer. The command built in the
calculator to generate a random positive integer is
RANDOM(a,b). This command generates a random integer
between integers a and b (and including a and b). Which of the
following lines of code will ensure that the random integer
generated will be even? Correct Answer RANDOM(a,b) * 2
A student developed a program that outputs the name of a fruit
that begins with a letter, dependent upon the variable
keyPressed, which stores the letter (from A to Z only) a user
types on the keyboard. Below is a section of code from her
program:
Which of the following descriptions below would be a way that
this student might have written the rest of her code so that it
executes as intended? Select two answers. Correct Answer Use
25 nested IF/ELSE blocks where the IF portion is formatted like
the code segment above (changing the letters of the alphabet and
fruits) and the else simply holding the next IF portion until the
last ELSE, which displays a fruit that begins with Z.
,Use 26 IF blocks formatted similarly to the one above (changing
the letters of the alphabet and fruits).
A team of students is collaborating on a program to obtain local
weather data from a website, and predict weather-related school
closings based on their own formulas. They must present their
code to a group of faculty, some of whom have little to no
experience with code. What strategies can the group use while
writing their code, in order to make it more understandable for
the faculty?
Select two answers. Correct Answer Choose meaningful names
for all variables and procedures.
Include comments detailing the purpose and behavior of
variables and procedures.
Consider a robot that is initially facing north in a 5-by-5 grid, as
shown in the diagram below. A program segment has been
written to move the robot to the upper-right corner where it
should face west.
The following program segment is intended to move a robot
from the starting position to the ending position as shown above.
However, the program segment does not work correctly.
Which 2 lines of code in the segment above must be switched in
order for the program to correctly move a robot from the starting
position to the ending position? Select two answers. Correct
Answer Line 7
, Line 5
Consider the code segment below.
Line 1: IF (b ≠ 0)
Line 2: {
Line 3: a ← a/b
Line 4: }
Line 5: ELSE
Line 6: {
Line 7: a ← a*b
Line 8: }
Which of the following changes will NOT affect the results
when the code segment is executed? Correct Answer Changing
line 7 to a ← 0
Consider the following actions which might be performed by a
developer when creating a new piece of software to solve a
problem.
1. Thoroughly testing code with a variety of inputs
2. Designing an algorithm to tackle the central problem the
program hopes to solve
3. Considering what outputs a program solving the problem
might produce and what inputs it may require to do this
4. Writing code in a high-level programming language to
implement an algorithm
In which order in the development cycle would these actions
first appear? Correct Answer 3,2,4,1
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Classroom. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $10.99. You're not tied to anything after your purchase.