Our string class always deletes the old character buffer

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

Our String class always deletes the old character buffer and reallocates a new character buffer on assignment or in the copy constructor. This need not be done if the new value is smaller than the current value, and hence would fit in the existing buffer. Can we rewrite the String class so that each instance will maintain an integer data field indicating the size of the buffer, then only reallocate a new buffer when necessary. Abstract the common tasks from the assignment operator and the copy constructor, and place them into an internal method?

Here is the string class

class String
{
public:
String(); // Default constructor
String(const char p[]); // Simple constructor
String(const String& right); // Copy constructor
~String(); // Destructor
String& operator=(const String& right); // Assignment operator
String& operator+=(const String& right);
int length() const;
char& operator[](int index);
char operator[](int index) const;
private:
char* buffer;
int len;

 

 

Reference no: EM13167742

Questions Cloud

Determine the rate of reaction : Given the following balanced equation, determine the rate of reaction with respect to [NOCl]. If the rate of Cl2 loss is 4.84 x 10-2 M/s, what is the rate of formation of NOCl?
A file (complex.txt) which has a number of complex numbers : Read in a file (complex.txt) which has a number of complex numbers in the form of a+bi (e.g. 3+5i  2-3i etc).
Calculate the mass of silver chloride required to plate : Calculate the mass of silver chloride required to plate 235 mg of pure silver. Silver chloride, often used in silver plating, contains 75.27% .
What is the heat of fusion per mole of cadmium : A 35.8-g sample of cadmium metal was melted by an electric heater providing 4.66 J/s of heat. If it took 6.92 min from the time the metal began to melt until it was completely melted, what is the heat of fusion per mole of cadmium?
Our string class always deletes the old character buffer : Our String class always deletes the old character buffer and reallocates a new character buffer on assignment or in the copy constructor.
Other area of medicine would you expect technology : In what other area of medicine would you expect technology to make inroads next? Where do you think it would be most beneficial and how would it changes the way doctors and nurses work today? Provide several examples
How many moles of acetylene will be produced : If 6.20 mol calcium carbide (CaC2) reacts with an excess of water, how many moles of acetylene (C2H2) will be produced?
How many grams of kcio3 were used : if 82.7874 grams of oxygen was given off during the decomposition, how many grams of KCIO3 were used?
Software driver that will implement a byte-wide data : Design the hardware and software driver that will implement a byte-wide data transfer from your processor to a peripheral device. Each transfer must be accompanied by a strobe to deskew the data. Draw the UML sequence diagram and the timing diagra..

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