Question: Please explain why the correct answer is correct. Q1.1: Which of the following is a valid constructor for the class above? a) void MyInt(int val)

 Please explain why the correct answer is correct. Q1.1: Which of

Please explain why the correct answer is correct.

Q1.1:

Which of the following is a valid constructor for the class above?

a) void MyInt(int val) { n = val; }

b) void MyInt(int val) : n(val) { }

c) MyInt(int val) : val(n) { }

d) MyInt(int n) : n(n) { }

Q1.2: In the driver program above, replace /* construct object */ with MyInt k(5); Assuming the correct answer to Q1.1, what happens when you try to compile and run the program?

a) It doesn't compile

b) It throws a runtime erro

c) It outputs 0

d) It outputs 2

e) It outputs 5

f) It outputs 7

Q1.3: In the driver program above, replace /* construct object */ with MyInt k; Assuming the correct answer to Q1.1, what happens when you try to compile and run the program?

a) It doesn't compile

b) It throws a runtime error

c) It outputs 0

d) It outputs 2

e) It outputs 5

f) It outputs 7

The code snippet gives a simple class and driver program, with a line missing from each. #import using namespace std; class MyInt { public: /* constructor */ int getN() { return n; } void setN(int newval) { n = newval; } private: int n; }; int main() { /* construct object */ k.setN(k.getN() +2); cout

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!