reversal

Your friend tells you that she's disappointed that "palindrome", a word or phrase that is the same backwards and forwards, is not itself a palindrome. Words such as "Bob" or "Taco cat" are palindromes.

However, "palindrome" is an "emordnilap", which is a recently coined word that denotes a word or phrase that creates another word backwards (such as "dog" and "god" or "desserts" an "stressed".

You decide to write a program that automatically reverses a string of up to 50 characters and prints out the result. Use arrays to reverse up to 50 characters and print them back to the screen. Assume there are no spaces.

39
 
1
#include <iostream>
2
3
using namespace std;
4
5
6
int main(){
7
   char buffer[50];
8
   cout<<"Enter a string to be reversed:"<<endl;
9
   
10
   //size as a variable is needed here because you don't know, a priori, how much of buffer will be filled
11
   //you will later learn a way to measure the size of an array directly, but don't worry about that here.
12
   int size = 0;
13
   for(int i = 0; cin>>buffer[i]; i++)
14
   {
15
      size++;
16
   }
17
   // What do you need to add to the end of the array?
18
                          
19
   
20
   char reversedbuffer[50];
21
22
   // Reverse the buffer from the buffer array into the reversedbuffer array
23
   // Don't forget what you need to add to the end of the reversedbuffer array
24
25
26
27
28
29
30
   cout<<"reversed string:";
31
32
   // Print out the string (don't use a loop if you can help it)
33
   // Don't print a newline (endl)...we'll do that ourselves.
34
35
36
   cout << endl;
37
38
    return 0;
39
}