English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need to write a library similar to the header file. I need help writing the following functions. They are included in my own class called "string".

void resize(unsigned int, char);
//resizes character array "Buffer" to number specified by
//first parameter
//fills extra space by the second parameter character

void insert(unsigned int, string &);
//Inserts a string into "Buffer" a character array.
//First parameter: Place to insert
//Second parameter: string to insert.


void remove(unsigned int, unsigned int);
//removes characters from "Buffer", a character array.
//First parameter : Starting position,
//Second parameter : number of characters to remove.

2007-05-23 02:59:14 · 3 answers · asked by Karel d 1 in Computers & Internet Programming & Design

3 answers

Okay, this is pretty obviously homework. I won't show any code here, but I'll give you an idea how to implement the functions listed.

First, void resize(unsigned int, char); It has to do these things in approximately this order:
Validate int as greater than zero, or the operation is over before it starts. Next, it needs to allocate memory for a new Buffer with the extra space. Oh-oh. How do you find the buffer if it doesn't return a pointer or a reference to it? Better change the return type to char& or char *. Okay, now the new characters are written into the new buffer and then the old characters ... Oh-oh, we need to know where that things at too. Better include a reference or pointer to the old buffer as a parameter. So we take the old buffer and move the old characters over into the new buffer behind(?!) the new characters. Rats! Do we need to consider that the new characters should always be prepended or appended or does it change?

void insert(unsigned int, string & old_string, string & new_string); maybe?

void remove(unsigned int, unsigned int, string & buffer);

Unless you MUST follow these exact prototypes for your assignment, you may want to consider these modifications.

I think you can work these last two from the first walk through I gave you. They aren't really any different as to the mechanics of the problem, just what information is needed to operate from. Good luck!

2007-05-26 18:50:52 · answer #1 · answered by Anonymous · 0 0

Sounds like homework to me...
And if you can't do these simple things, you are in trouble!
Do it as a for(i=..;i<..;i++) loop, and use Buffer[i].
(or review the use of pointers: that's the beauty of C)

2007-05-23 05:19:07 · answer #2 · answered by just "JR" 7 · 0 0

probable considering the fact which you're which contain the .cpp utilizing a #contain... Dont use is composed of for .cpp. replaced that assertion with "extern bool strContains(const string inputStr, const string searchStr);" which will restore it

2016-11-26 19:29:22 · answer #3 · answered by yau 4 · 0 0

fedest.com, questions and answers