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

  Write a program to make the ssds function

Write a program to make the SSDs function as a MM:SS real-time clock. Hint: You must not use a single delay routine for the one second delay because that will not allow for persistence of vision. The displays need to be constantly refreshed during ev..

  Write a program that skip s leading whitespace character

a) Write a program that skip s leading whitespace character s in each line of the pro vided data file CPPHumor .txt . Save the results in a new file

  Store a list of student info

Store a list of student info, (id number, First name and Last name) using a link list. The ID is the key field. The program should implement a linked list using arrays.The program should process the following operations

  Write a program that will represent an axis-aligned

Write a program that will represent an axis-aligned right triangle in the x-y plane as a Class. A right triangle has a right angle (90-degree angle) and two sides adjacent to the right angle, called legs. See http://en.wikipedia.org/wiki/Right_tri..

  Write program which prompts user to enter numbers

Write down the program which prompts the user to enter numbers, findsout how many positive and negative values have been entered, and calculates sum and average of numbers entered.

  Given a character code to indicate the type of customer

Pete's Plumbing of Pompey sells to both retail and wholesale buyers. The retail buyer must pay New York State and Onondaga County sales tax (8%). However, the wholesale buyer does not pay sales tax and receives a volume discount on the amount purchas..

  Opportunity to work with both c style strings

The focus of this lab is on using strings. You will have an opportunity to work with both C style strings and the string data type. This lab also gives you an opportunity to use what you have learned previously

  Write a full program that implements the aggregation concept

Write a full program that implements the aggregation concept for the Mail Message, Header , Body and Attachment classes.

  Write a c++ program containing a linked list of 10 integer

Write a C++ program containing a linked list of 10 integer numbers. Have the program display the numbers in the list.

  Create a program that contains 4 methods

Create a program that contains 4 methods / functions... main(), getTestScores(), calcAverage(), and displayAverage(). The main() method should call the getTestScores() method to get and return each of 3 test scores.

  All the new strings generated

Explain why, if on some round, all the new strings generated for any syntactic category are longer than s, and s has not already been generated for L(), then s cannot ever be put in L(). Hint: Use Exercise 11.3.5.

  Calculate the total of a purchase from a farmer''s market

You will develop a program that can calculate the total of a purchase from a farmer's market that sells apples, bananas, and oranges. At this particular market, apples are $1.99/lb., bananas are $0.99/lb., and oranges are $1.50/lb. Users should be..

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