C++ Using the code provided below Do the Following: Modify the Insert Tool Function to ask the user if they want to expand the tool holder to accommodate additional tools Add the code to the insert tool function to increase the capacity of the toolbox (Dynamic Array)   USE THE FOLLOWING CODE and MODIFY IT:   #define _SECURE_SC

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

In C++
Using the code provided below
Do the Following:

  1. Modify the Insert Tool Function to ask the user if they want to expand the tool holder to accommodate additional tools
  2. Add the code to the insert tool function to increase the capacity of the toolbox (Dynamic Array)
  3.  

USE THE FOLLOWING CODE and MODIFY IT:

 

#define _SECURE_SCL_DEPRECATE 0

#include <iostream>

#include <string>

#include <cstdlib>

using namespace std;

 

class GChar

{

 

public:

static const int DEFAULT_CAPACITY = 5;

 

//constructor

GChar(string name = "john", int capacity = DEFAULT_CAPACITY);

 

//copy constructor

GChar(const GChar& source);

 

//Overload Assignment

GChar& operator=(const GChar& source);

 

//Destructor

~GChar();

 

//Insert a New Tool

void insert(const std::string& toolName);

 

private:

 

//data members

string name;

int capacity;

int used;

string* toolHolder;

 

};

//constructor

GChar::GChar(string n, int cap)

{

name = n;

capacity = cap;

used = 0;

toolHolder = new string[cap];

}

//copy constructor

GChar::GChar(const GChar& source)

{

cout << "Copy Constructor Called." << endl;

name = source.name;

capacity = source.capacity;

used = source.used;

toolHolder = new string[source.capacity];

copy(source.toolHolder, source.toolHolder + used, toolHolder);

}

//Overload Assignment

GChar& GChar::operator=(const GChar& source)

{

cout << "Overload Assignment Called." << endl;

//Check for self assignment

//c1=c1

if (this == &source)

{

return *this;

}

this->name = source.name;

this->capacity = source.capacity;

used = source.used;

 

copy(source.toolHolder, source.toolHolder + used, this->toolHolder);

}

//Destructor

GChar::~GChar()

{

cout << "Destructor called for " << this->name << " @ this memory location " << this << endl;

delete[] toolHolder;

}

 

void GChar::insert(const string& toolName)

{

if (used == capacity)

{

cout << " The tool holder is full, Cannot add any additional tools" << endl;

}

else

{

toolHolder[used] = toolName;

used++;

}

}

 

int main()

{

GChar gc1;

gc1.insert("potion");

gc1.insert("crossbow");

gc1.insert("candle");

gc1.insert("cloak");

gc1.insert("sword");

gc1.insert("book of spells");

 

GChar gc2("Bob", 5);

 

GChar gc3 = gc2;

 

return 0;

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education