Mathematical Concepts of Programming (questions 45-52)

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

47. IF(a>3) AND (b) {z←1} ELSE { IF (c>10) {z←2} ELSE {z←3} } Which of the following code segments would produce the exact same output as the code above? Select TWO answers.

Incorrect: (A) IF (a>3) AND (b) {z←1} IF (c>10) {z←2} ELSE {z←3} Explanation: Choice A is incorrect because the last IF and ELSE statements are paired meaning one of them must happen. That is incorrect because neither may happen because of the first statement.

50. Which of the following conditions will evaluate to true given that x is true and y is false? Select TWO answers.

Incorrect: (A): (x OR y) AND (x AND y) Explanation: This answer is correct because this turns out to be (true) AND (false) which evaluates to false.

51. A school uses the following chart to determine if a student is exempt from taking the final exam in a class. All grades are rounded to integer values between 0 and 100. All absences are whole number. Final Grade # of Absences Exemption Status 90+ 0-5 Exempt 90+ 6+ Not Exempt 80-89 0-3 Exempt 80-89 4+ Not Exempt 70-79 0 Exempt 70-79 1+ Not Exempt 0-69 n/a Not Exempt Which of the following procedures would correctly return the exemption status of a student?

Correct Answer: (A) PROCEDURE exemptionStatus (grade, absences) { IF ( (grade>89 AND absences <6) OR (grade>79 AND absences<4) OR (grade>69 AND absences=0) ) { RETURN ("Exempt) } ELSE { RETURN ("Not Exempt") } } Explanation: This code is the correct one because only one of the expressions in the compound condition would have to be true for the program to return "Exempt" and that would be correct.

52. A program reports the number of hours and minutes that have passed given a total number of minutes. For example, consider the following input. totalMin: 85 The following would be output: 1 hour and 25 minutes have passed. Which of the following code segments would assign the correct values to the hour and minutes variables?

Correct Answer: (B) minutes←totalMin MOD 60 hour←(totalMin-minutes)/60 Explanation: This is the correct choice because it first sets minutes to the remainder of totalMin divided by 60, this will let you know the extra minutes that have passed.

48. PROCEDURE test (x) { answer←1 REPEAT x TIMES { answer←answer•x x←x-1 } RETURN (answer) } Which of the following accurately describes what the test procedure does?

Correct Answer: (B) Returns z factorial Explanation: This answer is correct because no matter what number is used as x the program will return the answer as one less every time.

46. IF(a>3) AND (b) {z←1} ELSE { IF (c>10) {z←2} ELSE {z←3} } Assume that a is set to 7, b is false, and c is 8. What will z be after this code segment?

Correct Answer: (C) 3 Explanation: This answer is correct because the first statement proves to not be completely true as b is false. Because of this you move down to the ELSE. We are told c is 8 therefore the answer is 3.

49. PROCEDURE test (x) { answer←1 REPEAT x TIMES { answer←answer•x x←x-1 } RETURN (answer) } Which of the following changes would allow the procedure to return the exact same output as the original code?

Correct Answer: (D) Change "REPEAT x TIMES" to "REPEAR (x-1) TIMES" Explanation: Choice D is correct because the last loop of the procedure just multiplies answer by 1, it is only possible to repeat (x-1) times.

52. A program reports the number of hours and minutes that have passed given a total number of minutes. For example, consider the following input. totalMin: 85 The following would be output: 1 hour and 25 minutes have passed. Which of the following code segments would assign the correct values to the hour and minutes variables?

Incorrect: (A) hour←totalMin/60 minutes←totalMin MOD 60 Explanation: This answer is not correct because when it divides it does not find the remainder in order to be able to find the extra minutes.

46. IF(a>3) AND (b) {z←1} ELSE { IF (c>10) {z←2} ELSE {z←3} } Assume that a is set to 7, b is false, and c is 8. What will z be after this code segment?

Incorrect: (A) 1 Explanation: This answer is not correct because we are told b is false, therefore z will not be equal to 1.

49. PROCEDURE test (x) { answer←1 REPEAT x TIMES { answer←answer•x x←x-1 } RETURN (answer) } Which of the following changes would allow the procedure to return the exact same output as the original code?

Incorrect: (A) Change "answer←1" to "answer←0" Explanation: This answer is incorrect because if this was done the factorial will be equal to 0 every time the loop is run.

48. PROCEDURE test (x) { answer←1 REPEAT x TIMES { answer←answer•x x←x-1 } RETURN (answer) } Which of the following accurately describes what the test procedure does?

Incorrect: (A) Returns the value of x raised to the z Explanation: This answer is not correct because nowhere in the program is x being raised to z.

51. A school uses the following chart to determine if a student is exempt from taking the final exam in a class. All grades are rounded to integer values between 0 and 100. All absences are whole number. Final Grade # of Absences Exemption Status 90+ 0-5 Exempt 90+ 6+ Not Exempt 80-89 0-3 Exempt 80-89 4+ Not Exempt 70-79 0 Exempt 70-79 1+ Not Exempt 0-69 n/a Not Exempt Which of the following procedures would correctly return the exemption status of a student?

Incorrect: (B) PROCEDURE exemptionStatus (grade, absences) { IF ( (grade>89 OR absences<6) AND (grade>79 OR absences<4) AND (grade>69 OR absences=0) ) { RETURN ("Exempt") } ELSE { RETURN ("Not Exempt") } } Explanation: This procedure is incorrect because it has the conditional operators AND and OR reversed which causes the program to return "Exempt" if the grade is above 69 and the number of absences is 0.

46. IF(a>3) AND (b) {z←1} ELSE { IF (c>10) {z←2} ELSE {z←3} } Assume that a is set to 7, b is false, and c is 8. What will z be after this code segment?

Incorrect: (B) 2 Explanation: This choice is not correct because c=8 which is not greater than 10, so z will not be equal to 2.

49. PROCEDURE test (x) { answer←1 REPEAT x TIMES { answer←answer•x x←x-1 } RETURN (answer) } Which of the following changes would allow the procedure to return the exact same output as the original code?

Incorrect: (B) Change "answer←answer • x" to "answer←x•x" Explanation: Choice B is incorrect because the answer will always be set to x squared instead of the x factorial.

50. Which of the following conditions will evaluate to true given that x is true and y is false? Select TWO answers.

Incorrect: (B): [(NOT x) OR y] OR (x AND y) Explanation: This answer is correct because this turns out to be (false) OR (false) which evaluates to false.

51. A school uses the following chart to determine if a student is exempt from taking the final exam in a class. All grades are rounded to integer values between 0 and 100. All absences are whole number. Final Grade # of Absences Exemption Status 90+ 0-5 Exempt 90+ 6+ Not Exempt 80-89 0-3 Exempt 80-89 4+ Not Exempt 70-79 0 Exempt 70-79 1+ Not Exempt 0-69 n/a Not Exempt Which of the following procedures would correctly return the exemption status of a student?

Incorrect: (C) PROCEDURE exemptionStatus (grade, absences) { IF ( (grade>89 AND absences<6) ) { RETURN ("Exempt") } ELSE { IF(grade>79 AND absences<4) { RETURN ("Exempt") } ELSE { (grade>69 AND absences=0) { RETURN ("Exempt") } ELSE { IF (grade>70) { RETURN ("Not Exempt") } } } } } Explanation: This procedure would only work correctly for the scenarios where students are exempts. It only returns "not exempt" when the grade is below 70.

52. A program reports the number of hours and minutes that have passed given a total number of minutes. For example, consider the following input. totalMin: 85 The following would be output: 1 hour and 25 minutes have passed. Which of the following code segments would assign the correct values to the hour and minutes variables?

Incorrect: (C) minutes←totalMin MOD 60 hour←totalMin/60 Explanation: Choice C is not correct because it is calculating the number of hours for the minutes.

45. IF (x > 0) {x←1} IF (x<0) {x←-1} ELSE {x←0} The code segment above is supposed to set x equal to 1 if x was positive, -1 if it was negative, and do nothing to x if it was 0. Which of the following changes could be made so that the code will work as intended? Select TWO answers.

Incorrect: (C) Replace the first and second IF statements with the following: IF (x=0) { IF (x<0) {x←-1} ELSE {x←1} } Explanation: This choice is incorrect because it does not make sense to check if x is 0 since x is set to 0 in the ELSE statement.

49. PROCEDURE test (x) { answer←1 REPEAT x TIMES { answer←answer•x x←x-1 } RETURN (answer) } Which of the following changes would allow the procedure to return the exact same output as the original code?

Incorrect: (C) Change "answer←answer•x" to "answer←answer•(x-1)" and delete "x←x•1" Explanation: This answer is incorrect because the procedure would return (x−1) raised to the x since x does not decrease at the end of each loop.

48. PROCEDURE test (x) { answer←1 REPEAT x TIMES { answer←answer•x x←x-1 } RETURN (answer) } Which of the following accurately describes what the test procedure does?

Incorrect: (C) Returns 0 Explanation: Choice C is not correct because whatever value you choose for x and repeat the program x times it will end at 1.

47. IF(a>3) AND (b) {z←1} ELSE { IF (c>10) {z←2} ELSE {z←3} } Which of the following code segments would produce the exact same output as the code above? Select TWO answers.

Incorrect: (D) IF (a>3) AND (b) {z←1} IF (a<=3) AND (NOT b) AND (c>10) {z←2} IF (a<=3) AND (NOT b) AND (c>=10) {z←3} Explanation: This choice is incorrect because it cannot work unless the last statement said (c<=10).

51. A school uses the following chart to determine if a student is exempt from taking the final exam in a class. All grades are rounded to integer values between 0 and 100. All absences are whole number. Final Grade # of Absences Exemption Status 90+ 0-5 Exempt 90+ 6+ Not Exempt 80-89 0-3 Exempt 80-89 4+ Not Exempt 70-79 0 Exempt 70-79 1+ Not Exempt 0-69 n/a Not Exempt Which of the following procedures would correctly return the exemption status of a student?

Incorrect: (D) PROCEDURE exemptionStatus (grade, absences) { IF ( (grade>89 AND absences>5) OR (grade>79 AND absences>3) OR (grade>69 AND absences>0) { RETURN ("Not Exempt") } ELSE { IF (grade <70) { RETURN ("Not Exempt") } ELSE { RETURN ("Exempt") } } } Explanation: This answer is not correct because the three expressions in the compound condition are separated by OR, so only one of them would have to be true for the whole statement to be true.

52. A program reports the number of hours and minutes that have passed given a total number of minutes. For example, consider the following input. totalMin: 85 The following would be output: 1 hour and 25 minutes have passed. Which of the following code segments would assign the correct values to the hour and minutes variables?

Incorrect: (D) hour←totalMin/60 minutes←totalMin/60 Explanation: Choice D is incorrect because it is doing the same thing for minutes and hours and those should not be the same.

45. IF (x > 0) {x←1} IF (x<0) {x←-1} ELSE {x←0} The code segment above is supposed to set x equal to 1 if x was positive, -1 if it was negative, and do nothing to x if it was 0. Which of the following changes could be made so that the code will work as intended? Select TWO answers.

Incorrect: (D) Replace the second IF statement with an ELSE. Explanation: Choice D is incorrect because replacing the second IF with an ELSE would leave the second ELSE without an IF.

48. PROCEDURE test (x) { answer←1 REPEAT x TIMES { answer←answer•x x←x-1 } RETURN (answer) } Which of the following accurately describes what the test procedure does?

Incorrect: (D) Returns the value of x raised to the (x-1) Explanation: The choice D is wrong because x is being set equal to x-1 not raised to x-1.

46. IF(a>3) AND (b) {z←1} ELSE { IF (c>10) {z←2} ELSE {z←3} } Assume that a is set to 7, b is false, and c is 8. What will z be after this code segment?

Incorrect: (D) z will not be set to anything Explanation: Choice D cannot be correct because z is always set to something, so there is no scenario where z cannot be set to something.

45. IF (x > 0) {x←1} IF (x<0) {x←-1} ELSE {x←0} The code segment above is supposed to set x equal to 1 if x was positive, -1 if it was negative, and do nothing to x if it was 0. Which of the following changes could be made so that the code will work as intended? Select TWO answers.

Correct Answer #2: (B) Replace the first and second IF statements with the following: IF [NOT (x=0)] { IF (x<0) {x←-1} ELSE {x←1} } Explanation: Choice B solves the problem by changing the first IF statement to check to see if x is not 0. If x is not 0, it checks to see if the value will be positive or negative inside another if statement.

47. IF(a>3) AND (b) {z←1} ELSE { IF (c>10) {z←2} ELSE {z←3} } Which of the following code segments would produce the exact same output as the code above? Select TWO answers.

Correct Answer #2: (C) IF (a>3) { IF (b) {z←1} ELSE { IF (c>10) {z←2} ELSE {z←3} } } ELSE { IF (c>10) {z←2} ELSE {z←3} } Explanation: Choice C is correct because though it it not as efficient as the original code, it still works. It works by taking away the AND from the original code and instead turned it into a series of IF statements.

50. Which of the following conditions will evaluate to true given that x is true and y is false? Select TWO answers.

Correct Answer #2: (D): (NOT y) AND (x OR y) Explanation: This answer is correct because this turns out to be (true) AND (true) which evaluates to true.

45. IF (x > 0) {x←1} IF (x<0) {x←-1} ELSE {x←0} The code segment above is supposed to set x equal to 1 if x was positive, -1 if it was negative, and do nothing to x if it was 0. Which of the following changes could be made so that the code will work as intended? Select TWO answers.

Correct Answer #1: (A) Replace the second IF and the ELSE with the following: ELSE { IF (x<0) {x←-1} ELSE {x←0} } Explanation: With this solution, the problem is solved by inserting another IF/ELSE statement inside an ELSE. This works because there are no IF/IF statements, it must be IF/ELSE.

47. IF(a>3) AND (b) {z←1} ELSE { IF (c>10) {z←2} ELSE {z←3} } Which of the following code segments would produce the exact same output as the code above? Select TWO answers.

Correct Answer #1: (B) IF (a>3) AND (b) {z←1} IF (a<=3) OR (NOT b) { IF (c>10) {z←2} ELSE {z←3} } Explanation: This choice is correct because it replaced the second ELSE with an IF. This is unnecessary, but the code will work nonetheless.

50. Which of the following conditions will evaluate to true given that x is true and y is false? Select TWO answers.

Correct Answer #1: (C): (x or y) AND [x AND (NOT y)] Explanation: This answer is correct because this turns out to be (true) AND (true) which evaluates to true.


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

Chapter 4 Cell Structure and Function

View Set

Chapter 15-Assessing Head and Neck

View Set

Chapter 24 On-Board Diagnostic and Scan Tools

View Set

TEXTBOOK: Ch. 8: Television, Cable, and Mobile Video

View Set