I need help to finish this program: //Purpose: This program tests comparing two
ID: 3617958 • Letter: I
Question
I need help to finish this program: //Purpose: This program tests comparing two one dimensional arrays to each// other. Specifically, the program will read in an arry of
// characters and see if it is a palindrome by copying the
// array backwards into another array, then seeing if the
// two arrays have the same values.
//Note: Words can be no longer than 20 characters, but they may be shorter.
#include <iostream>
using namespace std;
//function prototypes
void readWord(char[],int&);
void reverseWord(char[],char[],int);
bool palindrome(char[],char[],int);
int main()
{
//Variable declarations
char word[20],reverse[20];
int howMany;
//initialize both arrays to contain the character ' '
initialize boththe arrays with the blank character ' '
//read the word
readWord(word,howMany);
//create the reverse of the original word
reverseWord(word,reverse,howMany);
// print the reversed word
cout << "Reversed word is : " ;
for(int i=0; i<20;i++)
cout << reverse[i];
cout << endl;
//output the original word
for(int i=0; i<20;i++)
cout << word[i];
//if the two words are the same, the original was a palindrome
if(palindrome(word,reverse,howMany))
cout << " is a palindrome. ";
else
cout << " is not a palindrome. ";
return 0;
}
//function readWord reads in characters until ' ' and keeps count
//of how many characters were read. The first parameter is the array
//to store the word read. The second parameter is for how many characters.
void readWord(char word[],int& howMany)
{
int i=0;
howMany = 0;
cin.get(word[i]);
while((word[i] != ' ') && (i < 20))
{
howMany++;
i++;
cin.get(word[i]);
}
if(word[i] == ' ')
word[i] = ' ';
return;
}
//function reverseWord takes two character array parameters and an integer
//parameter telling how many characters are in the first array.
//The purpose of reverseWord is to copy the first array into the second
//array backwards.
void reverseWord(char word[],char reverse[],int howMany)
{
//Write thecode necessary to copy the array word into the array//reverse in backwards order. Remember that if there are howMany//characters in the array, then the last character is stored in//location howMany-1, and the first character is stored in location 0.
return;
}
//function palindrome takes two character array parameters and an integer
//parameter telling how many characters are in each array.
//The purpose of palindrome is to compare each character in the first
//array with the corresponding character in the second array and see if
//the two arrays are identical. If they are, then palindrome returns true.
//Otherwise palindrome returns false.
bool palindrome(char word[],char reverse[],int howMany)
{
//Write thecode necessary to compare each character of word with the//corresponding character of reverse. If the two characters are ever//not the same, then the function should return false. Otherwise//the function should return true.
} I need help to finish this program: //Purpose: This program tests comparing two one dimensional arrays to each
// other. Specifically, the program will read in an arry of
// characters and see if it is a palindrome by copying the
// array backwards into another array, then seeing if the
// two arrays have the same values.
//Note: Words can be no longer than 20 characters, but they may be shorter.
#include <iostream>
using namespace std;
//function prototypes
void readWord(char[],int&);
void reverseWord(char[],char[],int);
bool palindrome(char[],char[],int);
int main()
{
//Variable declarations
char word[20],reverse[20];
int howMany;
//initialize both arrays to contain the character ' '
initialize boththe arrays with the blank character ' '
//read the word
readWord(word,howMany);
//create the reverse of the original word
reverseWord(word,reverse,howMany);
// print the reversed word
cout << "Reversed word is : " ;
for(int i=0; i<20;i++)
cout << reverse[i];
cout << endl;
//output the original word
for(int i=0; i<20;i++)
cout << word[i];
//if the two words are the same, the original was a palindrome
if(palindrome(word,reverse,howMany))
cout << " is a palindrome. ";
else
cout << " is not a palindrome. ";
return 0;
}
//function readWord reads in characters until ' ' and keeps count
//of how many characters were read. The first parameter is the array
//to store the word read. The second parameter is for how many characters.
void readWord(char word[],int& howMany)
{
int i=0;
howMany = 0;
cin.get(word[i]);
while((word[i] != ' ') && (i < 20))
{
howMany++;
i++;
cin.get(word[i]);
}
if(word[i] == ' ')
word[i] = ' ';
return;
}
//function reverseWord takes two character array parameters and an integer
//parameter telling how many characters are in the first array.
//The purpose of reverseWord is to copy the first array into the second
//array backwards.
void reverseWord(char word[],char reverse[],int howMany)
{
//Write thecode necessary to copy the array word into the array//reverse in backwards order. Remember that if there are howMany//characters in the array, then the last character is stored in//location howMany-1, and the first character is stored in location 0.
return;
}
//function palindrome takes two character array parameters and an integer
//parameter telling how many characters are in each array.
//The purpose of palindrome is to compare each character in the first
//array with the corresponding character in the second array and see if
//the two arrays are identical. If they are, then palindrome returns true.
//Otherwise palindrome returns false.
bool palindrome(char word[],char reverse[],int howMany)
{
//Write thecode necessary to compare each character of word with the//corresponding character of reverse. If the two characters are ever//not the same, then the function should return false. Otherwise//the function should return true.
}
Explanation / Answer
Dear.. //Purpose: This program tests comparing two one dimensional arrays to each// other. Specifically, the program will read in an arry of
// characters and see if it is a palindrome by copying the
// array backwards into another array, then seeing if the
// two arrays have the same values.
//Note: Words can be no longer than 20 characters, but they may be shorter.
#include <iostream>
using namespace std;
//function prototypes
void readWord(char[],int&);
void reverseWord(char[],char[],int);
bool palindrome(char[],char[],int);
int main()
{
//Variable declarations
char word[20],reverse[20];
int howMany;
//initialize both arrays to contain the character ' ' for(inti=0;i<20;i++) { word[i]=' '; reverse[i]=''; } //read the word
readWord(word,howMany);
//create the reverse of the original word
reverseWord(word,reverse,howMany);
// print the reversed word
cout << "Reversed word is : " ;
for(int i=0; i<20;i++)
cout << reverse[i];
cout << endl;
//output the original word
for(int i=0; i<20;i++)
cout << word[i];
//if the two words are the same, the original was a palindrome
if(palindrome(word,reverse,howMany))
cout << " is a palindrome. ";
else
cout << " is not a palindrome. ";
return 0;
} //function readWord reads in characters until ' ' and keeps count
//of how many characters were read. The first parameter is the array
//to store the word read. The second parameter is for how many characters.
void readWord(char word[],int& howMany)
{
int i=0;
howMany = 0;
cin.get(word[i]);
while((word[i] != ' ') && (i < 20))
{
howMany++;
i++;
cin.get(word[i]);
}
if(word[i] == ' ')
word[i] = ' ';
return;
}
//function reverseWord takes two character array parameters and an integer
//parameter telling how many characters are in the first array.
//The purpose of reverseWord is to copy the first array into the second
//array backwards.
void reverseWord(char word[],char reverse[],int howMany) { intj=howMany-1; for(inti=0;i<howMany;i++) { reverse[i]=words[j]; j--; } return; } //function palindrome takes two character array parameters and an integer
//parameter telling how many characters are in each array.
//The purpose of palindrome is to compare each character in the first
//array with the corresponding character in the second array and see if
//the two arrays are identical. If they are, then palindrome returns true.
//Otherwise palindrome returns false.
bool palindrome(char word[],char reverse[],int howMany)
{ boolstatus=true; for(inti=0;i<howMany;i++) if(wor[i]!=reverse[i]) { status=false; break; } returnstatus; }
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.