Discover answers to your questions with Westonci.ca, the leading Q&A platform that connects you with knowledgeable experts. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform. Discover detailed answers to your questions from a wide network of experts on our comprehensive Q&A platform.

A teacher put three bonus questions on a test and awarded 5 extra points to anyone who answered all three bonus questions correctly and no extra points otherwise. Assume that the boolean variables bonusOne, bonusTwo, and bonusThree indicate whether a student has answered the particular question correctly. Each variable was assigned true if the answer was correct and false if the answer was incorrect. Which of the following code segments will properly update the variable grade based on a student's performance on the bonus questions?

I. if (bonusOne && bonusTwo && bonusThree)grade += 5;
II. if (bonusOne || bonusTwo || bonusThree)grade += 5;
III. if (bonusOne)grade += 5; if (bonusTwo)grade += 5; if (bonusThree)grade += 5;

a. I only
b. II only
c. III only
d. I and III
e. II and III



Sagot :

Answer:

The answer is "Option a".

Explanation:

In this question, option (I) is correct because it uses the if condition block, that declares three variable that is "bonusOne, bonusTwo, and bonusThree", in which it uses the AND logic gate that checks the condition and add value 5 in grade variable, and other choices were wrong which can be defined as follows:

  • In option II, it uses the OR operator, when each of the variable value is "true" it will add value 5 in grade variable that's why it's wrong.
  • In option III, it uses multiple conditions to check the variable value and add value 5 in the wrong grade variable.