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
When computer users have trouble with their machines or software, Roland is the first person they call for help. Roland helps us
Schach [20]

Answer:

The correct answer is A) Support Analyst

Explanation:

From the question, we can see that Roland is familiar with both machines and software. He is familiar with the operations of both parts of a computer to the end that he can attempt a fix. And if he can't he knows who to refer the end-users to. Usually, some IT personnel that is more experienced.

From the above points, we can safely say that Roland is an IT Support Analyst. He cannot be the Systems analyst because Systems Analysts are usually at the top of the Pyramid. They take on problems that are referred upwards to them from support analysts.

Cheers

3 0
3 years ago
What type of editor is used to edit HTML code?What type of editor is used to edit HTML code?
Law Incorporation [45]

For learning HTML we recommend a simple text editor like Notepad (PC) or TextEdit (Mac).

mark me brainliestt :))

4 0
3 years ago
Lean production systems are sometimes referred to as pull systems because demand from customers activates the production actions
fredd [130]

Answer:

a.Kanban Pull System

Explanation:

Part of a lean manufacturing technique, is the pull system and it is a production or service oriented process used to reduce waste. A pull system is a Lean technique for reducing the waste of any production process. Using a pull system allows you to begin new work only when there is either customer demand for it or goods are required by the next step within the production process. Applying a pull system allows you to start new work only when there is a customer demand for it. This gives you the opportunity to reduce overhead and optimize storage costs.

Kanban is based on a set of principles and practices that are easy to understand. Implementing them is also fairly simple since you do not need to make any serious changes to your existing process. But it is key that you understand the methodology and stick with the core practices if you want to successfully implement a Kanban pull system.

7 0
3 years ago
Read 2 more answers
Find an example of a print or Internet ad that includes images and text, and then answer
WARRIOR [948]

4. Find an example of a print or Internet ad that includes images and text, and then answer the following questions about it.

           a. Describe the ad. (1-3 sentences. 1.0 points)

Mcdonald's all day breakfast. It shows their breakfast items, with high-quality images.

b. What do you think this ad's marketing message is? (1-5 sentences. 2.0 points) TIP: Does it use a specific desire or fear, or does it try to show how the product is a need or how it solves a problem?

They use desire because they show their delicious looking food, and the customers are wanting it.

c. Is the ad trying to get people to do something? If so, what is it trying to get people to do? If it isn't trying to get people to do something, what do you think the point of the ad is? (1-5 sentences. 2.0 points)

The ad is trying to get people to stop at Mcdonalds and buy their breakfast items

           d. Do you think this ad is effective? Why or why not? (1-5 sentences. 2.0 points)

Yes I think this ad is effective because it is showing high quality images of their breakfast items that encourage people to stop by and try their products.

3 0
3 years ago
What role does modern technology play in globalization today?
lana [24]

<span>Advances in technology are one of the main reasons that globalization has escalated in the past decade. In information and communication technology, innovations have become smaller in size, more efficient and often more affordable. In transport technology, vehicles have tended to become larger and faster, as well as becoming more environmentally friendly and cheaper to run. Whether for personal use or for business, technology has made the world seem a smaller place and assisted in the rise of globalization. </span>
6 0
3 years ago
Other questions:
  • Here are the codes for producer and consumer problems.
    10·1 answer
  • When possible, you should avoid using _________ variables in a program?
    11·1 answer
  • What is the most common way to perform searches in a search engine?
    6·1 answer
  • A large IPv4 datagram is fragmented into 4 fragments at router 1 to pass over a network with an MTU of 1500 bytes. Assume each f
    15·1 answer
  • What is the most likely cause of a print job rendering the wrong colors on the output?
    14·1 answer
  • Router 1 is configured with static NAT. Addressing on the router and the web server are correctly configured, but there is no co
    11·1 answer
  • Which statement about intellectual property is true? (CSI-7.6) Group of answer choices It is okay to use code you find on the in
    14·1 answer
  • Wendell notices that the company's top executives share a belief that managers are directly responsible for the organization's s
    13·1 answer
  • Edge is a video game featuring interactive extreme sports. The graphics used in the game are protected by
    8·1 answer
  • Data is stored on ________ using a laser to either melt the disc material or change the color of embedded dye.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!