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]
2 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]2 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
A vast global network that is made up of many smaller interconnected networks is known as:
Galina-37 [17]

The answer is The Internet.   It is a vast global network that is made up of many smaller interconnected networks. It connects to millions of computer units world wide, in which any computer can communicate with any other computer as long as they are both connected to the Internet. It also made access to information and communication easier.

6 0
3 years ago
Read 2 more answers
Types in java are divided into two categories. the primitive types are boolean, byte, char, short, int, long, float and double.
Rudik [331]
Types in java are divided into two categories. the primitive types are boolean, byte, char, short, not, long, float, and double. all other types are REFERENCE types
4 0
2 years ago
Modify the provided code file to create a workout tracking program that lets the user enter (from the console) the distance they
koban [17]

Answer:

  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3. public class Main {
  4.    public static void main(String[] args) {
  5.        Scanner input = new Scanner(System.in);
  6.        double distances [] = new double[7];
  7.        for(int i=0; i < distances.length; i++){
  8.            System.out.print("Input running distance for day " + (i+1) + ": ");
  9.            distances[i] = input.nextDouble();
  10.        }
  11.        System.out.println(Arrays.toString(distances));
  12.    }
  13. }

Explanation:

The solution code is written in Java.

Firstly, create a Scanner object to get user input for running distance (Line 6). Next, declare a distances array and set the array size to 7 because we intend to use this array to hold running distance for 7 days per week.

Next, use the for loop that run for 7 times to repeatedly prompt user to input running distance for each day and store each value to the array distances (Line 9 -12).

At last, display the array to console terminal (Line 14).

3 0
3 years ago
Which statement best describes the types of products and services that are suitable for online sale?
garri49 [273]

A statement which best describes the types of products and services that are suitable for online sale is: D. Not all products or services are well-suited for sale on the Internet.

<h3>What is e-commerce?</h3>

E-commerce is also referred to as an online sale and it can be defined as a business model which is designed and developed to involve the buying and selling of goods (products) over the Internet.

Basically, e-commerce technologies are designed and developed to comprises software and information technology (IT) systems which typically support safe and secure transactions over network and the Internet, so as to make e-commerce possible.

<h3>What is a product?</h3>

A product can be defined as any physical object (tangible item) that is typically produced by a manufacturer so as to satisfy and meet the demands, needs or wants of every customer. Some examples of a product include the following:

  • Mobile phones
  • Television
  • Microwave oven
  • Laptop

In conclusion, we can infer and logically deduce that it is not all products or services that are well-suited for sale on the Internet through e-commerce.

Read more on e-commerce here: brainly.com/question/23369154

#SPJ1

4 0
2 years ago
ENG103 DISCUSSION BOARD 6
amm1812
The proper citation for your course of study -computer related- is APA (American Psychological Association)  format. This citation format allows us to state the publication date, title , and authors in an organized and short fashion. All scholarly reports that are technology or psychology based, should be cited in APA format. 

<span>I know this because it is the format I use for all of my college courses which are all Computer/Technology related. </span>
3 0
3 years ago
Other questions:
  • Copy the 10 statements as they appear below into your journal.
    6·2 answers
  • What is master slide and tell about master slide
    6·1 answer
  • Which software product release category is "generally feature complete and supposedly bug free, and ready for use by the communi
    7·1 answer
  • What's the name of this apex legend hero​
    13·2 answers
  • Jim is in the market for a car that will last for the next 10 years and has saved up some money for the purpose of a car. What’s
    8·2 answers
  • Is there a way to earn free robux
    7·2 answers
  • The terms Apps and Applications can be used interchangeably about software installed
    8·1 answer
  • Which two statements are true about algorithms?
    15·2 answers
  • Visit on social networking site and look for the site's privacy policy.The link is typically found at the bottom of the page and
    9·1 answer
  • What color pixels are used in a camera?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!