Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ 1.Below is a partially implemented C++ program that manages a dynamic array of WordFreq objects. Please implement the four functions highlighted in the main(

c++

1.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; }

2.

Given the following lines of code, what will be the output, i.e., the value of *(ptr+3)?

 int intArray[7] ={121, -21, 5, 103, 71, 11, 101}; int *ptr = &intArray[2];
 cout << *(ptr+3); 

3.

Given the following class interface

class IntPair{ private: int num1; int num2; public: //Question. What's the function prototype to overload the - (subtraction) operator as a // member function, which restricts this operator from modifying either of the // operands? This function will return an IntPair object. 
 // If needed, please use lhs or rhs to refer to the left-hand side // or right-hand side operand in your prototype. Also, if you need to pass in // one or more parameters to this function, you are required to pass it by reference. };

4.

Given the following pointer:

 struct WordFreq{ string word; int freq; };
 WordFreq *arrayWF = nullptr; 

Please allocate an array of 999 WordFreq objectx and make this array the pointee of arrayWF.

5.

Will the following C++ code lead to a compilation error?

int x=0;

if (x=10)

x += 1;

Select one:

a. Yes.

b. No.

4.

Declare a pointer to functions with the name of funcPtr. Furthermore, this pointer can be used to point to any function that takes two double parameters and returns a double. For example, funcPtr can be used to point to the following function max().

 double max( double x, double y); //returns max(x, y) 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

Complexity of linear search is O ( n ) . Your answer: True False

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago