Question: Assume that you correct for minor compile-time errors. Given the code for the following game, identify the statements that are true. #include ; using namespace

Assume that you correct for minor compile-time errors. Given the code for the following game, identify the statements that are true.

  1. #include ;
  2. using namespace std;
  3. int main() {
  4. int i = 10, b, tries = 0;
  5. cout << "Guess the number between 0 and 19?" << endl;
  6. for(; tries < 4; tries++) {
  7. cin << b;
  8. if(i == b) break;
  9. if(i >= b) cout << "higher" << endl;
  10. else if (i < b) cout << "lower" << endl
  11. }
  12. if(tries == 4)
  13. cout < "The answer was: " << i << ". Game Over!" << endl;
  14. else
  15. cout << "Correct!" << end1;
  16. return 0;
  17. }

Select one or more:

a. The program would always run the same if line 15 uses if instead of else if.

b. If we instead assigned i the value of 12 and guessed 10, 15, 13, 12, then the outputs would be lower, higher, lower, Correct!

c. If we instead assigned i the value of 9 and guessed 11, 6, 10, 8, then the outputs would be lower, higher, lower, higher, The answer was: 9. Game Over!

d. If the error on line 14 is not fixed, the output will be wrong.

e. If we instead assigned i the value of 9 and guessed 11, 6, 10, 8, then the outputs would be higher, higher, lower, higher, The answer was: 9. Game Over!

f. If we instead assigned i the value of 12 and guessed 10, 15, 13, 12, then the outputs would be higher, lower, lower, Correct!

g. tries needs to be initialized before the first ; on line line 11 or the output may be undefined.

Assume that you correct for minor compile-time errors. Select the statements that are true.

  1. #include
  2. #include
  3. using namespace std;
  4. int main() {
  5. int f = 2;
  6. double k = -1.2;
  7. double a = 1.44;
  8. const float epsilon = 0.000001;
  9. if(abs(pow(k, f)) - a < epsilon) {
  10. cout << "Power! ";
  11. }
  12. if(pow(k, f+1) == abs(pow(k, f+1))) {
  13. cout << "More Power! ";
  14. }
  15. cout << end1;
  16. return 0;
  17. }

Select one or more:

a. The equivalence operator on line 15 should be === to avoid floating point error.

b. The output is Power! More Power!

c. No choice of epsilon will ever catch all floating point rounding errors.

d. Floating point multiplication is inexact and can lead to unexpected errors.

e.The output is Power!.

cout << bar[3] < end1;

Assume that you correct for minor compile-time errors. Select the true statements about the following code.

  1. #include
  2. using namespace std;
  3. int main() {
  4. int x, y, z;
  5. cin > x > y > z;
  6. if(x < y) {
  7. if(y < z)
  8. cout << "first < second";
  9. cout << " and second < third" << endl;
  10. } else {
  11. cout << "second <= first and "
  12. if(x < z)
  13. cout << "first < third" << endl
  14. } else {
  15. cout << "third <= first") << endl;
  16. }
  17. return 0;
  18. }
  19. Select one or more:

    a. If the input is "2 1 3" then the output will be second <= first and first < third

    b. If the input is "2 1 3" then the output will be second <= first and third <= first

    c. If the input is "3 1 2" then the output will be second <= first and third <= first

    d.If the input is "3 1 2" then the output will be and second < third

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!