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
olganol [36]
3 years ago
6

Write a C++ program that determines if a given string is a palindrome. A palindrome is a word or phrase that reads the same back

ward as forward. Blank, punctuation marks and capitalization do not count in determining palindromes. Here is some examples of palindromes:
Radar
Too hot to hoot
Madam!I'm adam
Computers and Technology
1 answer:
Ostrovityanka [42]3 years ago
6 0

The cpp program to determine if the given string is palindrome, is shown below.

The program has comments at places to indicate the logic.

#include <iostream>

#include <string.h>

using namespace std;

int main() {

// string is taken as an array of characters of size 50

char str1[50];

int i, len, flag;

cout<<"Enter any string to check for palindrome"<<endl;

cin>>str1;

// length of input string is stored in variable len to be used in the loop

len = strlen(str1)-1;

for(i=0; i<=len; i++)

{

// if string is palindrome, value of flag variable is initialized to 0 else 1

   if(str1[i]==str1[len-i])

        flag = 0;

           else

                flag = 1;

}

if (flag == 0)

       cout << str1 << " is a palindrome";

   else

       cout << str1 << " is not a palindrome";      

// returns integer value since main has return type of integer  

   return 0;

}

Explanation:

The header files for input and output and string are imported.

#include <iostream>

#include <string.h>

The string is taken as an array of type char having adequate size of 50.

char str1[50];

The length of the input string is calculated as

len = strlen(str1)-1;

Within a single for loop using a single variable and the length of the string, we check whether the string is palindrome or not.

      for(i=0; i<=len; i++)

{

   if(str1[i]==str1[len-i])

        flag = 0;

            else

                flag = 1;

}

The int flag is declared but not initialized.

If the string is palindrome, the value of flag variable becomes 0. Otherwise, the value of flag variable will be initialized to 1.

Depending on the value of flag variable, the message is displayed if the input string is palindrome or not.

The above program works for all strings irrespective of special characters which may be included in the string.

The above program also works for the examples of input string given in the question.

You might be interested in
HELP FAST PLEASE
never [62]

Answer:

I am not sure can you explain a little more

7 0
2 years ago
Read 2 more answers
You are in the process of replacing the toner cartrige for a laser printer. however, you notice that toner particles have been s
makkiz [27]

Answer:

Toner vacuum

Explanation:

In the process of replacing the toner cartrige for a laser printer, whenever you notice that toner particles have been split inside the printer, what you should use to effectively remove these particles is a TONER VACUUM, it is a device specially created for that purpose, after using a toner vacuum, you can use the activated toner clothe to clean the rest, after which I will advise you to use an aerosol spry to get the best result.

8 0
3 years ago
Which functions return a logical value (TRUE or FALSE)?
Ludmilka [50]

Answer:

Functions with a boolean return type.

Explanation:

If the return type is boolean, the only possible values are true or false.

8 0
3 years ago
Which of the following is not an advantage of a flowchart?
ad-work [718]

Answer:

d) Improper documentation

Explanation:

A flowchart is a type of diagram in which it presents the flow of the work or how the process is to be followed. It is a diagram that represents an algorithm that defines step by step approach to solving the task. In this, there are various boxes that are linked with the arrows

There are various advantages like in this, there is a better communication, coding is to be done in an efficient way, system could be tested also there is a proper documentation

hence, the correct option is d

4 0
2 years ago
Which is needed for the specific task of inserting a chart into a report?
Arturiano [62]

To add charts in Access to reports, click the “Create” tab in the Ribbon. Then click the “Report Design” button in the “Reports” button group. Unlike other report controls, the chart control uses its own data source to show its data. Therefore, you can insert it into a blank, unassociated report, if desired

6 0
2 years ago
Other questions:
  • What precaution can you take while using a social networking site to prevent a data breach?
    15·1 answer
  • The buttons on a specific tab are organized into logical Ribbons. <br> T<br> F
    12·2 answers
  • How do open online courses help with independent learning? (1 point)
    13·2 answers
  • Write a program segment with a do-while loop that displays whether a user-entered integer is even or odd. The code should then a
    5·1 answer
  • If your database is in archivelog mode, how can you force an archive?
    7·1 answer
  • Write an algorithm and flowchart to calculate sum of two given numbers​
    13·1 answer
  • What is printed to the console?<br> console.log(15 % 4);<br><br> 1<br><br> 2<br><br> 3<br><br> 4
    9·1 answer
  • Including the word OR will make a search less specific.<br> O False<br> O True
    8·2 answers
  • Can someone please explain to me how the points work when you ask a question? Worth 30 points I think, I still don't know how th
    5·2 answers
  • Global visibility is: Group of answer choices A visibility type where an object A has a semi-permanent reference to another obje
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!