Unit: Programming

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

The following numbers are displayed by a program: 2 4 6 8 The program code is shown below, but it is missing three values: <COUNTER>, <AMOUNT>, and <STEP>. i ← <COUNTER> REPEAT <AMOUNT> TIMES { DISPLAY(i * 2) i ← i + <STEP> } Given the displayed output, what must the missing values be? A. <COUNTER> = 1, <AMOUNT> = 2, <STEP> = 2 B. <COUNTER> = 2, <AMOUNT> = 4, <STEP> = 1 C. <COUNTER> = 1, <AMOUNT> = 4, <STEP> = 1 D. <COUNTER> = 2, <AMOUNT> = 4, <STEP> = 2 E. <COUNTER> = 2, <AMOUNT> = 2, <STEP> = 1

C. <COUNTER> = 1, <AMOUNT> = 4, <STEP> = 1

A toy for a baby indicates that it should only be used for babies that weigh less than 25 pounds and are less than 30 inches tall. The variable weight represents a baby's weight in pounds and the variable height represents a baby's height in inches. Which of the following expressions evaluates to true if a baby meets the criteria? A. NOT (weight ≥ 25) AND NOT (height ≥ 30) B. weight > 25 AND height < 30 C. NOT (weight ≥ 25) AND height > 30 D. weight ≤ 25 AND NOT (height < 30) E. weight < 25 OR height < 30

A. NOT (weight ≥ 25) AND NOT (height ≥ 30) Why? This expression is true when weight is not greater than or equal to 25 pounds (the same as being less than 24 pounds) and true when height is not greater than or equal to 30 inches (the same as being less than 30 inches).

Which of these is the best explanation of pseudocode? A. Pseudocode is a language that represents concepts across programming languages, but cannot actually be run by a computer. B. Pseudocode is a standard programming language that is understood by all computers. C. Pseudocode is the language that runs the fastest on computers. D. Pseudocode is a programming language that looks just like natural human language. E. Pseudocode is code that has too many mistakes in it to qualify as real code.

A. Pseudocode is a language that represents concepts across programming languages, but cannot actually be run by a computer.

Allyson is making an online store. Her code needs to calculate the final cost of a $32 item with a $5 coupon applied. The initial code looks like this: itemsCost ← 32 coupon amount ← 5 Which code successfully calculates and stores the final cost? A. finalCost ← itemCost MOD couponAmount B. finalCost ← itemCost / couponAmount C. finalCost ← itemCost + (-1 * couponAmount) D. finalCost ← (couponAmount - itemCost) E. finalCost ← (itemCost - couponAmount) F. finalCost ← itemCost - couponAmount

B. finalCost ← itemCost / couponAmount E. finalCost ← (itemCost - couponAmount) F. finalCost ← itemCost - couponAmount

Imagine our program starts with this line: var nickname = "SplashyPants"; Select the line of JavaScript code that successfully stores the greeting "Ahoy, SplashyPants!": A. var greeting = "Ahoy, " nickname "!"; B. var greeting = "Ahoy, " + nickname + "!"; C. var greeting = "Ahoy," nickname "!"; D. var greeting = "Ahoy," + nickname + "!"; E. var greeting = "Ahoy, " + nickname "!";

B. var greeting = "Ahoy, " + nickname + "!"; Why? This line correctly uses the JavaScript concatenation operator, the plus sign, between the string literals and the variable.

Ada notices that her classmate's program is very long and none of the code is grouped into procedures. How can Ada persuade her classmate to start organizing their code into procedures? A. She can find the most slow-running parts of her classmate's program and suggest putting that code into a procedure to make it run faster. B. She can find buggy parts of her classmate's code and suggest they move those parts into procedures to fix the code. C. She can find places where her classmate's program has repeated code, and suggest using a procedure to wrap up that code. D. She can find the most unique part of her classmate's code and suggest they use procedures to hide that functionality from other classmates.

C. She can find places where her classmate's program has repeated code, and suggest using a procedure to wrap up that code.

Oakley is making a program to display events for the next few days. Here's a snippet of the code: today ← 11 tomorrow ← 12 DISPLAY (tomorrow) DISPLAY (today) After running that code, what will be displayed? A. 11 11 B. 12 12 C. 11 12 D. 12 11

D. 12 11

Casper is programming a game called GhostHunter Extreme, where players must capture as many ghosts as possible in 5 minutes. Which variable would he most likely use a string data type for? A. soundLevel: The volume of the sound effects ("Boo!") B. timeLeft: The seconds remaining C. score: The number of ghosts captured D. playerName: The player's name

D. playerName: The player's name

This program uses a nested conditional to assign the variable mystery to a value: IF (x > y) { mystery ← x - y } ELSE { IF (x < y) { mystery ← y / x } ELSE { mystery ← x + y } } If we set x to 32 and y to 8, what value will the mystery variable store after running this code? A. 4 B. -24 C. 40 D. 32 E. 8 F. 24

F. 24

The code below processes two numerical values with a conditional statement. numA ← INPUT() numB ← INPUT() IF (numA < numB) { DISPLAY(numA) } ELSE { DISPLAY(numB) } The code relies on a built-in procedure, INPUT(), which prompts the user for a value and returns it. Which of the following best describes the result of running this code? A. The code either displays whichever number is greater (numA or numB) or displays numA if they are equal. B. The code displays whichever number is greater (numA or numB) or displays numB if they are equal. C. The code either displays whichever number is smaller (numA or numB) or displays numA if they are equal. D. The code displays whichever number is smaller (numA or numB) or displays numB if they are equal.

D. The code displays whichever number is smaller (numA or numB) or displays numB if they are equal.


Kaugnay na mga set ng pag-aaral

Funeral Service Management 165 Chapter 4

View Set

Fundamentals of Sectional anatomy LAZO chapter 2

View Set