AP Computer Science

Ace your homework & exams now with Quizwiz!

What will the following program display in the console? for(var i =0; i <4; i++) console.log(i); }

0 1 2 3

Computer systems use binary numbers to represent data that it processes. If it has a number in memory represented by the binary number 0010 1001, and it is processing an instruction to add the decimal number 21 to it, what is the resulting number in binary format?

0011 1110

You have imported a library with the birthYear() function. Based on the API, how many strings are inputed to calculate the birth month? // calculate birth month year based on the day of the month, day of the week, and the birth year // dayMonth {number} - a day of a month from 1 to 31 // dayWeek {string} - the name of the day of the week // year {number} - the birth year // return {string} - the month you were born BirthdayLibrary.birthMonth(dayMonth, dayWeek, year);

1

A sorted list of numbers contains 500 elements. Which of the following is closest to the maximum number of list elements that will be examined when performing a binary search for a value in the list?

10

What will the following program display in the console? var sum = 0; for(var i = 0; i < 5; i++){ sum = sum + i; } console.log(sum);

10

Each student that enrolls at a school is assigned a unique ID number, which is stored as a binary number. The ID numbers increase sequentially by 1 with each newly enrolled student. If the ID number assigned to the last student who enrolled was the binary number 1001 0011, what binary number will be assigned to the next student who enrolls?

1001 0100

Binary number sequences can be used to represent multiple types of data, including images, data, numbers, text, and sound. The computer determines what type of data a number sequence represents by the context in which it is used. Which of the following could NOT be represented by the sequence 0100 0001?

1011 1110

The measurement of the length of an object needs to be stored digitally. What are the minimum number of bits necessary to represent both the length (an integer number from 0-20 with no decimal places) and its unit of measure (represented by two ASCII characters such as "FT" or "IN")? Note that 8-bit ASCII encoding is being used in this case.

21

Computers keep a track of time by counting the number of seconds that have passed since January 1st, 1970, at 12:00:00. We store these numbers in 32-bits. However, on January 19th, 2038, we will run out of bits to express time. Since this would result in negative numbers and cause software to crash and computers to stop running, we need to change computers to a 64-bit system. Which of the following BEST describes the number of values we can express using a 64-bit system instead of a 32-bit system?

2^32 times as many values can be represented.

What is printed to the console? console.log(15 % 4);

3

What will be displayed in the console when this program runs? var numList = [10,20,30]; console.log(numList[numlist.length-1]);

30

A programmer developed a mathematical engine that could perform basic mathematical calculations. The engine required that it be given exactly three consecutive bytes of information. The first byte would signify an integer. The second byte would indicate the mathematical operation, and the third byte would be another integer. For example, to divide 12 by 3, the first byte would represent the number 12, the second byte would signify division, and the third byte would represent the number 3. The engine would return the result in decimal format. The second byte could have the following values: 0000 0000 = addition 0000 0001 = subtraction 0000 0010 = multiplication 0000 0011 = division What would this mathematical engine return if it were given the following stream of bits? 0001 0000 0000 0010 0000 0011

48

Doris needs to represent 26 different letters using binary. What is the minimum number of binary digits she will need to represent this many letters?

5

What will be displayed when this program finishes running? var numbersList = [20, 10, 5] appendItem(numbersList, 50) appendItem(numbersList,100) removeItem(numbersList,1) insertItem(numbersList, 0, 30) console.log(numbersList.length)

5

A certain computer has two identical processors that are able to run in parallel. Each processor can run only one process at a time, and each process must be executed on a single processor. The following table indicates the amount of time it takes to execute each of three processes on a single processor. Assume that none of the processes are dependent on any of the other processes. Process Execution Time on Either Processor X 60 seconds Y 30 seconds Z 50 seconds Which of the following best approximates the minimum possible time to execute all three processes when the two processors are run in parallel?

80 seconds

Data compression is the process of transforming a file so that it uses less bits than the original file, thereby reducing its file size. Which of the following is NOT true concerning data compression?

