Question
Below is a partially implemented C++ program that manages a dynamic array of WordFreq objects. Please implement the four functions highlighted in the main( ).
Below is a partially implemented C++ program that manages a dynamic array of WordFreq objects. Please implement the four functions highlighted in the main( ). You can either first declare the prototypes of these four functions above main() and then implement them below main(); or simply implement these functions above main( ) without declaring their prototypes separately. Submission instruction: copy and paste the following code into your submission and then insert your code. Please remember to include exception handling whenever you call the new operator in the constructArray( ) function.
#include#include using namespace std;
struct WordFreq{ //same as the second coding lab string word; int Freq; };
int main( ) { WordFreq *arrayWF=nullptr; int size=0; int capacity = 20; WordFreq wf = {Hello, 10};
//the following function // (1) allocates a memory space capable to hold up to capacity WordFreq objects; and (2) each object is initially set to (,0) constructArray( arrayWF, size, capacity);
//the push_back() function inserts the WordFreq object wf to the back of the arrayWF. Please note that this function needs to allocate more memory if needed. for (int i=0; i<100; i++) push_back(arrayWF, size, capacity, wf);
//the function below prints out all the WordFreq objects stored in arrayWF one at a time in the format of (word, freq) printArray(arrayWF, size);
//deallocate the memory space held by arrayWF deallocateArrayWF( arrayWF );
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started