C++ ONLY Write a function, int flip(string a[], int n); It reverses the order of the elements of the array and returns n. The variable n will be greater than or equal to zero.
Example:
string array[6] = { "a", "b", "", "c", "d", "e" };
int q = flip(array, 4); // returns 4
// array now contains: "c" "" "b" "a" "d" "e"
![Write a function, int flip(string a[], int n); It reverses the order of the elements of the array and returns n. The variable](http://img.homeworklib.com/questions/6ec42670-0bdf-11eb-8830-ad6cbf35cae5.png?x-oss-process=image/resize,w_560)
C++ Code:
#include <iostream>
using namespace std;
int flip(string arr[],int n){
string *ptr1=arr;
string *ptr2=arr+n-1;
while(ptr1<ptr2){
string temp=*ptr1;
*ptr1=*ptr2;
*ptr2=temp;
ptr1++;
ptr2--;
}
return n;
}
int main() {
string arr[6]={"a","b","","c","d","e"};
cout<<"Before flip: ";
for(int i=0;i<6;i++)
cout<<arr[i]<<" ";
cout<<endl;
flip(arr,4);
cout<<"After flip: ";
for(int i=0;i<6;i++)
cout<<arr[i]<<" ";
cout<<endl;
}

if you like the answer please provide a thumbs up
C++ ONLY Write a function, int flip(string a[], int n); It reverses the order of the...
C++ language
Write a function, int flip(string a[], int n); It reverses the order of the elements of the array and returns n. The variable n will be greater than or equal to zero. Example: string array[6] = { "a", "b", "", "c", "d", "e" }; int q = flip(array, 4); // returns 4 // array now contains: "C" "" "" "a" "d" "e" O Full Screen 1 code.cpp + New #include <string> 2 using namespace std; 3 4- int...
C ++Write a function, anyThree (int a[], int n), that returns
true if the value 3 appears in the array exactly 3 times, and no
3's are next to each other. The parameter n will be greater than or
equal to 0.
Write a function, anyThree (int all, int n), that returns true if the value 3 appears in the array exactly 3 times, and no 3's are next to each other. The parameter n will be greater than or...
Can you make this a function? Thank you.
int locationOfMin(const string a[], int n): Return the position of a string in the array such that that string is < = every string in the array. If there is more than one such string, return the smallest position of such a string. Return -1 if the array has no elements. Here's an example: string people[5] = { "samwell", "jon", "margaery", "daenerys" "tyrion" }: int j = locationOfMin(people, 5);//returns 3, since daenerys...
Write function in C++:
int removeDups (string a[], int n); For every sequence of consecutive identical items in a, retain only one item of that sequence. Suppose we call the number of retained items r. Then when this function returns, elements through of a must contain the retained items (in the same relative order they were in originally), and the remaining elements may have whatever values you want. Return the number of retained items. Here's an example: string [9] =...
In C++ Write a function int * return_matches(int a[], int & size,TEST t) which returns an array (allocated off of the heap in the function) containing only the elements of array a that pass the “test” t. The function iterates through all the elements of a, and constructs a new array containing all the elements that pass the test. When the parameter corresponding to “size” is passed in (by reference), it contains the size of the array a. In the...
Write a function getScores(...) that is given a string, an int type array to fill and the max number of elements in the array as parameters and returns an integer result. The function will find each substring of the given string separated by space characters and place it in the array. The function returns the number of integers extracted. For example: int values[3]; getScores("123 456 789", values, 3 ); would return the count of 3 and fill the array with...
please do in c++Q4. Using recursion only (no loops allowed!), write a C++ function of the form int count7s(int) that when passed a non-negative integer, returns the number of occurrences of the digit 7 in the number. So, for example: count7s(717) → 2 count75(7) →1 count7s(123) → 0 Q5. Write a C++ function of the form string mirrorEnds(string)that when given a string, looks for a mirror image (backwards) string at both the beginning and end of the given string. In other words, zero or...
Using C,
Write a function reverse which takes a string as an argument, reverses the string and returns the reversed string. Note; you should not return a string that you created inside the reverse function! For example: Test char str[]-"hello" printf("%s", reverse (str)); Result olleh
write a C program!! Q2 and Q3
Write the following functioned int search(int a[], int n, int key, int **loc); a is an array to be searched, n is the number of elements in the array, key is the search key, and loc is a pointer to the first location of the search key in array a (if found) or NULL otherwise. The function returns 1 if key is found in a, and returns 0 otherwise. Write a main() and...
13. Write a recursive function with the declaration: int count Equal (int* numbers, int n, int x) that has as parameters an array numbers with n > 0 elements, and an integer x, and returns how many times I appears in the array. 14. Write a recursive function with the declaration: double dist(double* u, double *v, int n) that gets two double precision arrays with n > 1 elements and returns the value: Vu[0] - v[0])2 + (u[1] – v[1])2...