Question
Here is a C++ problem, I just need a main code to test my code. Here is my code: int locateMinimum( const string array[ ],
Here is a C++ problem, I just need a main code to test my code. Here is my code:
int locateMinimum( const string array[ ], int n ){ if(n => return -1; } else{ int minInd = 0; for(int i = 0; i if(array[i] minInd = i; } } return minInd; } }
int findLastOccurrence( const string array[ ], int n, string target ){ int ind = -1; if(n > 0){ for(int i = 0; i if(array[i] == target){ ind = i; } } } return ind; }
int flipAround( string array[ ], int n ){ int count = 0; if(n > 0){ for(int i = 0; i => if(i != n - i - 1){ ++count; string temp = array[i]; array[i] = array[n - i - 1]; array[n - i - 1] = temp; } } } return count; }
bool hasNoDuplicates( const string array[ ], int n ){ if(n return false; } else{ for(int i = 0; i for(int j = 0; j if(i != j && array[i] == array[j]){ return false; } } } return true; } }
void unionWithNoDuplicates( const string array1[ ], int n1, const string array2[ ], int n2, string resultingString[ ], int&resultingSize ){ if(n1 resultingSize = -1; } else{ resultingSize = 0; for(int i = 0; i bool found = false; for(int j = 0; j if(resultingString[j] == array1[i]){ found = true; } } if(!found){ resultingString[resultingSize++] = array1[i]; } } for(int i = 0; i bool found = false; for(int j = 0; j if(resultingString[j] == array2[i]){ found = true; } } if(!found){ resultingString[resultingSize++] = array2[i]; } } } }
int shiftRight( string array[ ], int n, int amount, string placeholderToFillEmpties ){ if(amount n || n return -1; } else{ for(int i = 1; i array[i] = array[i - 1]; } return n - amount; } }
bool isInIncreasingOrder( const string array[ ], int n ){ if(n return false; } else if(n == 0){ return true; } else{ for(int i = 1; i if(array[i] => return false; } } return true; } }
And my task is
Task
Here are the functions you must implement:
intlocateMinimum(conststringarray[ ],intn ); Return the index of the smallest item found in the array or -1 if n =>
int findLastOccurrence( const string array[ ], int n, string target ); Return the largest index that holds the target value in the array or -1 if it is not found at all or n => intflipAround(stringarray[ ],intn ); Flips the items found in the array so that the first item holds what was originally found in the last item, the last item holds what was originally found in the first item, and so on throughout the array. The function should keep track of all the flips it performs and return that count. For example, for the array people[ 5 ] shown above, flipAround( people, 5 ) should adjust the array so that it now holds { \"tyrion\", \"daenerys\", \"margaery\", \"jon\", \"samwell\" }; and should return 2 (because it performed the flip of samwell and tyrion and the flip of jon and daenerys).
bool hasNoDuplicates( const string array[ ], int n ); If every value in the array is unique and unduplicated, return true otherwise false or if n
void unionWithNoDuplicates( const string array1[ ], int n1, const string array2[ ], int n2, string resultingString[ ], int&resultingSize ); Create a new array by combining together all the items of array1 and array2, while ensuring that the new array has no duplicated values. If either n1 or n2 is less than or equal to zero, set the resultingSize to -1. For example, for the array string data[ 4 ] = { \"howard\", \"ucla\", \"howard\", \"ucla\" }; and the array people[ 5 ] shown above, then unionWithNoDuplicates( people, 5, data, 4, result, size ) should adjust the result array to hold the values { \"samwell\", \"jon\", \"margaery\", \"daenerys\", \"tyrion\", \"howard\", \"ucla\" }; and sizeshould have the value 7. For example, unionWithNoDuplicates( data, 4, people, 3, result, size ) should adjust the result array to hold the values { \"howard\", \"ucla\", \"samwell\", \"jon\", \"margaery\" }; and size should have the value 5. As the examples attempt to show, the elements coming from array1 should be listed before any elements coming from array2. (Note: Please be sure that your driver code has allocated enough array memory for the resultingString array to hold all the elements that this function plans to store into it)
int shiftRight( string array[ ], int n, int amount, string placeholderToFillEmpties ); Adjust the items found in the array, shifting each value to the right by amount parameter, filling the resulting first amount elements of the array with the placeholder parameter and returning the number of original array items still remaining in the array after all the shifting has been performed. For example, for the array people[ 5 ] shown above, shiftRight( people, 5, 3, \"foo\" ) should return 2 and adjust the array to have the value { \"foo\", \"foo\", \"foo\", \"samwell\", \"jon\" }; If the amount parameter is less than zero or exceeds n, return -1.
bool isInIncreasingOrder( const string array[ ], int n ); If every value in the array is larger than the one that precedes it, return true otherwise false or if n
Also, professor has gave a incomplete set of test for this project:
#include
#include
#include
using namespace std;
int main()
{
string a[6] = { \"alpha\", \"beta\", \"gamma\", \"gamma\", \"beta\", \"delta\" };
string b[6] = { \"delta\", \"gamma\", \"beta\", \"alpha\", \"beta\", \"alpha\" }; string h[7] = { \"samwell\", \"jon\", \"margaery\", \"daenerys\", \"\", \"tyrion\", \"margaery\" }; int answer;
string output[6] = { \" \", \" \", \" \", \" \", \" \", \" \" }; int outputSize = 6;
assert(locateMinimum(a, 3 ) == 0); assert(locateMinimum(b, 3 ) == 2); assert(findLastOccurrence(a, 5, \"beta\" ) == 4); assert(findLastOccurrence(b, 3, \"beta\" ) == 2);
assert(hasNoDuplicates(a, 3) == true); assert(hasNoDuplicates(a, 6) == false);
assert(isInIncreasingOrder(a, 3) == true); assert(isInIncreasingOrder(a, 6) == false); unionWithNoDuplicates(a, 6, b, 2, output, outputSize ); assert( outputSize == 4 ); assert( output[0] == \"alpha\" );
answer = shiftRight(h, 6, 1, \"foobar\" ); assert( answer == 5 ); assert( h[0] == \"foobar\" );
assert(flipAround(b, 3 ) == 1); assert(flipAround(b, 4 ) == 2);
cout
Can someone either finish this code or make a new one? I just need to test my function.
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