A compressed file cannot be restored to its original format unless the person trying to restore the file has decryption rights.

A chain of retail stores uses software to manage telephone calls from customers. The system was recently upgraded. Customers interacted with the original system using their phone keypad. Customers interact with the upgraded system using their voice. The upgraded system (but not the original system) stores all information from the calling session in a database for future reference. This includes the customer's telephone number and any information provided by the customer (name, address, order number, credit card number, etc.). The original system and the upgraded system are described in the following flowcharts. Each flowchart uses the following blocks. The upgraded system uses a directory containing additional information not supplied by the customer. The directory is used to help direct calls effectively. Which of the following is LEAST likely to be included in the directory?

A list of computers the company owns and the computers' corresponding IP addresses

Samantha cannot figure out why her program isn't working. She emails the file to her friend Ben and asks him if he can find what's wrong. Which of the following would be most helpful for Ben as he tries to debug Samantha's code?

A list of example inputs along with the desired outputs.

Which of the following school policies is most likely to have a positive impact on the digital divide?

A school provides a laptop or tablet computer to all students enrolled at the school.

Collaborative spreadsheets are now common tools for people to use and share information in real time. An example of collaborative spreadsheet software is Google Sheets. Of the following situations, which are most conducive for using collaborative spreadsheet software instead of using standalone spreadsheet software? Select TWO answers.

A team of engineers records their individual test results, which are monitored by a supervisor every hour. -------------------- Each day, students in an AP Computer Science Principles class record how many hours of sleep they received the previous night, and the average is reported to the class.

Three students (Alex, Bryan, and Carmen) are working on creating an app for a computer science project. They completed an initial version of the app and now just finishing conducting two different focus groups-one for parents and one for young kids. The students decide to discuss their notes and observations from the focus groups the next day at school. The next day comes but Bryan doesn't show up to school because he's sick. All of the following are ways that the three students can still collaborate EXCEPT

Alex and Carmen have a discussion on their own assuming that Bryan's observations are similar to theirs.

Eric is going to write a program for the math teachers at his school that will help them keep track of book numbers across the department. Before he can begin planning this program, what vital information will he need? Select TWO answers.

Any concerns that the teachers have about how the program will work. -------------------- A description of what the user interface should look like and how the teachers will interact with the program.

Which of the following can be represented by a single binary digit? Select TWO answers.

Any integer modulus 2 -------------------- If a grade is passing or failing

In computer science, experience has demonstrated that there are numerous benefits that come out of collaboration. Some benefits come from the communication that is an intrinsic part of collaboration, whether the collaboration is between individuals inside an organization or between different organizations. Which of the following is NOT a benefit that comes from communicating in collaboration?

Bias increases.

Collaboration is an important way of working in the modern world. Of the following statements, which more accurately describe advantages of teams working together collaboratively? Select TWO answers.

Brainstorming among team members encourages creativity. -------------------- Work being shared among team members helps get the job done faster.

Which of the following can be represented by exactly two binary digits? Select TWO answers.

Compass directions (North, South, East, and West). -------------------- Classifying a student by whether or not they are passing and whether or not they have perfect attendance.

A television show features contestants with a variety of different talents. After the contestants highlight their talents, each of the three judges gives either a "thumbs up" or a "thumbs down". The live audience also votes and if a majority votes as "thumbs up", then the overall audience vote is a "thumbs up". Else, the overall audience vote is a "thumbs down". Online voting works in the same fashion. The final results are indicated in a sequence of 5 bits, with the rightmost 3 bits representing the votes of the three judges, the leftmost bit representing the online vote, and the bit second from the left representing the overall live audience vote. A bit value of 1 signifies a "thumbs up" vote and a bit value of 0 represents a "thumbs down" vote. The three judge's votes are weighted twice as high as the online or live audience votes, which are weighted equally. The weighted votes are simply added together and the contestant with the greatest value of weighted votes wins the talent show. The following are the final voting results for the four contestants. Contestant A: 11001 Contestant B: 10110 Contestant C: 01101 Contestant D: 00111 Which contestant won the competition?

