CSE202Lab6 - Write a loop that can detect whether this...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 202 Lab 6 Instructions: The purpose of this lab is to detect whether a given string is a palindrome or not. If the string is NOT a palindrome your job is then to make it one. Definition: A palindrome is a string of text whose order can be reversed and still spell the original string. For example, racecar, is a palindrome. A longer example is: “Kay, a red nude, peeped under a yak.” (i.e. kayarednudepeepedunderayak). To do: The goal of this lab is to write a program that will request a string of text from the user and then perform the following actions. First detect whether the string is a palindrome, if it is, indicate this to the user. If the string is not a palindrome, make it one and output it to the screen, it does not matter if the new string makes no sense. A general outline for your program could be as follows: 1. Ask user for input, store this value in a string. 2.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Write a loop that can detect whether this string is a palindrome. a. If it is a palindrome, set some Boolean value to true. If it is not, set it to false. (How can you write an algorithm to do this?). 3. Use this Boolean value to either a. Indicate the string was a palindrome, output the string, exit the program. b. Make the string a palindrome by concatenating the existing string with a REVERSE copy of the same string. For example, if you are presented with “ilove202”, create the string “ilove202202evoli”. The input string will be unformatted text with no white-space or punctuation marks. e.g. racecar or kayarednudepeepedunderayak. Hints: You will need to use loops for parts 2 and 3b. You will most likely rely on the string methods “at” and “length” and the concatenation symbol “+” to complete this lab. Turn in a printed copy of your source code....
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online