Add a copy constructor

Assignment Help C/C++ Programming
Reference no: EM13165968

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 <iostream>
#include <string>
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<count; 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;
}

Reference no: EM13165968

Questions Cloud

Find out the amount of iron chloride hexahrdrate : The solution of iron (III) chloride used in this experiment is 0.02M. Determine the amount of iron (III) chloride hexahrdrate
How much energy in calories was absorbed : A canister is filled with 310 of ice and 100. of liquid water, both at 0 . The canister is placed in an oven until all the has boiled off and the canister is empty. How much energy in calories was absorbed?
Reaction to the public service announcement-e-activity : From the e-Activity, discuss your reaction to the public service announcement in relation to the marketing of junk food to children, with a focus on why or why not this PSA is appropriate.
What mass of calcium oxide is required daily : If the coal is burned in a power plant that uses 1800 tons of coal per day, what mass of calcium oxide is required daily to eliminate the sulfur dioxide?
Add a copy constructor : 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.
State polyethylene is a polymer consisting of only carbon : Polyethylene is a polymer consisting of only carbon and hydrogen. If 2.300 g of the polymer is burned in oxygen it produces
How much heat is required to vaporize : the heat of vaporization of benzene, C6H6, is 30.8kJ/mol at its boiling point of 80.1C. How much heat is required to vaporize 102g benzene at its boiling point?
Beginning with the row number passed : Write a MATLAB function that takes a matrix, a row number and a column number. Beginning with the row number passed to the function, scan down the column passed to the function and return the row number that contains the largest absolute value in ..
State calibrate ion-selective electrodes : You will need two series of standard solutions to calibrate your ion-selective electrodes - one series for sodium and one for calcium.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd