Take the code below and add a copy constructor, assignment operator definition and destructor to the class. These functions have already been started for you.
#include
#include
using namespace std;
class Tool
{
public:
string getType()
{
return type;
}
int getQuant()
{
return quantity;
}
void set(string s, int q)
{
type = s;
quantity = q;
}
private:
string type;
int quantity;
};
class ToolBox2
{
public:
ToolBox2()
{
count = 3;
t = new Tool[count];
}
ToolBox2(int c)
{
if (c > 1)
count = c;
else
count = 3;
t = new Tool[count];
}
// copy constructor
ToolBox2(ToolBox2 &otherbox)
{
}
// assignment operator
ToolBox2& operator=(ToolBox2 &otherbox)
{
}
// destructor
~ToolBox2()
{
}
void set(int index, string s, int q)
{
t[index].set(s, q);
}
void display()
{
cout << "the tools are\n";
for (int i=0; i cout << t[i].getType() << ": " << t[i].getQuant() << endl;
}
private:
Tool *t;
int count;
};
int main()
{
ToolBox2 tb2;
tb2.set(0, "screwdrivers", 8);
tb2.set(1, "pliers", 5);
tb2.set(2, "wrenches", 20);
tb2.display();
return 0;
}