Implementation of the constructor


Discuss the below:

Q: Consider the class declaration

class demoClass
{
public:
// assign arguments as initial values for the data members
demoClass(int a = 5, int b = 10);
// function returns the maximum of itemA and itemB
// int max() const;
private:
int itemA, itemB;
};

(a) Give the implementation of the constructor using an initialization list.

(b) Implement the member function max() as an external function.

(c) For each of the following object declarations, give the corresponding initial values for attributes itemA and itemB:

demoClass obj1(7,9); // itemA = ________ itemB = ________
demoClass obj2(12); // itemA = ________ itemB = ________
demoClass obj3; // itemA = ________ itemB = ________

(d) What is the output from each statement, assuming the previous declarations?

cout << obj2.max(); // Output: _________
cout << obj3.max(); // Output: _________

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Implementation of the constructor
Reference No:- TGS01937551

Now Priced at $25 (50% Discount)

Recommended (99%)

Rated (4.3/5)