having issue writing function for void edit text line pretty sure need to delete
ID: 3749293 • Letter: H
Question
having issue writing function for void edit text line pretty sure need to delete text than do textength the allocate a new name if that wirte help or if have different idea to ifnish this small program
#include <iostream>
#include "Text.h"
#include <cstring>
using namespace std;
/*
Function Name: Text (constructor)
Parameters: Send a pointer to a constant character array or a string literal to this function
Purpose: called automatically when Text object is created, dynamically allocates a character array which contains the character array passed to the function
*/
Text::Text(const char*)
{
textLength= strlrn(text);
char* tmparr= new char[testArray+1];
stpcpy(tmparr,text); //copying the passed array into the temp array.
textArray= tmparr;
}
Text::~Text()
{
delete textArray;
}
void Text:: displayText() const
{
cout<< textArray << endl;
}
void Text::editText(const char*)
{
}
const char* Text::getText() const
{
return array:
}
int Text::getLength() const
{
return textLength;
}
Explanation / Answer
If you have any doubts, please give me comment...
#include <iostream>
#include "Text.h"
#include <cstring>
using namespace std;
/*
Function Name: Text (constructor)
Parameters: Send a pointer to a constant character array or a string literal to this function
Purpose: called automatically when Text object is created, dynamically allocates a character array which contains the character array passed to the function
*/
Text::Text(const char *text)
{
textLength = strlen(text);
char *tmparr = new char[testLength + 1];
stpcpy(tmparr, text); //copying the passed array into the temp array.
textArray = tmparr;
}
Text::~Text()
{
delete textArray;
}
void Text::displayText() const
{
cout << textArray << endl;
}
void Text::editText(const char *text)
{
textLength = strlen(text);
char *tmparr = new char[testLength + 1];
stpcpy(tmparr, text);
textArray = tmparr;
}
const char *Text::getText() const
{
return textArray:
}
int Text::getLength() const
{
return textLength;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.