1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ikadub [295]
3 years ago
6

Write a bool function isPalindrome that takes one string parameter and returns true if that string is a palindrome and false oth

erwise. c++

Computers and Technology
1 answer:
kkurt [141]3 years ago
7 0

Answer:

Here is the bool function isPalindrome:

bool isPalindrome(string s)

{  bool palindrome;      

 int j;

 int len = s.length();

 for (int i =0, j= len-1; i < len/2; i++, j--)  

   if (s[i] == s[j])

     palindrome = true;  

   else

     palindrome = false;

 return palindrome; }

Explanation:

The bool function isPalindrome takes a string as parameter and returns true if the string is a palindrome or false if the string is not palindrome. The string variable s holds the string value. In function isPalindrome, there is a bool type variable palindrome. bool is a data type which is used to hold values true or false which is then stored in the palindrome variable.

Next it is being found that how many characters are there in the input string using length() function which returns the length of the string. The length of the string is stored in int type variable len.

Next the for loop starts which has two variables i and j where i starts at 0 position of the input string and j starts at the last position of the string. These two variables move or traverse along the string this way. i variable stops when half the length of the input string is reached. At the end of every iteration i moves forward by the increment of its value to 1 and j moves backwards by the decrement  of its value to 1.

Every the body of  the loop executes, there is an if condition in the body of the loop which checks if the string is a palindrome. This is checked by matching the character at position/index i with the character at position j of the string. This will continue character by character until the i reached half the length of the input string and if every character in i was matched to every character in j then palindrome = true; statement is executed which returns true as the string is a palindrome otherwise palindrome = false; is returned as the string is not a palindrome.

For taking input string from the user and to check if the function isPalindrome() works correctly a main() function is written which takes input string from the user and reads in variable str calls isPalindrome() function. If the string is palindrome then the cout statement in main() function prints the message: String is a palindrome and if the input string is not a palindrome the the following message is displayed in the output screen: String is not a palindrome

int main()

{

string str;

cout<<"Enter a string: ";

cin>>str;

if(isPalindrome(str))

cout<<"String is a palindrome";

else

cout<<"String is not a palindrome";

}

The screenshot of the program along with the output is attached.

You might be interested in
Data mining requires specialized data analysts to ask ad hoc questions and obtain answers quickly from the system. select one: t
rjkz [21]

Specialized data analysts are needed for data mining in order to ask ad hoc inquiries and swiftly get responses from the system. choose one. This claim is false.

<h3>What does data mining mean exactly?</h3>
  • Large data sets are sorted through in data mining in order to find patterns and relationships that may be used in data analysis to assist solve business challenges.
  • Enterprises can forecast future trends and make more educated business decisions thanks to data mining techniques and technologies.
  • Increasingly huge databases are explored via data mining, which also helps market segmentation.
  • It is feasible to predict a customer's behavior to guide personalized loyalty marketing by analyzing the links between criteria like their age, gender, and preferences.

To learn more about Data mining, refer to:

brainly.com/question/2596411

#SPJ4

5 0
2 years ago
What is done when Python complies your program
alexgriva [62]

Answer:

It makes

Explanation:

it run the program

4 0
3 years ago
Read 2 more answers
_______ allows you to add formatting such as shapes and colors to text. a. worddraw b. wordart c. worddesign d. wordshapes
4vir4ik [10]
Word Design is the answer.
4 0
3 years ago
Read 2 more answers
What are the differences between packet and circuit switching? Which is more prevalent today?
Juliette [100K]

Answer: The difference present between the packet switching and circuit switching are as follows:-

  • Packet switching i the switching in which the data packet travels through the connectionless path whereas connection oriented routes are present for circuit switching
  • Network layer uses the feature of packet switching while physical layer uses circuit switching technique
  • Data transferring is mostly preferred through packet switching and voice communication takes place through the circuit switching.
  • Packet switching is considered flexible as no already established connection is present for switching but the connection in circuit switching are already defined which makes it less flexible.

Among the packet switching and circuit switching , packet switching is preferred for the communication through the data packets because they have  flexibility and affordability.It can establish numerous connection for switching and this make it efficient.

4 0
3 years ago
During a move, employee workstations were disconnected from the network and reconnected in new offices. However, after the move
Troyanec [42]

Answer:

Make sure the cables are functional and properly plugged.

Explanation:

For the fact that everything was working perfectly before the move, but after the move, it was noticed that a few workstations cannot get a valid IP, the first thing that is required to be checked is to ensure that the cables are properly plugged, and if they are, make sure that you test for the functionality of the cables. It is only after these checks and the problem persist, that further troubleshooting is required.

5 0
3 years ago
Other questions:
  • Adam is evaluating the security of a web server before it goes live. He believes that an issue in the code allows an SQL injecti
    5·1 answer
  • Jamal is creating a presentation for a report on engineers. He wants to use a template. How can he access different options for
    14·1 answer
  • What are the two most popular applications of theInternet?
    7·1 answer
  • ________ is used by text recognition software to convert typed, printed, or handwritten text into the computer-based characters
    15·1 answer
  • Which do switches create?<br> Networks<br> Wireless access points<br> Routes<br> Collision domains
    13·1 answer
  • A gas furnace has an efficiency of 75% . How many BTU will it produce from 1000 BTU of natural gas​
    14·2 answers
  • The best way to safeguard your document is to save it
    11·1 answer
  • What are the functions of super computer?<br> ​
    7·2 answers
  • Provide the user with a menu for the following 10 algorithms. Then ask which algorithm the user decides she/he wants to use. Fin
    9·1 answer
  • What refers to a set of instructions executed in order?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!