Contestant D

Amal has written the largest part of her program and is now thinking of test cases to make sure the program works the way it should. When she finds errors, she fixes them. What is this process called?

Debugging

A digital photo file contains data representing the level of red, green, and blue for each pixel in the photo. The file also contains metadata that describe the date and geographic location where the photo was taken. For which of the following goals would analyzing the metadata be more appropriate than analyzing the data?

Determining the likelihood that the photo was taken at a particular public event

A student notices that students and teachers at her school are throwing recyclable items into trash cans instead of the blue recycling containers. She decides to create a mobile application to help her school determine whether or not an item is recyclable. The app would allow a user to photograph an item, and it would then indicate whether or not the item is recyclable, based upon an algorithm developed with the help of her community's local recycling center. Her school environmental club advisor thinks it would be great to offer the app to other schools if the app works as intended. As she creates her program, she finds that recycling programs might have different procedures in different communities. In addition, she sees patterns in images that help her determine if the item can be recycled. What is the BEST possible explanation for what the student has learned?

Developing a new algorithm to solve a problem can yield insight into the problem.

Which of the following best explains how data is typically assembled in packets for transmission over the Internet?

Each packet contains data to be transmitted, along with metadata containing information used for routing the data

Which of the following practices will make collaborating with another programmer more effective? Select TWO answers.

Each programmer should use the same documentation guidelines as they write code. -------------------- The programmers could use online tools like Google Docs to share files and work together.

Akram started writing a program that is supposed to generate a random menu for a week; the user enters recipes and can then generate menus for a given number of days. In the beginning stages of implementing the code, he realized that the program could be even better if the user could input what ingredients they have on hand. Then the program could suggest menu items that the user can make without buying more food. Which of the following steps should Akram consider taking next? Select TWO answers.

Finish his original program, then add the new elements once the original program works. -------------------- Stop programming, rework the original plan, then start programming again.

It is becoming more popular for businesses to allow workers to telecommute to work by accessing their information remotely through a computer and working from home instead of coming into the office. Which of the following would be a disadvantage of working in this manner?

Harder for cross discipline collaboration.

Computer scientists are great at reading data and crunching numbers to draw conclusions. We live in a data-rich world that offers more information than has ever been present before. Companies often do not hire computer scientists on their own and will often group the computer science folks with team members from other fields. Which of the following is the BEST reason for a computer scientist to work with some one outside their field?Computer scientists are great at reading data and crunching numbers to draw conclusions. We live in a data-rich world that offers more information than has ever been present before. Companies often do not hire computer scientists on their own and will often group the computer science folks with team members from other fields. Which of the following is the BEST reason for a computer scientist to work with some one outside their field?

Help draft goal of what to look for.

Three students (Alex, Bryan, and Carmen) are working on creating an app for a computer science project. They have completed an initial, working version of the app and they would like to hold a focus group to receive feedback on how to make their app appealing to young kids. They decide to conduct two different focus groups-one for parents and one for young kids. Which of the following options best explains whether holding the focus groups is a form of collaboration?

Holding the focus groups is a form of collaboration because the students are gaining insight from parents and young kids.

While working on a presentation for work, a person recorded a video of the speech on a webcam and then sent it to a coworker for some peer feedback. The colleague opened their email to load the video, but found that video was very grainy. Which of the following might contribute to this? I. Lost bits in compression need to be guessed by video viewer. II. Weak internet connection cause poor streaming. III. Stronger compression algorithm to make file small enough to email.

I and III only

