Question: Exercise P7.15. Exercise P7.14 demonstrated how to use the string and vector classes to implement resizable arrays. In this exercise, you should implement that capability
Exercise P7.15. Exercise P7.14 demonstrated how to use the string and vector classes to implement resizable arrays. In this exercise, you should implement that capability manually. Allocate a buffer of 1,000 characters from the heap (new char[1000]). Whenever the buffer fills up, allocate a buffer of twice the size, copy the buffer contents, and delete the old buffer. Do the same for the array of char* pointersstart with a new char*[100] and keep doubling the size.
**(I dont think i answered the question right with my code, can anybody help? Its C++)**
#include
using namespace std;
/**define macros to define line size and arrays length**/ #define SIZE 1000 #define Line_Size 100
/**Function to print the elements**/ void Print(char**& input_line,int line_count) { int i; cout << "Characters entered, line by line now in a new array with double the size: "; for( i=0;i<=line_count;i++) { cout< /**Function to resize the array and delete old array**/ void IncreaseArray(char *&CurrArray,int &Currentsize) { /*Multiply the value of Currentsize by two and assigned it into Currentsize.*/ Currentsize=Currentsize*2; char*ptr=new char[Currentsize]; /*Iterate the for loop until the old size of the array.*/ for(int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
