Question: IN VISUAL STUDIO CODE ( C + + ) Deliverable: pointerproblemfunctions.cpp Purpose: Implement the Merge function whose prototype is given in pointerproblemfunctions.h . Read the

IN VISUAL STUDIO CODE (C++)
Deliverable: pointerproblemfunctions.cpp
Purpose: Implement the Merge function whose prototype is given in pointerproblemfunctions.h. Read the comments in pointerproblemfunctions.h (attached) for details about this function.
Specifications: - The files for this problem are in the attached problem2.zip - No changes are to be made in the attached pointerproblemfunctions.h file - Implement the Merge functions in pointerproblemfunctions.cpp and attach your revised pointerproblemfunctions.cpp file to the assignment. This is the most important file for this problem - The function should not create a memory leak or memory leaks - The code should compile and link with the command g++-std=c++17-I . pointerproblemfunctions.cpp pointerproblemdriver.cpp to see if your Merge function correctly merges two SortedDynamicArrays
Initial Testing: Randomly generated SortedDynamicArrays are created in pointerproblemdriver.cpp and the Merge function is called to merge the two structures. To test with the file, ou can use command make pointerproblemdriver.
C pointerproblemfunctions.h >...
// prototypes for functions implemented in pointerproblemfunctions.cpp
// DO NOT MODIFY THE CONTENTS OF THIS FILE!
#ifndef _POINTERPROBLEMFUNCTIONS_H_
#define _POINTERPROBLEMFUNCTIONS_H_
// the SortedDynamic struct will hold a pointer to a block of distinct sorted
// integers, and an integer that specifies the number of integers in the block.
// This structure type is used in pointerproblemdriver.cpp and by the Print
// and Merge functions whose prototypes are given below.
struct SortedDynamicArray {
int size;
int * values;
};
// the Print function is already implemented in pointerproblemfunctions.cpp
void Print(const SortedDynamicArray * const nums);
// You will implement the Merge function, whose prototype is given below, in
// pointerproblemfunctions.cpp
// The Merge function takes two pointers to SortedDynamicArray structures.
// The function assumes that the two structures the arguments point to contain
// distinct integers that are sorted in ascending order. These preconditions
// must be met in order for the function to merge the values as expected.
// The function will merge the two sorted lists of values into the structure
// that the first argument points to. That updated structure should be resized
// to exactly fit the merged, sorted list of distinct values.
// For example: If the first argument points to a structure with size 4 and
// values {3,8,15,22}, and the second argument points to a
// structure with size 6 and values {1,8,10,16,22,30}
// Then after the function call, the first argument should be
// updated to point to a structure with size 8 and values
//{1,3,8,10,15,16,22,30}
// We can omit the variable names in the function
// declaration below.
// In the definition in pointerproblemfunctions.cpp, you will need
// to pick your favorite variable names.
// The "const" after SortedDynamicArray * means the pointer
// should not be changed to point to a different object.
void Merge(SortedDynamicArray * const, const SortedDynamicArray * const);
#endif // end _POINTERPROBLEMFUNCTIONS_H_
``````
`+ pointerproblemfunctions.cpp
C+ pointerproblemfunctions.cpp >...
1 #include"pointerproblemfunctions.h"
#include
using std::cout;
using std::endl;
#include
using std::setw;
// do not modify the implementation of the Print function
void Print(const SortedDynamicArray * nums){
for ( int i =0; i nums->size; ++i )
cout setw(4) nums->values[i];
cout endl;
}
// implement the Merge function (described in pointerproblemfunctions.h) here
``````
pointerproblemdriver.cpp
@+ pointerproblemdriver.cpp >...
// Initial test driver for the struct / pointers / dynamic memory allocation
// problem on Exam 2.
// Your code should compile and link with this UNEDITED file in order to get
// compilation points.
// You are encouraged to create more rigorous tests.
#include
using std::cout;
using std::endl;
#include
#include
#include
using std::setw;
#include"pointerproblemfunctions.h"
int main(){
// seed the random function with the current time
srand(time(0));
SortedDynamicArray sorted1, sorted2;
// randomly generate sizes for two blocks of sorted integers
sorted1.size = rand()%20+1;
sorted1.values = new int[sorted1.size];
sorted2.size = rand()%20+8;
sorted2.values = new int[sorted2.size];
// fill the block of memory sortedl.values points to with a list of distinct
// "random" distinct integers sorted from smallest to largest
sorted1.values[0]= rand()%5;
for ( int i =1; i sorted1.size; ++i ){
sorted1.values[i]= sorted1.values[i -1]+ rand()%10+1;
}
// fill the block of memory sorted2.values points to with a list of distinct
// "random" distinct integers sorted from smallest to largest
sorted2.values[0]= rand()%8;
for ( int i =1; i sorted2.size; ++i ){
sorted2.values[i]= sorted2.values[i -1]+ rand()%6+1;
}
// print the two lists
cout "Size of sorted1=" sorted1.size "
V
IN VISUAL STUDIO CODE ( C + + ) Deliverable:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!