comp sci principles mid term

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

consider the following code segment if x>y DISPLAY (x + y) else DISPLAY (x - y) a. -2 b. 2 c. 8 d. nothing will be displayed

a. -2

which of the following integers display all integers begween 1 and 20 inclusive that arent divisible by 3 (two correct answers) a. step 1: set x to 0 step 2: increment x by 1 step 3: if x is not divisible by 3 then display x step 4: repeat steps 2 and 3 until x is 20 b. step 1: set x to 0 step 2: if x is divisible by 3, then display x step 3: increment x by 1 step 4: repeat steps 2 and 3 until c. step 1: set x to 1 step 2: if x is divisible by 3, then do nothing, otherwise display x step 3: increment x by 1 step 4: Repeat steps 2 and 3 until x is 20. d. step 1: set x to 1 step 2: x is divisible by 3, then do nothing; otherwise display x. step 3: increment x by 1 step 4: Repeat steps 2 and 3 until x is greater than 20.

a. step 1: set x to 0 step 2: increment x by 1 step 3: if x is not divisible by 3 then display x step 4: repeat steps 2 and 3 until x is 20 and d. step 1: set x to 1 step 2: x is divisible by 3, then do nothing; otherwise display x. step 3: increment x by 1 step 4: Repeat steps 2 and 3 until x is greater than 20.

