AP Computer Science Semester 2 Final Exam
Consider the JavaScript code segment below. Which statement should be used in place of <missing code> such that the alarm is set to 9:00 am on weekends, and 6:30 am on weekdays?
(day == "Saturday") II (day == "Sunday")
Assume that a variable temperature is assigned like this: Var temperature = 30; Choose the two (2) Boolean expressions that evaluate to FALSE.
(temperature == 0) II (temperature > 32) & (temperature < 0) II (temperature > 32)
From the list of possible outputs listed two (2) are IMPOSSIBLE. Choose the two (2) outputs that are impossible for this code to produce. X <= 0 REPEAT_UNTIL(x = 3) Y <= 0 REPEAT_UNTIL(y = 3){ Y <= y + 1 X <= x + 1 DISPLAY(x+ "," +y) { {
0,0 & 2,4
Consider the following flow chart showing a process for program execution. Given that a = 5, and b = 10, what will be displayed by the program?
10
Given the following array, what will the code segment below display after being run? The initial state of the array is shown for you to use as a reference. Data = [5,8,3,4,2,1] Index = 1,2,3,4,5,6 A <= data[5] B <= data[2] DISPLAY(a+b)
10
What is contained in the list data after the following code segment is run? Data <= [10,45,38,16,23] Index = 1,2,3,4,5 REMOVE(data,2) REMOVE(data,3)
10,38,23
A programmer designed a program for an airline to determine whether there is an extra fee on a checked bag. The logic is shown in the flow chart at right. The code they wrote (see below) runs without error, unfortunately it does not work as intended. What is the problem? Consider the list of values below and choose two that if assigned to weight will result in the incorrect message being displayed as the response (choose 2)?
125
What is the output to the console after the following code segment is executed?
13
What does the following code segment display? Data <= [3,5,8,2,1] Index = 1,2,3,4,5 REMOVE(data,3) DISPLAY(data[3])
2
What value will be displayed after the loop has executed? Var a = 5; While (a >= 3){ A = a -1; } console.log(a);
2
A student decides to draw a series of three dots as shown in the diagram. How would she adjust line 2 and 3 to implement the change?
2 var middle & Var top = middle
The counter variable in the code below increments by 1 each time through the loop. What will the value of counter be after the following loop executes? Var counter = 0; Var n = 6; While (n>0){ Counter = counter +1; } console.log(counter)
3
What is stored in list data after the following code segment is run? Data <= [0,1,2] INSERT(data, 1,3) INSERT(data, 2,4) INSERT(data, 3,5) DISPLAY(data) Data = [0,1,2] Index= 1,2,3
3,4,5,0,1,2
What will be displayed after the loop has executed? Var a = 5 While (a>5) { A = a - 1; } console.log(a);
5
What is the output of the following JavaScript code segment?
55
What is the output of the following JavaScript code segment?
5hello
Consider the following code segment that appends numbers to a list one at a time. Data <= [] Append (data,2) Append (data,6) Append (data,9) Append (data,3) Append (data,1) What is the value of data[2] after the code above is executed (Assuming indexing begins with 1)?
6
What is the output of the code segment below? The initial state of the array is shown for you to use as a reference. Data = [5,8,3,4,2,1] Index = 1,2,3,4,5,6 I <= 4 A <= data[i] B <= data[i + 1] DISPLAY(a+b)
6
Pick the two expression involving the Modulo operation that compute to the exact same value.
9MOD8 & 1MOD16
Choose the answer that is NOT a feature of Public Key Cryptography
A Public Key database ensures 3rd party accountability of security
When might a programmer create a global variable instead of a local variable?
A global variable's scope can be used and updated by any part of the code. The variable is declared (created) outside of any function, object, or method. A local variable is a variable whose scope can only be seen, used and updated by code within the same scope. Typically this means the variable was declared (created) inside a function--includes function parameter variables.You would use a global variable when you are going to use the variable many times throughout the code, whereas you would use a local variable if you are going to use that variable very few times, most likely once, throughout your code.
Which of the following statements best describes the properties of public key encryption?
A public key encryption is an encryption method which relies on separate keys for encrypting and decrypting information
Consider the code segment below. Var a = 0 Var b = 3 Var c = 4 A = a+c B= a+c C= a+c
A= 4, B= 0, C= 0
Two students, Keri and Adam, are arguing in class about an App Lab project. Adam states, "Huh, a button and an image are basically the same thing!". Keri replies, "That doesn't make any sense at all!". Explain what Adam may have meant by that statement.
Adam may have said that because you can visually see a button and an image, but they both have different functions in the user interface. An image is just a visual representation and a button is an interactive UI element that connects to a command.
Tiffany is writing a program to help manage a bake sale. She writes the following code which prompts the user to enter the total number of items a person is buying and then a loop repeatedly prompts for the cost of each item. She wrote the code, but there is a problem: it runs in an infinite loop. How can Tiffany change her code so it doesn't loop forever? O -var numItems = promptNum("How many items?"); 1 -var total = 0; 2 -while (numItems > 0){ 3 -total = total + promptNum("Enter next item price"); 4 -} 5 -console.log("The total is" + total);
Add after line 3: numItems-1;
What is a Distributed Denial of Service (DDoS) attack?
An attempt to compromise a single target by flooding it with requests from multiple systems.
Which of the following is false about element IDs?
An element with a unique ID must always have an event handler associated with it.
A programmer wrote an essay for his history class, and realized he has confused the names of Benjamin Franklin and Alexander Graham Bell. Instead of going through the whole paper and changing the names, he used the following incorrect algorithm in an attempt replace every occurrence of "Benjamin Franklin" with "Alexander Graham Bell" and vise versa: First, change all occurrences of "Benjamin Franklin" to "apple" Then, change all occurrences of "apple" to "Alexander Graham Bell". Then, change all occurrences of "Alexander Graham Bell" to "Benjamin Franklin". Here is an example of one of the sentences from the paper: Alexander Graham Bell was born 141 years before Benjamin Franklin, so he was never able to telephone his neighbors. Which of the following is the result of running the described incorrect algorithm on the sentence above?
Benjamin Franklin was born 141 years before Benjamin Franklin, so he was never able to telephone his neighbors.
What is the possible output when the following code segment executes? The ending position of the turtle is shown in each diagram. The starting position is shown as a white triangle in cases where the turtle starts and ends in different locations.
C
Which of the following are actions a programmer could take when debugging a segment of code that would most likely lead to finding a problem and fixing it?
Display the value of the variables at various points during the program & Ask a friend or collaborator to look over the code segment to see if they are able to find any errors.
Which of the following images is the most likely outcome of the drawing?
Drawing with the square with the turtle in the left
What is the output to the console after the following code segment is executed?
Error, unknown identifier x
Which of the following is false about event-driven programming?
Event-driven programs do not implement algorithms.
Which of the following are true statements about digital certificates in Web browsers? I. Digital certificates are used to verify the ownership of encrypted keys used in secured communication. II. Digital certificates are used to verify that the connection to a Website is fault tolerant.
I Only
In JavaScript you can find the number of characters in String by using .length. For example: For the next to questions consider the following JavaScript code segment. If above code segment is run and "hello" is entered at the prompt, what will be displayed in the console?
I have never heard that before.
.A pseudocode program is started below that asks the user for input and stores the value in a variable. Continue writing pseudocode to accomplish this task: If the hour is within the school day (8 to 15) then display "Nice to see you!", Otherwise, display "It's time to go home!"
IF (hour >=8) AND (hour<=15) { DISPLAY ("Nice to see you!") } ELSE{ DISPLAY ("It's time to go home!") }
A programmer created a list of all of her siblings' ages: Unfortunately, she made a typo! Her middle sibling is 13 years old. Which of the following solutions will NOT fix the typo? Data = [10,12,17] Index = 1,2,3
INSERT the value 13 at the index of 2
What will be displayed as a result of the JavaScript code below executing? Var a = 0; While (a != 5){ A = a + 2; } console.log(a);
Infinite loop
Which of the following most accurately describes Moore's Law?
Moore's Law is the observation that computing power tends to double every two years.
Which of the following statements about strings in JavaScript is FALSE?
Strings with numerical digits in them are invalid.
Fill in the blank of the following statement: "___ encryption is a method of encryption involving one key for both encryption and decryption."
Symmetric
Consider the code segment below given in pseudocode (see reference above). Assuming that variables a,b, and c already have numeric values assigned to them, what is the expected output of this code segment?
The code will display the largest of the three values.
A programmer is writing a system that is intended to be able to store large amounts of personal data. As the programmer develops the data system, which of the following is LEAST likely to impact the programmer's choices in designing the structure of the system?
The frequency of a particular item occurring in a data set.
Consider the following JavaScript code segment. Something is wrong with the logic in the program above. For which values of time will the greeting "Good Morning" be displayed?
There is no value of time that will result in "Good Morning" being displayed.
A Boolean expression is an expression that evaluates to which of the following?
True/False
If the above code segment is run, and "goodbye" is entered into the prompt, what will be displayed in the console?
Use that word on the SAT.
What is displayed by the console.log statement after the following segment?
Value is 4
Jose is writing a reply function for a text message app...
Var temp =
Which of the following is true about while loops in JavaScript?
While loops run as long as a given Boolean condition is true.
A coffee shop is considering accepting orders and payments through their phone app and have decided to use a public key encryption to encrypt their customer's credit card information. Is this a secure form of payment?
Yes, public key encryption is built upon computationally hard problems that even powerful computers cannot easily solve.
What is the expected output of the given pseudocode segment? A reference for the pseudocode can be found immediately below the question.
You are old enough to be President!
Which of the following scenarios is most characteristic of a phishing attack?
You get an email from the IT Support desk that asks you to send a reply email with your username and password.
Consider the following segment given in pseudocode (see reference from previous question): What will be displayed if grade is set to 70?
You passed!
The JavaScript code below creates an array of numbers and makes a call to the mystery function. The code for the mystery function is also shown and it makes use of the swap function which you should assume works as described in the previous question. mystery(data); Function mystery(data){ if(data[1] < data[0]){ swap(data,0,1); } if(data[2] < data[1]){ swap(data,0,1); } if(data[1] < data[0]){ swap(data,0,1); } } Data = [3,81] Index = 0,1,2
[1,3,8]
Jasmine is writing a shopping app. She has created a variable to keep track of the number of items in the shopping cart. Every time someone clicks the addItem button she would like the variable to decrease by one.
cartTotal= cartTotal + 1
Which of the following JavaScript statements will result in the following output being displayed to the console?
console.log("Hello!/nHow are you/");
A statistician would like to simulate rolling a single die until she has rolled the die a total of 100 times, or she rolls a six a total of 25 times, whichever come first. Which boolean expression should she use for the <missing code> to accomplish this? Var rolls = 0; Var sixes = 0; While (<missing code>){ Var nextRoll = randomNumber(1,6); if (nextRoll == 6) { Sixes = sixes + 1; } Rolls = rolls + 1; } console.log(rolls);
rolls < 100 && sixes < 25
You are trying to write a function swap(list a,b), which will swap the position of the two at indexes a and b in the list. Example: before and after a call to swap(list 1,2) on the list shown below. The function header is defined for you. Choose the 3 lines of code that will perform the swap correctly. Function swap(list a,b){ <choose option from below>
var temp = list[b] list [b] = list [a]; list [a] = temp;