subject

Complete the program below. 1) First the user is asked to enter a word. Then the program determines whether the word is a palindrome. A palindrome is a word that is spelled the same whether begin to end or vice-versa. For example, racecar is a palindrome, whereas yellow is not (wolley backwards). /* Output Enter a word: racecar racecar is a palindrome. /* Output Enter a word: yellow yellow is not a palindrome.
2) The word is read using getline().
3) Then a for loop is used to push the word into a STL list. - With each iteration, one character is pushed into the list. - The for loop stops when the null character '\0' is encountered. Now the list holds the word. To determine whether a word is a palindrome, the first character in the list must equal the last character. Then the second letter in the list must equal the next-to-the-last character... and so on.
4) So use a loop and iterate through the list in both directions using two iterators. - Use a loop to check the first character to the last, use both iterator it, and reverse_iterator rit. it rit word. begin() word. begin() • In the first iteration, check the first character to the last character. o If they are not the same, break out of the loop. . If they are the same, progress the the second character from the front to the second character from the end. • To move the iterator it to the next character, use it++. o Likewise, to move the reverse_iterator rit to the next character (in reverse order), use rit++.
5) Use this code and then finish the program. #include #include #include using namespace std; int main() list characters; string word; Notice that we can use the subscript operator ( 1 with a string, (not just with c_strings). cout << "Enter a word: "; getline (cin, word); for (int i = 0; word[i] != '\0'; i++) characters. push_back (word[i]); // //
6) Now the list holds the word, with each node in the list holding one character. // Include code below to determine whether the word is a palindrome.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 23:10
Write a method that accepts a string object as an argument and returns the number of words it contains. for instance, if the argument is "four score and seven years ago", the method should return the number 6. demonstrate the method in a program that asks the user to input a string and then passes that string into the method, printing out whatever the method returns.
Answers: 3
question
Computers and Technology, 22.06.2019 02:00
Aisha has finished working on a word processing document that contains 15 pages. she has added some special elements in the first three pages, page 9 and 10, and page 15 from the document. she wants to print only these pages to see how they look. which option is the correct way to represent (in the print dialog box) the pages that aisha wants to print?
Answers: 3
question
Computers and Technology, 22.06.2019 14:30
What percentage of companies is projected to use social media to locate new employees in 2012
Answers: 2
question
Computers and Technology, 22.06.2019 19:50
Write a car class having two private member variables called tank and speed. write public methods called pumpgas and gofast. the method pumpgas gets an integer for gas that must be pumped. that value needs to be added to tank (no more than 20 gallons). it must return the amount of gas that is purchased ($4 per gallon). the method gofast should increase the speed by 5 each time it is called.write a constructor for the above class that initialized both variables to zero.write a tostring to display both the tank and speed when the car is printed.modify the car class to implement the interface comparable and an interface called carinter having the public methods in carinter.write the main program to create an array of size 5 of type car. create 5 car objects having each location of the array to refer to one of the cars. test the pumpgas, gofast, equals method on the array items. write an enhanced loop to print all the car values (using a tostring written last time).write a generic method to find the minimum of four items. pass int, double, char, string and car objects to test this method.
Answers: 1
You know the right answer?
Complete the program below. 1) First the user is asked to enter a word. Then the program determines...
Questions
question
Social Studies, 17.02.2021 06:40
question
Mathematics, 17.02.2021 06:40
question
History, 17.02.2021 06:40
question
Mathematics, 17.02.2021 06:40
question
Mathematics, 17.02.2021 06:40
question
History, 17.02.2021 06:40
Questions on the website: 13722367