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

  Two for loops that will calculate the sum of all even number

Write a program using two for loops that will calculate the sum of all even numbers between 2 and 100,

  Reads from the external file input.txt

Program that reads from the external file input.txt, counts the letters in every word, replaces the word by that number, and then writes the numbers to an external file output.tx

  Write program to count occurrences of each word in text

Write down C++ program to read following text. Count occurrences of each word in text and keep this count in list of elements containing (word, occurrence count) pairs.

  Emulates the behavior of a bus

Write a program that emulates the behavior of a bus. The bus must have a schedule ( a finite number of times for it to stop) and a certain capacity (number of passengers). In this program the bus has two states: stopped and going.

  Program that uses an instance of the timeoff

Write a program that uses an instance of the TimeOff class you designed in Programming Challenge 5. The program should ask the user to enter the number of months an employee has worked for the company. It should then use the TimeOff object to calc..

  Show the deatils of an emplyoee - c programming

Show the deatils of an emplyoee in a neat format.

  Write a program to calculate a person''s net pay

Write a program to calculate a person's net pay after subtracting federal income tax.The program should ask the user to enter the person's name, social security number, gross pay, and the number of dependents.

  Write the class definition for a class called complex

. Write the class definition for a class called complex.

  Convert celsius temperatures to fahrenheit temperatures

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

  Prepare a linux shell

Prepare a linux shell (in other words, write a C/C++ program) that will recursively prompt for input from the user. The shell should prompt as

  Grocery store program

This program draws upon several concepts that were covered in CptS 121 and should serve as a good refresher for CptS 122. Our store, Cougar Mart, maintains its inventory in a text file. Not being very tech savvy, the owner of Cougar Mart needs you to..

  Write function that finds the minimum of three double value

1. Write a function that finds the minimum of three double values. This function should use another function that finds the minimum of two double values.

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