Sue and Tom have worked together to design a card game. They decided that each of them would program separate features of the game and put them together for a finished product.. Early in the development process, they decided to meet and go through a program walkthrough of each other's code. This involves the reviewer taking time to examine the code to determine if it works correctly, it is optimized, and it is documented sufficiently. The reviewer then communicates their opinions to the code author at a face-to-face meeting, and they decide what changes (if any) should be made. Of the following, which are benefits of performing a program walkthrough? I. Program walkthroughs could highlight tricks and tips that either the reviewer or code author were not familiar with. II. Program walkthroughs are effective at determining which programmer, either the reviewer or the code author, is the most proficient programmer. III. Program walkthroughs are an effective way of finding bugs and optimizing code before it is implemented in a live environment.

I and III only.

In a certain country, a person must be at least 16 years old to drive a car and must be at least 18 years old to vote. The variable age represents the age of a person as an integer. Which of the following expressions evaluates to true if the person is old enough to drive but not old enough to vote, and evaluates to false otherwise? I. (age ≥ 16) AND (age ≤ 18) II. (age ≥ 16) AND (NOT(age ≥ 18)) III. (age < 18) AND (NOT(age < 16))

II and III only

Bridget was a programmer for many years at a company, but then she moved on to a bigger and better job at another corporation. Sally was promoted into Bridget's old position and is now responsible for maintaining the programs that Bridget originally developed. Sally has been asked to debug the following code but is having a hard time understanding its functionality. PROCEDURE a (b, c) { REPEAT UNTIL (b > c) { IF (b MOD 10 = 0) { c <-- c + 2 } ELSE { DISPLAY (b) } b <-- b + 1 } } Of the following modifications that Bridget could have made to this code before she left the company, which would have been the most useful for helping Sally better understand the code? Select TWO answers.

Include documentation that explains the purpose of procedure a and its two parameters b and c. -------------------- Replace the name of the procedure and the variables names with longer and more meaningful names.

Molly asks Sean to help her debug her code. She tells him that the code is supposed to take a list of names and return the alphabetically sorted list with any duplicate names in bold. Why will this information help Sean debug Molly's code?

Knowing what the program is supposed to do will help Sean determine what is wrong with the code.

A metal fabricating company owns a variety of machines that are used to cut and shape metal products. The company stores the status of each of its eight machines as a sequence of bits. A bit value of 1 means that the machine is in service and a bit value of 0 means that the machine is out of service. Each machine is given a number from 0-7 (machine 0, machine 1, ..., machine 7). The status of machine 0 is represented by the rightmost bit, machine 1's status is represented by the bit left of the rightmost bit, and machine 7's status is represented by the leftmost bit, etc. The company communicates the status of its machines to its supervisors by using the decimal equivalent of these series of bits. If the company communicates its machine statuses as the decimal number 52, which machines are currently in service?

Machine 2, Machine 4, and Machine 5

The following procedure is intended to return the number of times the value val appears in the list myList. The procedure does not work as intended. Line 1: PROCEDURE countNumOccurences(myList, val) Line 2: { Line 3: FOR EACH item IN myList Line 4: { Line 5: count 0 Line 6: IF(item = val) Line 7: { Line 8: count count + 1 Line 9: } Line 10: } Line 11: RETURN(count) Line 12:} Which of the following changes can be made so that the procedure will work as intended?

Moving the statement in line 5 so that it appears between lines 2 and 3

This function checks if a character is a vowel. If it is, it returns true. Otherwise, it returns false. Where should return false; be written in the code? function checkVowel(character){ var vowels = ["a", "e", "i", "o", "u"]; for(var i=0; i<vowels.length; i++){ if(vowels[i] == character){ return true; OPTION A } OPTION B } OPTION C } OPTION D

OPTION C

Three students (Alex, Bryan, and Carmen) are working on creating an app for a computer science project. They have completed an initial, working version of the app and they would like to hold a focus group to receive feedback on how to make their app appealing to young kids. Which of the following would be the best means of enlisting participants for the focus group?

Passing out flyers to parents at an elementary school.

Pair programming is a programming style that has proved to be effective in certain situations. Of the following, which is NOT a collaborative characteristic of pair programming?

Program design and program development are split between the pair of people.

The following question uses a robot in a grid of squares. The robot is represented by a triangle, which is initially facing up. Which of the following programs will move the robot to the gray square following the path shown on the grid?

REPEAT 2 TIMES REPEAT 3 TIMES MOVE_FORWARD TURN LEFT

Rachel is planning on writing code that will have to do computations with very large numbers. Which of the following is the most important issue she should check before writing her code?

Rachel should look up how many bits are used to store integers and floating point numbers in the programming language she is using.

You are given the following procedure which determines the lowest passing test grade that one of your students made on an important test. The test grades are stored in list testGrades. There will be at least one test grade in the list and all test grades are between 0-100. The parameter maxFailingGrade is the highest score a student can make and still fail the test. For example, if testGrades contains [64, 85, 63, 99, 75, 55, 93] and the maximum failing test grade is 59, then this procedure should return 63. Note: This procedure should return 999 if all test grades are failing test grades. However, after testing this procedure, the programmer discovered that it contained some bugs. Which of the following two can be combined to correct this procedure? Select TWO answers.

Replace line 3 with the following: lowGrade <-- testGrade[1] -------------------- Replace line 6 with the following: IF {{grade < lowGrade) AND (grade > maxFailingGrade))

Which of the following is NOT an example of collaboration?

Seth and Alex each decide they want to create a piece a music using a coding software. Seth and Alex discuss what genre of music they want to make, but they cannot agree. They each decide to create their own music.

A list of numbers has n elements, indexed from 1 to n. The following algorithm is intended to display the number of elements in the list that have a value greater than 100. The algorithm uses the variables count and position. Steps 3 and 4 are missing. Step 1: Set count to 0 and position to 1. Step 2: If the value of the element at index position is greater than 100, increase the value of count by 1. Step 3: (missing step) Step 4: (missing step) Step 5: Display the value of count. Which of the following could be used to replace steps 3 and 4 so that the algorithm works as intended?

Step 3: Increase the value of position by 1. Step 4: Repeat steps 2 and 3 until the value of position is greater than n.

A process named "Stepwise Refinement" is useful when programming. What is Stepwise Refinement?

Stepwise Refinement is a top-down design process in which the programmer starts with the overall goal of the program and continually breaks down the design into sub-functions.

There is growing preference in today's age for streaming music over purchasing music. For what reasons might people prefer streaming over purchasing music? Select TWO answers.

Streaming music is cheaper as most streaming services are free or charge low subscription fees. -------------------- Purchasing and downloading music takes up storage space on the device.

A chain of retail stores uses software to manage telephone calls from customers. The system was recently upgraded. Customers interacted with the original system using their phone keypad. Customers interact with the upgraded system using their voice. The upgraded system (but not the original system) stores all information from the calling session in a database for future reference. This includes the customer's telephone number and any information provided by the customer (name, address, order number, credit card number, etc.). The original system and the upgraded system are described in the following flowcharts. Each flowchart uses the following blocks. Of the following potential benefits, which is LEAST likely to be provided by the upgraded system?

The company will be able to provide a human representative for any incoming call.

A job placement agency helps match job seekers with potential employers. The agency would like to design a simulation in order to help predict the likely job placement outcomes for job seekers based on historical trends and patterns. Which of the following is least likely to be a benefit of the simulation?

The computer simulation could be used to test hypotheses about patterns in the job placement process that are costly or time consuming to observe in reality.

A photograph was loaded into Photoshop and stored as a Vector SVG file. Which of the following is a true statement?

The image could be enlarged without impacting quality.

Vang is programming some software for a client. Which of the following will best help Vang understand what the software is supposed to do?

The intended outcome of several specific inputs.

Binary representation can be used to denote different types of information. Given that you only have 3 bits to store some data, which of the following can be best represented in these three bits?

The number of dots shown on the top face of a standard die after rolling it in a board game.

In the creation of programs, what you choose to name the variables is very important. What are the benefits of well-named variables in a program? Select TWO answers.

The program allows others to read it more easily. -------------------- The program will be easier to edit and debug.

Which of the following would be the best explanation of the functionality of a program?

