Share
Explore BrainMass

Data Structures with C++ (STL)

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

(a) Give the implementation of the constructor using an initialization list.
demoClass::demoClass(int a=5, int b=10) {
itemA=a;
itemB=b;
}
(b) Implement the member function max() ...

Solution Summary

Data Structures with C++ (STL) are examined.

$2.19