Clicker Questions

Week 2 - OOP

Opinion 1:

Consider the following code snippet:
int n;
float f;  
cout << "Enter an integer and a float: ";
cin >> n >> f;
cout << "The integer is: " << n << endl;
cout << "The float is: " << f << endl;
If the user types 3.7 at the prompt, the program will output:
  1. The integer is: 3.7
    The float is: 0
  2. The integer is: 3
    The float is: <garbage>
  3. The integer is: 4
    The float is: <garbage>
  4. The program will print something else.
  5. The program will crash.


Question 2:

Consider the following code snippet
float x = 7;
float y = 11;
Point p(3,2);
p.setX(y);
p.print();
  
What is the output of this program?
  1. (3, 11)
  2. (7, 11)
  3. (11, 2)
  4. (3, 2)
  5. This will generate an error


Question 3:

Consider the following code snippet
Point p;
Point *ppt, *qpt;
ppt = &p;
qpt = ppt;
qpt->setX(10);
p.print();
  
What is the output of this program?
  1. (0, 0)
  2. (10, 0)
  3. The program will not compile.
  4. The program will generate an error when run.