Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education