The program asks the user for a word, then translates the word into pig latin. The program does this using the substring procedure and concatenation.

A school is developing a program to keep track of information about students and their class schedules. In which of the following instances would a data abstraction be most helpful?

The program includes individual variables to store the names of each student rather than a single list of students.

please note that != means not equal What will be displayed in the console when the following program runs? var count = 0 while (count != 5){ console.log(count); count = count + 2; }

The program will result in an infinite loop

Which of the following statements about programming are TRUE? Select TWO answers.

The purpose of a program will determine what kinds of algorithms, helper methods, and strategies the programmer will need to use. -------------------- A program created for a small group of people might be useful for a different purpose for large groups of people.

Three friends are collaborating on a big AP® Statistics project. They met once and decided to gather data about the "effect of extracurricular activities on class rank." Separately, they generated their own questions and collected data from various classmates. Each student cleaned their individual dataset, and then they combined the three datasets into one dataset. The end product was a scatterplot that analyzed their results. However, the teacher was not impressed with their work. Which of the following are the most appropriate changes the students should make to their collaborative process to make it more effective? Select TWO answers

The students should develop the survey questions together and each should ask the same questions to their classmates. -------------------- The data should be combined before it is cleaned, so that it is cleaned in a consistent manner.

A user purchased a new smart home device with embedded software and connected the device to a home network. The user then registered the device with the manufacturer, setting up an account using a personal e-mail and password. Which of the following explains how a phishing attack could occur against the user of the smart home device?

The user is sent an e-mail appearing to be from the manufacturer, asking the user to confirm the account password by clicking on a link in the e-mail and entering the password on the resulting page.

Jerry and Ron are each working on programs with different purposes and implementations. They each use the following binary sequence in their programs: 0110 1100 0100 0111 Which of the following statements is true?

This binary sequence MIGHT represent the same type of data.

A home security company develops software that takes a human voice as input, searches for the voice in a voice recognition database, and determines the identity of the person based on the voice. It is sophisticated enough to be able to distinguish a live voice from a recorded voice. The main purpose of this software is to activate and deactivate the security system at a person's home residence. Of the following, which would be the MOST logical extension of this software for another purpose?

To allow an officer's entry into a military facility.

There is no result for the second call because the program is only being called once.

To clarify well-named variables in the code so that you know what the variables represent. For example: currentScore = 0 // represents the current score in the current score in the game

Sometimes a programmer is not given much information about the code they are about to maintain. One way to determine what the code is doing is to examine the inputs and expected outputs. Many times, it becomes much easier to determine its functionality when you have this information. A procedure named processNumbers has one parameter named inputNum and it returns a list named outputNums. All input and output numbers are positive integers greater than zero. Here are various test cases and their intended outputs. inputNum outputNum 3 [1, 3] 6 [1, 2, 3, 6] 8 [1, 2, 4, 8] 12 [1, 2, 3, 4, 6, 12] 28 [1, 2, 4, 7, 14, 28] Given only the test cases and their intended outputs above, what is the most likely purpose of the procedure processNumbers?

To determine all of the factors of inputNum.

A website tracking data on high schools around the country maintains a school profile on each school affiliated with it to be able to share with colleges. These files contain quantitative information about the school and help to paint a picture of what the schools value. The website requires that the size of the file shared by the high schools must be below a certain threshold of size. Why might the website restrict this?

To minimize storage on their webserver.

A constant is a special type of variable sometimes used to represent a piece of information in a computer program. Which of the following choices is the best situation for using a constant in a program?

To represent the maximum number of lives a player can have in a game.

Alvin is working on creating a fairly large program. Which of the following strategies will make his code easier to maintain once the program is finished? Select TWO answers.

Using procedures for repeated code. -------------------- Writing documentation for all procedures and variables in the program.

