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

  Flipflaps - game based on pancake sorting

The project is to design and write a C++ 11/FLTK game program with a graphical user interface.The game is based on "pancake sorting,", which actually has some mathematical significance.

  Design a simple game of blackjack

Prepare a simple game of blackjack using object oriented programming.

  Write function to accept character array

Write down the C++ function which will accept the character array of at most 30 cells. Your function must return true if string and its reverse are identical;

  Write song playlist class-object-oriented design principles

Write a song playlist class in C++ called "PlayList" using object-oriented design principles. The playlist should support the following ADT.The implementation should be based on an array of strings to store the song titles.

  C assignment of curl library

C Assignment Curl library must be used To be done on linux, it should be compiled using the following command: gcc -Wall -ansi -pedantic NameOfFile.c -lncurses Please make sure it is commented with clarification Variable names in camel case

  Write a program that plays a tic-tac-toe game.

Using functional decomposition, write a program that plays a tic-tac-toe game.

  Write c program which has parent process and child process

Write a C program that has a parent process, a child process, and a grandchild process. The parent process should print its id and the square or 5.

  Write c program that forks two child processes

Write a C program that forks two child processes. The parent process will print all prime numbers up to 229, the first child process will print the first 50 Fibonacci numbers.

  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..

  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,

  Squares, triangles, circles and ellipses

write a program which will answer a pair of questions for squares, triangles, circles and ellipses. A square is defined by its lower left corner ( S L L x , S L L y ), and the length of one side  S W .

  Output the even numbers from 1 to 10 in ascending order

Output the even numbers from 1 to 10 in ascending order, then the odd numbers from 10 to 1 in descending order: 2 4 6 8 10 9 7 5 3 1. in C++

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