Palisades Charter High School**We aren't endorsed by this school
Course
COMPUTER SCIENCE 180251
Subject
Computer Science
Date
Dec 17, 2024
Pages
5
Uploaded by MasterAtomBarracuda34
In the following procedure, the parametermaxis a positive integer.PROCEDURE printNums(max){count←1REPEAT UNTIL(count > max){DISPLAY(count)count←count + 2}}
Which of the following is the most appropriate documentation to appear with theprintNumsprocedure?ResponsesAPrints all positive even integers that are less than or equal tomax.BPrints all positive odd integers that are less than or equal tomax.CPrints all positive even integers that are greater thanmax.DPrints all positive odd integers that are greater thanmax.Answer BCorrect. The procedure initializes count to 1. Inside the loop, the value of count isdisplayed, then count is incremented by 2 to the next odd integer. The loop terminateswhen count exceeds max, so all positive odd integers less than or equal to max areprinted.In the following procedure, the parametersxandyare integers.
Which of the following is the most appropriate documentation to appear with thecalculateprocedure?ResponsesADisplays the value ofx + (y / x).The value of the parameterxmust not be0.BDisplays the value ofx + (y / x).The value of the parameterymust not be0.CDisplays the value of(x + y) / x.The value of the parameterxmust not be0.DDisplays the value of(x + y) / x.The sum of the parametersxandymust not be0.Answer CCorrect. The code segment first adds the values of x and y, then divides the sum by x,then prints the result. The value of x must not be 0; otherwise a divide-by-zero error willoccur when result is divided by x.In the following procedure, the parameternumListis a list of numbers and the parametersjandkare integers.PROCEDURE swapListElements(numList, j, k)
{newList←numListnewList[j]←numList[k]newList[k]←numList[j]RETURN(newList)}Which of the following is the most appropriate documentation to appear with theswapListElementsprocedure?
ResponsesAReturns a copy ofnumListwith the elements at indicesjandkinterchanged.The value ofjmust be between0and the value ofk, inclusive.BReturns a copy ofnumListwith the elements at indicesjandkinterchanged.The values ofjandkmust both be between1andLENGTH(numList), inclusive.CInterchanges the values of the parametersjandk.The value ofjmust be between0and the value ofk, inclusive.DInterchanges the values of the parametersjandk.The values ofjandkmust both be between1andLENGTH(numList), inclusive.Answer BCorrect. The procedure creates a copy of numList called newList. The element atnewList[j] is assigned the element at numList[k], and the element at newList[k] isassigned the element at numList[j]. Therefore, the difference between numList andnewList is that the elements at indices j and k are interchanged. The procedure onlyworks if j and k are valid list indices, so it is important to document that j and k are bothbetween 1 and LENGTH(numList), inclusive.