Question
Requirements: c++, new programmer, simple code string people[5] = { samwell, jon, margaery, daenerys, tyrion }; string folks[8] = { samwell, jon, margaery, daenerys, tyrion,
Requirements: c++, new programmer, simple code
string people[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" };
string folks[8] = { "samwell", "jon", "margaery", "daenerys", "tyrion", "sansa", "howard123", "jon"}
1) int countSs( const string array[ ], int n ); Return the number of 's' or 'S' characters found inside each of the elements of the passed array or if n <= 0 return -1. For example, for the array people[ 5 ] shown above, countSs( people, 5 ) should return 2.
2) Change shiftRight function to match:
int shiftLeft( string array[ ], int n, int amount, string placeholderToFillEmpties ); Adjust the items found in the array, shifting each value to the left by amount parameter, filling the resulting first amount elements of the array with the placeholder parameter and returning the number of times the placeholder value has been used after all the shifting has been performed. For example, for the array people[5] shown above, shiftLeft( people, 5, 3, "foo" ) should return 3 and adjust the array to have the value { "daenerys", "tyrion", "foo", "foo", "foo" }; If n <= 0, return 0 because no shifting will have been performed at all. If amount exceeds n, return n since all of the original element will have been stomped over by this function.
int shiftRight( string array[ ], int n, int amount, string placeholderToFillEmpties )
{
int elementsRemaining = -1;
if (n >= amount && amount >= 0)
{
elementsRemaining = n - amount;
for ( int i = 1; i <= elementsRemaining; i++)
{
// move over the existing data over....
array[ n - i ] = array[ elementsRemaining - i ];
}
// put in the new placeholder values in the front of the array
for ( int i = 0; i < amount; i++)
{
array[ i ] = placeholderToFillEmpties;
}
}
return( elementsRemaining );
}
3)
bool matchingValuesTogether( const string array[ ], int n ); If all the duplicated values found in the array are located one right after the other, return true otherwise false. If you don't find any duplicated values at all, then return true since you never found any values violating this together principle. If n <=0, return false. For example, for the array people[ 5 ] shown above, matchingValuesTogether( people, 5 ) should return true. For the array folks[ 8 ], matchingValuesTogether( folks, 8 ) should return false because the two "jon" values are not located in the array in contiguously located elements, one right after the other.
4)
int divide( string array[ ], int n, string divider ); Rearrange the elements of the array so that all the elements whose value is < divider come before all the other elements, and all the elements whose value is > divider come after all the other elements. (Yes, there might be numerous correct rearrangements that are valid.) Return the position of the first element that, after the rearrangement, is not < divider, or 0 if there are none.
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