CSCI 240 - Possible Questions for Quiz 4

  1. (2 points) The three basic flow-of-control patterns are sequence, ___________ and __________

  2. (2 points) The three basic loop statements in C++ are while, _______, and _________

  3. (2 points) Write a fragment of code that checks a string variable to see if it contains your first name or not, and then prints either "that's me" or "that's not me" accordingly. Assume that the string variable aName has a valid string in it before the test is made.

  4. (2 points) Write a fragment of code that accepts integers from the user until a negative number is entered. The prompt should be "Enter a number (negative to quit):" Add up the numbers and print the sum (not including the negative number). Assume and use the following declarations:

  5. int sum = 0;
    int num;
  6. (2 points) Given the variables top, left, right, and bottom representing the coordinates of a rectangle's upper left and lower right corners, and variables ptX and ptY, representing the coordinates of a point, write a condition to test if the point is outside the rectangle. Assume that x increases to the right and that y increases to the top.

  7. (2 points) Write a for loop that does exactly the same thing as the following code:

  8. i = 1;
    while (i < 11)
      {
      cout << "the square root of " << i << " is " << sqrt(i);
      i += 2;
      }
  9. (2 points) Create a symbolic constant named PI to represent the value of pi (3.14) in two different ways.

  10. (2 points) Give two reasons why symbolic constants might be used in a C++ program.

  11. (2 points) What will the following code fragment print?

  12. for (i = 0; i < 5; i++);
        cout << i + 1;
    cout << i;
  13. (2 points) Suppose

  14. x = 0;
    y = 5;

    Is the following condition true or false?

    if (x > 0 && x < 10 || y = = 4)
  15. (2 points) Which of the following is a legal way to create a C-style symbolic constant?

    1. #define MAX_VAL = 30;
    2. #define MAX_VAL 30
    3. #define MAX_VAL = 30
    4. #define MAX_VAL