Write an Iterative (loop) function that reverses a vector of elements in type st
ID: 3695484 • Letter: W
Question
Write an Iterative (loop) function that reverses a vector of elements in type string, by swapping corresponding elements in the vector. Your cannot use additional vectors in your solution or call a function of vector to directly reverse it. void ReverseStringVector{ }{ } Define a function CoordUpdate() that transforms its first two input parameters xln and yln into two output parameters xOut and yOut. The function returns void. The update is defined as new = (20^*old = 3) Ex: If xln = 3 and yln = 4. then xOut is 63 and yOut is 83. See example call to CoordUpdate() below in function main(). #include using namespace std; int main() { int xValNew = 0; int yValNew = 0; CoordUpdate(3,4, xValNew, yValNew); cout NestedLessLess ldquo (3,4) becomes ldquo NestedLessLess rdquo ( ldquo xValNew NestedLessLess rdquo, ldquo NestedLessLess y ValNew NestedLessLess rdquo) ldquo NestedLessLess endl; return 0; }Explanation / Answer
void ReverseStringVector(string s)
{
int i=0;
char temp;
int l = s.length()-1;
while(i<l)
{//swap first and last characters and loop till middle
temp = s[i];
s[i] = s[l];
s[l] = temp;
i++;
l--;
}
cout << "reversed: " << s << endl;
}
//pass reference for the variable to remain same in main function
void CoordUpdate(int xOld,int yOld,int &xValNew,int &yValNew)
{
xValNew = (20*xOld) + 3;
yValNew = (20*yOld) + 3;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.