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

  Reverses the characters in a character array

Write the function reverseit that reverses the characters in a character array. You must also write main that calls reverseit.

  Write a programme on credit card number check

Credit Card Number Check. The last digit of a credit card number is the check digit, which protects againsttranscription errors such as an error in a single digit or switching two digits

  Windows application that function like a banking account

Create a Windows application that function like a banking account register. Separate the business logic from the presentation layer. The graphical user interface should allow user to input the account name, number, and balance.

  Class to act as a generic array

Create a class to act as a generic array (i.e. the user will be able to choose the data type to be stored by passing the appropriate template argument.

  Multiply a set of complex numbers

Write a C program to multiply a set of complex numbers stored in an array (that has been dynamically allocated). Specifically, first prompt the user to enter how many complex numbers need to be multiplied, dynamically create an array to store the ..

  Describe the probability of the moves

Write a program in C++ to describe the Probability of the moves

  How nested if-statements replace with one if-statement

Describe how following nested If-statements could be replaced with one if-statement using logical operator (And/Or/Not). Write down the C++ code example.

  Create the appropriate constructor, getters and setters

Create the appropriate constructor, getters and setters for the class. Create an instance of Student for each of the students listed above from array. Construct the instance with lastname, firstname, and job.

  Computer programming techniques

Construct a program from a design and use appropriate functions

  Program to enter number of values to be processed

Write c++ statements to permit the user to enter n, the number of values to be processed; then assign the anonymous array of n double values, storing its address in doublPtr.

  Add a sentinel command to stop the loop

add a sentinel command to stop the loop. When the program is compiled, It'll ask the user to type in a palindrome. I want the user to type EXIT to end the loop.

  Write in c++ another overloaded operator

Write in C++ another overloaded operator to go in the program that has Treasury. Overload the forward slash /  so that in the main program, you can declare sale to be of type Treasury, and commission to be of type Treasury, and commispctage to be of ..

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