AP Computer Science Principles Semester 1
What is the proper format for a single line comment in Karel? // This is a comment /* This is a comment This is a comment
// This is a comment
What is the decimal value of 1101 base 2? 13 12 1.101 1101
13
How many different digits are used in the Hexadecimal number system? 2 10 8 16
16
How many different values can be represented using 4 bits? 4 different values 8 different values 16 different values 32 different values
16
An online store uses 8-bit binary values to identify each unique item for sale. The store plans to increase number of items it sells and is considering changing to 9-bit binary values. Which of the following best describes the result of using 9-bit values instead of 8-bit values? 2 more items can be uniquely identified 9 more items can be uniquely identified 2 times as many items can be uniquely identified 2^9 times as many items can be uniquely identified
2 times as many items can be uniquely identified
Suppose the ESPN website uses 8-bit unsigned integers to store how many points a team has scored in an NBA game.For example:0000 0010 represents 2 points and 0000 1000 represents 8 points What is the highest possible score the ESPN website could display? 256 255 11111111 128
255
A news website uses 32-bit integers to count the number of times an article has been viewed. The website is becoming more popular, and expects some of the articles to exceed the number of views that can be represented with 32 bits. In anticipation of this, the website is planning to change to 64-bit integers for the view counter. Which of the following best describes the result of using 64-bit integers instead of 32-bit integers? 2 times as many values can be represented 32 times as many values can be represented 2^32 times as many values can be represented 32^2 times as many values can be represented
2^32 times as many values can be represented
What is printed to the screen if the user enters '5' when the following program is run? var userNum = readInt("Enter your favorite number: "); var calculatedNum = (userNum * userNum) + userNum; println(calculatedNum); 5 25 30 50
30
What is wrong with this for loop? for (var i = 0, i < 10, i + 1) { move(); } JavaScript A. The for loop uses commas instead of semicolons B. It should say i++ instead of i + 1 A B A and B The for loop is correct
A and B
Why does a programmer indent their code? Helps show the structure of the code. Easier for other people to understand. A key part of good programming style! All of the above
All of the above
What kinds of elements can you store in data structures? Strings of text and numerical values Strings of text, numerical values, and graphical objects (Circles, Rectangles, etc) Strings of text, numerical values, and booleans Any kind of object so anything you can store in a variable
Any kind of object so anything you can store in a variable
What does API stand for in computer science? American Petroleum Institute After Paleozoic Index A-frame Pixel Interface Application Programming Interface
Application Programming Interface
How can we teach Karel new commands? For loop While loop Define a new function The start function
Define a new function
What does the following program do? var radius = readInt("What is the radius of the circle? "); var circle = new Circle(radius); circle.setPosition(radius, radius); add(circle); Draws a circle to the center of the canvas with size based on user inputted value Draws a circle on the canvas with the center positioned at the coordinate (0,0) Draws a circle that is positioned in the bottom right corner of the canvas Draw a circle on the canvas that always touches the top and left sides of the canvas
Draw a circle on the canvas that always touches the top and left sides of the canvas
True or false: Functions must have parameters.
False
What is the output of the following program: (Assume the user enters 'Florence' then 'Fernandez'.) var first_name = readLine("What is your first name? "); var last_name = readLine("What is your last name? "); var whole_name = first_name + last_name; println (whole_name); Fernandez Florence Florence Fernandez FlorenceFernandez Florence Fernandez
FlorenceFernandez
Which of the following statements are true about simulation models? I - Models often omit unnecessary features of the phenomena being modeled.II - The time it takes for a simulation to run increases as the underlying model becomes more complex. I only II only I and II Neither I nor II
I and II
Which of the following is true for an API? I. Allows different devices to connect with each otherII. Allows for Interactivity between devices and softwareIII. Messenger program that takes requests and delivers the response back to the userIV. Allows the creation of applications that access the features or data of an operating system, application, or other servicesV. Specifies how software components should interactVI. Used when programming graphical user interface (GUI) components I, II, III, IV, V, and VI II, III, and V VI only I, IV, and Vi
I, II, III, IV, V, and VI
Why do we write functions? I. Make our code easier to understand by giving a readable name to a group of instructionsII. Avoid writing repeated codeIII. Make our code reusable II and III I only I and II I, II, and III
I, II, and III
Super Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs? move(); move(); turnRight(); move(); JavaScript Karel ends on street 1, avenue 3 Karel ends on street 2, avenue 3 This code won't run because of a syntax error Karel will crash into a wall
Karel will crash into a wall
Which of the following returns a random number between 1 and 99? randomInt(1, 99) randInt(1, 99) Randomizer.nextInt(1, 99) Randomizer.int(1, 99)
Randomizer.nextInt(1,99)
What is the purpose of a return statement in a function? Returns the value and stops the executing the program Stops executing the function and returns the value Returns the program back to the start of the function and continues to execute statements Returns the value and continues executing rest of the statements, if there are any
Stops executing the function and returns the value
If Karel starts at Street 1 and Avenue 1, facing East, where will Karel be, and what direction will Karel be facing after running the following code? (Assume the world is 10x10 in size) move(); turnLeft(); putBall(); turnLeft(); turnLeft(); turnLeft(); move(); turnLeft(); JavaScript Street 3, Avenue 1, Facing North Street 1, Avenue 4, Facing North Street 1, Avenue 3, Facing South Street 1, Avenue 3, Facing North
Street 1, Avenue 3, Facing North
What makes the following command an invalid Karel command? turnleft(); It should end in a colon rather than a semicolon The l should be a capital L It should start with a capital T This command is correct
The l should be a capital L
A student is transferring photos from her camera to her computer. The student notices that the saved photos on her computer are lower quality than the original raw photo on her camera. Which of the following could be a possible explanation for the difference in image quality? The saved image files were compressed with a lossy compression technique. The saved image files were compressed with a lossless compression technique. The saved image files were not compressed properly. Some information is lost every time a file is saved on a computer.
The saved image files were compressed with a lossy compression technique.
Question: 1 In the following code: var size = 20; var x = 100; var y = 200; var ball = new Circle(size); ball.setPosition(x, y); JavaScript What is the meaning of the x variable? The x coordinate of the center of the circle The x coordinate of the left edge of the circle The radius of the circle The position of the circle
The x coordinate of the center of the circle
Which of the following is a true statement about data compression? Data compression is only useful for files being transmitted over the Internet. Regardless of the compression technique being used, once a data file is compressed, it cannot be restored back to its original state. Sending a compressed version of a file ensures that no one can read the contents of the file except for the intended recipient. There are trade-offs involved in choosing a compression technique for storing and transmitting data.
There are trade-offs involved in choosing a compression technique for storing and transmitting data.
Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs? move(); putball(); move(); move(); move(); move(); move(); JavaScript Karel will end on Street 1, Avenue 2 Karel will end on Street 1, Avenue 7 This code won't run because of a syntax error Karel will crash into a wall
This code won't run because of a syntax error
What is top down design? Top down design is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve. Top down design is a way that you can create designs on a computer to put on a web page Top down design is a way of designing your programs starting with the individual commands first Top down design is a way to use loops and if statements to decompose the problem
Top down design is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.
A group of scientists has developed a simulation that simulates traffic in a city based on several factors. Which of the following statements is most likely something that can be learned from this simulation? Which roads are most likely to need maintenance in the near future Which areas of the city have the highest concentration of crime Precisely how many accidents will happen on any given day What the city's population will be in future years
Which roads are most likely to need maintenance in the near future
We want to simulate constantly flipping a coin until we get 3 heads in a row. What kind of loop should we use? For loop While loop Loop and a half Infinite loop
While Loop
What is an array (or list)? An unordered collection of unique items An ordered collection of items A collection of (key, value) pairs A collection of items stored at (row, column) locations
an ordered collection of items
A computer program uses 3 bits to represent integers. When the program adds the decimal (base 10) numbers 6 and 2, the result is 0. Which of the following is the best explanation for this result? An overflow error occurred. A round-off error occurred. An off-by-one error occurred. The result was affected by lossy data compression.
an overflow error occurred
How can we get the length of an array arr? arr.len arr.length length(arr) arr.length()
arr.length
Question: 3 What condition should be used in this while loop to get Karel to pick up all the tennis balls on the current location? while (________) { takeBall(); } JavaScript noBallsPresent() ballsPresent() frontIsClear() takeBall()
ballsPresent()
Which number system is used to store information digitally in a computer? Decimal (base 10) Binary (base 2) Octal (base 8) Hexadecimal (base 16)
binary(base 2)
Choose the best response: A function passed to an event handler that is called every time a certain event happens is called a parameterized function. return function. callback function. generator function.
callback function
Say you want to write a program to have Karel put down 300 tennis balls. Which control structure would you use? If statement While loop For loop Nested while loop
for loop
Which of the following is the correct way to create a function in JavaScript? function = myFunction() function:myFunction() function myFunction() myFunction()
function myFunction()
Which of the following type of variable is visible everywhere in your code? global local integer String
global
What method can we use to find the index of a particular element in an array? indexOf find findElement index
indexOf
Suppose we've written a function drawSquare that we want to call every time the mouse is clicked. How can we do this? mouseClickMethod(drawSquare); mouseClickMethod(drawSquare(e)); if(mouseClickMethod){ drawSquare(); } mouseClickMethod(drawSquare());
mouseClickMethod(drawSquare);
Which of the following lines of code would be considered the highest level of code? 10110011010011101010 move(); movl $1, %eax function move()
move();
How many times can a function be defined?
once
Which statement allows us to return values from functions? break return while function
return
Which of the following is not a valid condition to go in an if statement for Karel? ballsPresent() frontIsClear() leftIsBlocked() turnLeft()
turnLeft()
Which of the following choices is a properly formed JavaScript variable name, meaning it is both legal in the JavaScript language and considered good style? user_age UserAge userAge User age
userAge
The following program should draw a circle on the screen 1 function start(){ 2 var circle = new Circle(40); 3 circle.setPosition(getWidth() / 2, getHeight() / 2); 4 circle.setColor(Color.blue); 5 } JavaScript But when we run this code, we don't see the circle. What is missing from our start function?
we need to use the add function on the circle