One way of communicating hexadecimal color codes is in the following way: #RRGGBB. The first pair of numbers represents the red color value (R), the second pair represents the green color value (G), and the third pair represents the blue color value (B). Sometime a simplified color code scheme is used that follows this format: #RGB. In this format, only the first digits of each color component from the original format are used (#RRGGBB). Which of the following is true about using the simplified color scheme?

Using the simplified color code represents lossy compression because it only approximates the original color.

Which of the following might help a programmer with debugging? Select TWO answers.

Well named variables and procedures. -------------------- Inserting statements like "loop completed" or "if statement starts here" that display as the code is running.

A Web site uses several strategies to prevent unauthorized individuals from accessing user accounts. Which of the following is NOT an example of multifactor authentication?

When a user enters an incorrect password more than two times in a row, the user is locked out of the account for 24 hours.

Why is it important for programmers to debug their code in small parts as they go?

Whether or not the entire program works depends on whether or not each small part works.

Which of the following strategies help programmers develop a correct program to solve problems? Select TWO answers.

Writing part of the code and testing it before writing the next part. -------------------- Splitting the code into components, writing and testing them separately, then combining the components.

What will be printed to the console after this program runs? var numbers = [2, 5, 3, 1, 6] function changeNums(numList, addNum, subtractNum){ for(var i=0; i<numList.length; i++){ if(numList[i] % 3 == 0){ numList[i] numList[i] + addNum; } else { numList[i] = numList[i] - subtractNum; } } } changeNums(numbers, 3, 2); console.log(numbers);

[0, 3, 6, -1, 9]

var words = ["apple", "bug", "car", "dream", "ear", var filteredWords = []; for(var i = 0; i < words.length; i++){ var words = words[i]; if (word.length < 4){ appendItem(filteredWords, word) } } console.log(filteredWords); If the program above is run, what will be displayed in the console?

[bug, car, ear]

Sally had been working on a combat simulation game. Jason had been working on a maze navigation game. They discussed their programs over lunch, and decided to work together on a joint program, combining their work to make a more complete game. They worked together both in the classroom and via on-line chat from home to complete their project.. This is best described as

collaboration

Which function calls would provide the most helpful test of this function? function findMin(num1, num2){ if(num1 < num2){ return num1; } else { return num2; } }

findMin(-1, 1) findMin(1, -1) findMin(1, 1)

ageList and gradeList contain information about students in a classroom. A programmer has already written the following code with that information. var ages = [16,17,18, 17] var names = ["Beni", "Analise", "Ricardo", "Tanya"] var filteredNames = []; Which of the following programs will result in filteredNames only containing the names of students who are 17 or older?

for(var i = 0; i < ages.length; i++) { age = ages[i]; if(age >= 17){ appendItem(filteredNames, names[i]) } }

listAverage() returns the average number in a list. Which of these functions does this correctly?

function listAverage(list) { var sum = 0; for (var i = 0; i < list.length; i++) { sum = sum + list[i]; } return (sum / list.length); }

Here is the API for a robot library. // moves the robot forward function moveForward(); // turns the robot to the left function rotateLeft(); // turns the robot to the right function rotateRight(); // checks if a robot can move in any direction // direction {string} - the direction to be checked // return {Boolean} - true if the robot can move in that direction, otherwise returns false function canMove(direction); Which code segment will guarantee that the robot makes it to the grey square without hitting a wall or a barrier (black square)?

function solveMaze( ){ moveForward( ); moveForward( ); rotateRight( ); while(canMove( "forward")){ moveForwad( ); } rotateLeft( ); moveForward( ); }

list = [10, 5, 15]; for(var i = 0; <INSERT CODE>; i++){ console.log(list[i]); } Which of the following will NOT result in an error if placed where the program reads <INSERT CODE> and the program is run?

i < list.length

This function finds the minimum number in a list. What should <MISSING CODE SEGMENT> be replaced with in order for this function to operate as expected? function min(numList){ var min = numList[0]; for(var i=0; i<numList.length; i++){ if(numList[i] < min){ <MISSING CODE SEGMENT> } } return min; }

min = numList[i];

Dividing a program into separate subprograms (such as libraries) is known as:

modularity

Which call of the function correctly follows the instructions laid out in the API? //moves a given element on the screen //id {string} - the element ID for the item to be moved //direction {string} - the direction the element should be moved //amount {number} - the amount of pixels the element should be moved function moveElement(id, direction, amount) { var xPosition = getXPosition("id"); var yPosition = getYPosition("id"); if (direction == "left") { setProperty("id", "x", xPosition - amount); } else if ((direction == "right")) { setProperty("id", "x", xPosition + amount); } else if ((direction == "up")) { setProperty("id", "y", yPosition - amount); } else { setProperty("id", "y", yPosition + amount); } }

moveElement("button1", "down", 25);

The following grid contains a robot represented as a triangle. The robot is initially facing right. Which of the following code segments can be used to move the robot to the gray square along the path indicated by the arrows?

n = 1 REPEAT 3 TIMES REPEAT n TIMES MOVE_FORWARD ROTATE_LEFT REPEAT n TIMES MOVE_FORWARD ROTATE_RIGHT n = n + 1

Which code segment results in "true" being returned if a number is even? Replace "MISSING CONDITION" with the correct code segment. function isEven(num){ if(MISSING CONDITION){ return true; } else { return false; } }

num % 2 == 0;

A program is designed to determine the minimum value in a list of positive numbers called numList. The following program was written var minimum = <MISSING CODE> for(var i = 0; i < numList.length; i++){ if (numList[i] < minimum){ minimum = numList[i]; } } console.log("The minimum is" + minimum); Which of the following can be used to replace <MISSING CODE> so that the program works as intended for every possible list of positive numbers?

numList[0]

Which term refers to a solution to a large problem that is based on the solutions of smaller subproblems.

procedural abstraction

A restaurant knows from historical data that 60 out of 100 of its customers purchase a full meal while 40 out of 100 only order a side dish. The program below is intended to simulate the orders of 1000 customers. fullMeal 0 sideDish 0 REPEAT 1000 TIMES { IF (<MISSING CODE>) { fullMeal fullMeal + 1 } ELSE { sideDish sideDish + 1 } } Which of the following can be used to replace <MISSING CODE> so that the simulation works as intended?

random(1,100) <= 60

Using existing algorithms as building blocks for new algorithms has all the following benefits EXCEPT:

removes procedural abstraction

Algorithms can be created in all the following ways EXCEPT:

removing sequencing, selection, and iteration from an algorithm

What is one of the benefits of using a library in a program?

simplifies creating a complex program

Consider the following: 0110 1011 0010 1011 This sequence represents

something that depends on the context in which it is used.

A 2-sided coin has an equal likelihood of landing on each side. One side is called "heads" and the other is called "tails". The program below simulates randomly flipping that coin many times. var heads = 0; va tails = 0; va rolls = 100; for(var i = 0; i < rolls; i++){ if(randomNumber(0,1) == 0){ heads++ } else { tails++ } Which of the following is NOT a possible combination of values of the variables in this program when it finishes running?

tails has a value of 20 and heads has a value of 20

wordList is a list of words that currently contains the values ["tree", "rock", "air"] Which of the following lines will result in the list containing the values ["air", "rock", "air"]

wordList[0] = wordList[2]

The following code segment is intended to set max equal to the maximum value among the integer variables x, y, and z. The code segment does not work as intended in all cases. IF x > y AND x > z max = x IF y > x AND y > z max = y ELSE max = z Which of the following initial values for x, y, and z can be used to show that the code segment does not work as intended?

x = 3, y = 2, z = 1


Related study sets

20th Century Dance History Study Guide

View Set

World Geography : Chapter 27 : Bhutan, Nepal, Maldives and Sri Lanka

View Set

Intramembranous Ossification Tracing

View Set

Ch. 46 Antitrust Law and Unfair trade practices

View Set

Project Management (MGT 450) Chapter 3

View Set

Chapter 22: Complications Occurring During Labor and Delivery

View Set