in the following procedure, the parameter str is a string and the parameter num is a number procedure printArgs (str, num){ DISPLAY (num) DISPLAY(str) DISPLAY(num) } consider the following code segment printArgs("**", 1) printArgs("*:, 2) what is displayed as a result: a. 1 * 2 2 ** 2 b. 1 ** 1 2 * 2 c. * 1 * ** 2 ** d. ** 1 ** * 2 *

b. 1 ** 1 2 * 2

p <-- 10 q <-- 20 r <-- 30 s <-- 40 p <-- q q <-- r s <-- q r <-- p what is the value of r as a result of executing the code a. 10 b. 20 c. 30 d. 40

b. 20

in the program below y is a positive integer result <-- 0 repeat 3 times{ repeat y times{ result <-- result + 1 } } a. y + 3 b. 3y c. y^3 d. 3^y

b. 3y

a certain game keeps track of the maximum and minimum scores obtained so far. if num represents the most recent score obtained, which of the following algorithms correctly updates the values of the max and min. a. if num is greater than the min, set min equal to num. otherwise, if num is greater than the max, set max equal to num. b. if num is less than the min, set min equal to num. otherwise if num is greater than the max, set the max equal to num. c. if num is less than the min, set min equal to num. otherwise if num is less than the max, set max, equal to num. d. if num is greater than the min, set min equal to num. otherwise, if num is less than the max, set max equal to num.

b. if num is less than the min, set min equal to num. otherwise if num is greater than the max, set the max equal to num.

the variable age is to used to represent a person's age in years. which of the following is the most appropriate data type for age a. Boolean b. number c. string d. list

b. number

in the following procedure, the parameter max is a positive integer procedure printNums (max){ count<-- repeat until (count>max){ DISPLAY(count) count <-- count + 2 } } which of the following is the most appropriate documentation to appear with the printNums procedure a. print all positive integers that are less than or equal to max b. prints all positive odd integers that are less than or equal to max c. prints all positive even integers that are greater than max d. prints all positive odd integers that are greater than max

b. prints all positive odd integers that are less than or equal to max

which of the following are benefits of using well named variables in a computer program? (two answers) a. the program will run faster b. the program will be easier for people to read c. the program will have a greater data storage capacity d. the program will be easier to modify in the future

b. the program will be easier for people to read d. the program will be easier to modify in the future

consider the following code segment num1 <-- 6 num2 <-- 4 num3 <-- 10 if (num1 < num2) num1 <-- num2 else num3 <-- num2 if (num2 >= num3) num1 <-- num2 + num3 sum <-- num1 + num2 + num3 a. 12 b. 14 c. 16 d. 18

c. 18

consider the following code segment, which uses the variables r, s, and t r <-- 1 s <-- 2 t <-- 3 r <-- s s <-- t DISPLAY (r) DISPLAY (s) what is displayed as a result of running the code segment a. 11 b. 12 c. 23 d. 32

c. 23

in the program below, the initial value of x is 5 and the initial value of y is 10 if (x<0){ DISPLAY ("Foxtrot") }else if (x>y){ DISPLAY ("Hotel") }else if (y>0){ DISPLAY ("November") }else{ DISPLAY ("Yankee") } what is displayed as a result a. Foxtrot b. Hotel c. November d. Yankee

c. November

consider the following code segment with integer variables x and y if (x>10) if(y<10) DISPLAY ("ONE") else DISPLAY ("TWO") else if(y>3) DISPLAY ("THREE") else DISPLAY ("FOUR") if x has a value of 7 and y has a value of 20, what is displayed as a result of executing the code segment a. ONE b. TWO c. THREE d. FOUR

c. THREE

consider the following code segment i <-- 1 repeat until (i>4) rand <-- RANDOM (1, i) DISPLAY (rand) i <-- i + 1 a. 1 1 1 1 b. 1 2 3 2 c. 1 2 3 4 d. 1 3 2 4

d. 1 3 2 4

consider the following code segment ans <-- RANDOM (1,3) + RANDOM(2,5) ans <-- and + RANDOM (4, 8) a. any integer from 1 to 8 inclusive b. any integer from 1 to 16 inclusive c. any integer from 4 to 8 inclusive d. any integer from 7 to 16 inclusive

d. any integer from 7 to 16 inclusive

three different numbers need to be placed in order from least to greatest. for ex, if the numbers are ordered 9, 16, 4, they should be reordered as 4, 9, 16. which of the following algorithms can be used to place any three in the correct order? a. if the first number is greater than the last, swap them. then if the first number is greater then the middle, swap them. b. if the first number is greater than the middle, swap them. if the middle number is greater than the last, swap them. c. if the first number is greater than the middle, swap them. if the first number is greater than the last, swap them. d. if the first number is greater than the middle, swap them. if the middle number is greater than the last, swap them. if the first number is greater than the middle, swap them.

d. if the first number is greater than the middle, swap them. if the middle number is greater than the last, swap them. if the first number is greater than the middle, swap them.

which of the following is a true statement about program documentation a. program documentation should not be changed after it is first written b. program documentation is only needed for programs in development; it is not needed after a program is completed. c. program documentation is useful when programmers collaborate but not when a programmer works individually on a project d. program documentation is useful during initial program development and also when modifications are made to existing programs

d. program documentation is useful during initial program development and also when modifications are made to existing programs

consider the following code segment a <-- true b <-- false c<-- true repeat until a AND b c <-- NOT c b <-- c display a display b display c what will be displayed as a result a. true false false b. true false true c. true true false d. true true true

d. true true true

the following code segment is used to determine whether a customer is eligible for a discount val1 <-- (NOT(category = "new")) OR (age >= 65) val2 <-- (category = "new") AND (age<12) a. val1 = true, val2 = true b. val1 = true, val2 = false c. val1 = false, val2 = true d. val1 = false, val2 = false

d. val1 = false, val2 = false


संबंधित स्टडी सेट्स

Learn: Trade in a Global Economy

View Set

Chapter 14: Reconstruction: An Unfinished Revolution 1865-1877

View Set

Public Speaking Chapter 17: Methods of Persuasion

View Set

Chapter 14: Care of the Patient with a Neurologic Disorder, Chapter 51: Care of the Patient with a Reproductive Disorder, Chapter 13: Care of the Patient with a Sensory Disorder, Chapter 43: Care of the Patient with a Musculoskeletal Disorder

View Set