I've written the backbone for this code. I just needed a little insight on how i would complete the functions. i figure that a.swap(b)
would work for swaping two strings within the same array. Am i wrong?
Any insight/ suggestions are appreciated.
#include <string>
using std::string;
#include <iostream>
#include <cassert>
using namespace std;
void swap(string & a, string & b); // swaps two strings.
void reverse_arr(string a1[], int n1); // reverse an array of strings.
void swap_arr(string a1[], int n1, string a2[], int n2); // swaps two arrays of strings.
int main(){
string futurama[] = { “fry”, “bender”, “leela”,
“professor farnsworth”, “amy”,
“doctor zoidberg”, “hermes”, “zapp brannigan”,
“kif”, “mom” };
for (int i=0;i<10;i++)
cout << futurama[i] << endl;
swap(futurama[0],futurama[1]);
cout << “After swap(futurama[0],futurama[1]);” << endl;
for (int i=0;i<10;i++)
cout << futurama[i] << endl;
reverse_arr(futurama,10);
cout << “After reverse_arr(futurama,10);” << endl;
for (int i=0;i<10;i++)
cout << futurama[i] << endl;
// declare another array of strings and then
// swap_arr(string a1[], int n1, string a2[], int n2);
char w;
cout << “Enter q to exit.” << endl;
cin >> w;
return 0;
}
void swap(string & a, string & b){
// swaps two strings.
a.swap(b);
}
void reverse_arr(string a1[], int n1) {
// Reverse an array of strings.
}
void swap_arr(string a1[], int n1, string a2[], int n2) {
// swaps two arrays of strings.
}