Hello everyone, this is my third post for help for my Programming Meth Class. My class has gotten a problem in Lab where only 3/the entire class figured out. It's due Sunday and I just don't know what to do. Well I should say I don't have time to do it because I have an exam on Sunday plus this assignment being due right after the exam, but can anyone give me help or teach me how to merge these arrays. My program looks like this. I don't want anyone to fiddle around with the main function. I just don't know what to do in the void merge function. Also we are supposed to use strcpy and strcmp functions. I looked on google on how to merge arrays but they do it without the functions. Can anyone help??? Much appreciated and would help this future engineer out a lot.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <cstring>
using std::strcpy;
using std::strcmp;
//write the prototype of the merge fucntion here
void merge ( char * [ ], int, char * [ ], int, char * [ ] )
//main function for testing the merge routine
int main()
{
char *arr1[20];
char *arr2[20];
char *arr3[40];
//write code to allocate memory for all elements in arr1 and arr2
for ( i = 0; i < 20; i++ )
{
char arr1[ i ] = new char[ ];
char arr2[ i ] = new char[ ];
}
for ( l = 0; l < 40; l++ )
{
char arr3[ j ] = new char[ ];
}
//initialize arr1 and arr2
arr1[0]="ant";
arr1[1]="bird";
arr1[2]="dog";
arr1[3]="zebra";
arr2[0]="cat";
arr2[1]="monkey";
arr2[2]="octopus";
arr2[3]="parrot";
//write code to call merge rountie to merge arr1 and arr2 to arr3
merge( arr1, 4, arr2, 4, arr3 )
//write code to display all elements in arr3 one by one
for ( int j = 0; j < 8; j++ )
cout << arr3[ j ];
//write code to release the mememory of arr1, arr2, and arr3
for ( j = 4; j < 20; j++ )
{
delete arr1[ j ];
delete arr2[ j ];
}
for ( k = 8; k < 40; k++ )
{
delete arr3[ k ];
}
return 0;
}
/*This function merges arr1 and arr2 into a final array arr3,
which should be ascending order too.
Assumptions:
1) arr1 and arr2 are two characger pointer arrays, which
are both in ascending order
2) arr1 and arr2 have been initialized and contain size1
and size2 number of elements respecitively
3) arr3 has not been initialized
*/
void merge( char *arr1[], int size1, char *arr2[], int size2, char *arr3[] )
{
//write code to implement the merge routine
}
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <cstring>
using std::strcpy;
using std::strcmp;
//write the prototype of the merge fucntion here
void merge ( char * [ ], int, char * [ ], int, char * [ ] )
//main function for testing the merge routine
int main()
{
char *arr1[20];
char *arr2[20];
char *arr3[40];
//write code to allocate memory for all elements in arr1 and arr2
for ( i = 0; i < 20; i++ )
{
char arr1[ i ] = new char[ ];
char arr2[ i ] = new char[ ];
}
for ( l = 0; l < 40; l++ )
{
char arr3[ j ] = new char[ ];
}
//initialize arr1 and arr2
arr1[0]="ant";
arr1[1]="bird";
arr1[2]="dog";
arr1[3]="zebra";
arr2[0]="cat";
arr2[1]="monkey";
arr2[2]="octopus";
arr2[3]="parrot";
//write code to call merge rountie to merge arr1 and arr2 to arr3
merge( arr1, 4, arr2, 4, arr3 )
//write code to display all elements in arr3 one by one
for ( int j = 0; j < 8; j++ )
cout << arr3[ j ];
//write code to release the mememory of arr1, arr2, and arr3
for ( j = 4; j < 20; j++ )
{
delete arr1[ j ];
delete arr2[ j ];
}
for ( k = 8; k < 40; k++ )
{
delete arr3[ k ];
}
return 0;
}
/*This function merges arr1 and arr2 into a final array arr3,
which should be ascending order too.
Assumptions:
1) arr1 and arr2 are two characger pointer arrays, which
are both in ascending order
2) arr1 and arr2 have been initialized and contain size1
and size2 number of elements respecitively
3) arr3 has not been initialized
*/
void merge( char *arr1[], int size1, char *arr2[], int size2, char *arr3[] )
{
//write code to implement the merge routine
}