Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions

Question

Examine various types of executive compensation plans.

Answered: 1 week ago

Question

1. What is the meaning and definition of banks ?

Answered: 1 week ago

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago

Question

3. What information do participants need?

Answered: 1 week ago