The Name Reversing Program - Fun with Arrays and Pointers
#include iostream
using namespace std;
int main()
{
string names[] = { "Ben Dover", "Chuck Roast", "Jim Naysium",
"Ella Quint", "Justin Case" };
char originalname[100], reversedname1[100], reversedname2[100];
for (int i=0; i<5; ++i)
{
strcpy(originalname,names[i].c_str());
reverseWithArrays( originalname , reversedname1 );
cout << originalname << " reversed with arrays is "
<< reversedname1 << endl;;
reverseWithPointers( originalname , reversedname2 );
cout << originalname << " reversed with pointers is "
<< reversedname2 << endl;;
cout << endl;
}
system("pause"); return 0;
}
Use this program as a starting point, add the two missing functions, and submit the new complete program. The reverseWithArrays function must use [ ] notation, and the reverseWithPointers function must use * notation. This program should produce output similar to the following:
Ben Dover reversed with arrays is Dover, Ben
Ben Dover reversed with pointers is Dover, Ben
Chuck Roast reversed with arrays is Roast, Chuck
Chuck Roast reversed with pointers is Roast, Chuck
Jim Naysium reversed with arrays is Naysium, Jim
Jim Naysium reversed with pointers is Naysium, Jim
Ella Quint reversed with arrays is Quint, Ella
Ella Quint reversed with pointers is Quint, Ella
Justin Case reversed with arrays is Case, Justin
Justin Case reversed with pointers is Case, Justin
Press any key to continue . . .