Question

C++ languageWrite a function, int flip(string a[], int n); It reverses the order of the elements of the array and returns n. The variable

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++

#include <iostream>

using namespace std;
//function flips the order of the elements
int flip(string a[], int n)
{
int i = 0,end = n-1;
//loop flips the order of the elements
while (i < end)
{
  
string temp = a[i];
a[i] = a[end];
a[end] = temp;
i++;
end--;
}
//return the n value
return n;
  
}
//main function
int main()
{
//varaible declaration
string a[6] = {"a","b","","c","d","e"};
//calling a function & passing the parameter & returned value is stored into q variable
int q = flip(a , 4);
//printing the returned value
cout<<q;


return 0;
}

8 10- 13 1 #include <iostream> 2 3 using namespace std; 4 //function flips the order of the elements 5 int flip(string a[], i

Add a comment
Know the answer?
Add Answer to:
C++ language Write a function, int flip(string a[], int n); It reverses the order of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ ONLY Write a function, int flip(string a[], int n); It reverses the order of the...

    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...

  • C ++Write a function, anyThree (int a[], int n), that returns true if the value 3...

    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...

  • I have to write a loop that moves the content of the dynamic array to the...

    I have to write a loop that moves the content of the dynamic array to the static array but I can't seem to figure it out. Exit Full Screen code.cpp New 1 #include <iostream> 3 using namespace std; 4 5 int main) 6 int *ptr 7 ptr -new int[5]; 8 int arr[5]; 9int x; 10 cin >> x; 11 for( int í = 0; 1 < 5; 1++) // initialization 12 13 ptr[i] x; = 14 for O//your code goes...

  • C++ Write a recursive function that reverses the given input string. No loops allowed, only use...

    C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. #include <iostream> #include <string> using namespace std; //Write a recursive function 'void reverse(string &str)' that reverses the given input string. void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sherry";    reverse(name);    cout << name << endl; //should...

  • Write a C++ function, parsePhrases(...), that takes a string and replaces every comma ‘,’ and period...

    Write a C++ function, parsePhrases(...), that takes a string and replaces every comma ‘,’ and period ‘.’ with the newline character ‘\n’. Important: the function should edit the string (i.e. there should be no cout << calls within the function). Example Program: #include <iostream> using namespace std; // TODO: implement function parsePhrases (...) - no cout calls; int main() { string text = "In theory there is no difference between theory and "; text += "practice. In practice there is....

  • help me solving this both please in c++ language 6 Write function max(int al Lint n)...

    help me solving this both please in c++ language 6 Write function max(int al Lint n) that receives an array of integer and its length, it returns the maximum number in that array. Test your function in main. 7) Write functin reverse (char x[ .int n) that reieves an array of characters and reverse the order of its elements. Test this function in main.

  • /* Array expander: Write a function that accepts an int array as argument. The function should...

    /* Array expander: Write a function that accepts an int array as argument. The function should create a new array that is n times the size of the argument array, where n is a user input. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array */ #include <iostream> using namespace std; const int NUM_ELEM...

  • C++ Language Given an array length 1 or more of ints, return the difference between the...

    C++ Language Given an array length 1 or more of ints, return the difference between the largest and smallest values in the array. Examples: largeDiff (410, 3, 5, 6}, 4) - 7 largeDiff ({7, 2, 10, 9}, 4) - 8 largeDiff ({2, 10, 7, 2}, 4) + 8 largeDiff ({2}, 1) = 0 code.cpp + New I Full Screen 2- int largeDiff (const int a[], int n) { 3 4 5}

  • In C language Write a program that includes a function search() that finds the index of...

    In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...

  • Write function in C++: int removeDups (string a[], int n); For every sequence of consecutive identical...

    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] =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT