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
Discuss how the user-designer communications gap can cause a good project to go bad.
Mila [183]
This gap between user-designer communications <span>can cause a good project to go bad i</span>f the user is not able to process what is required to be fixed in order for the project to run smoothly. The user may have one way of fixing something while the designer has another. In this case, the designer understands how the project fully works while the user does not and this may end up compromising the whole project.

The law that “designers are not users” and “users are not designers” should always be followed.




3 0
3 years ago
As a member of the accounting group,
Anastasy [175]

Answer:

rtg

Explanation:

rth

3 0
3 years ago
On a wireless router, what gives out IP addresses?<br> DHCP<br> DNS<br> WPA<br> WPS
attashe74 [19]

Answer:

DHCP

Explanation:

The only option can give IP addresses is the DHCP The Dynamic Host Configuration Protocol, because the DNS (Domain Name System) only translates IP addresses to a hostname, and WPS (Wi-Fi Protected Setup) or WPA (Wi-Fi Protected Access) if for security network, doesn't matter if is a wireless router, in a network always DHCP gives the IP addresses.

7 0
2 years ago
What is the dividend rate for ibm stock?
Vaselesa [24]
3.28% I think 
......................................................................................................................................
5 0
3 years ago
Briefly describe the function of storage media
SIZIF [17.4K]

Answer:

In computers, a storage medium is any technology -- including devices and materials -- used to place, keep and retrieve electronic data. It refers to a physical device or component in a computing system that receives and retains information relating to applications and users. The plural form of this term is storage media.

Early forms of storage media included computer paper tape. Holes punched in the paper corresponded to a single bit of data. A paper tape reader would interpret each punched hole and convert it to a number. Paper tape was supplanted by magnetic tape, which eventually evolved to magnetic floppy disk.

How storage media works:

Media used in computer storage receive messages in the form of data, via software commands from the computer system. The commands determine the type of storage media needed to hold the data, based on its business value, compliance implications or other factors. In tiered storage, data is moved among disk, flash and cloud storage based on automated software policies.

A storage medium may be internal to a computing device, such as a computer's hard drive, or a removable device such as an external hard drive or universal serial bus (USB) flash drive. There are various types of storage media, including magnetic tape, nonvolatile memory cards, rotating fixed disk and solid-state drives (SSDs), which are based on nonvolatile flash memory.

The term storage encompasses all data, and can be either primary or secondary storage. Primary storage refers to data that is kept in memory for fast retrieval by a computer's processor. Secondary storage is data placed on hard disk or tape to ensure backup and long-term retention.

A storage device may be a type of storage media, or a piece of storage hardware outfitted with storage media. For example, storage arrays decouple storage media from servers. Storage arrays incorporate electromechanical hard disk drives (HDDs), SSDs or a combination of each, attached to separate servers and networking.

Storage media can be arranged for access in many ways. Some well-known arrangements include:

redundant array of independent disks (RAID);

network-attached storage (NAS); and

storage area network (SAN).

SAN arrays initially were designed with HDDs, until the advent of all-flash arrays outfitted solely with SSDs. Hybrid flash arrays blend the two storage media in an integrated system, with disk providing a capacity tier alongside a faster tier of flash.

Explanation:

please mark me as brainliest

4 0
2 years ago
Other questions:
  • A Hierarchy Custom Setting stores a specific URL for each profile in Salesforce. Which statement can a developer use to retrieve
    5·1 answer
  • Which of the following patterns of cell phone use can be observed in this chart
    12·1 answer
  • Which of the following describes ETL? a) A process that transforms information using a common set of enterprise definitions b) A
    14·1 answer
  • A shortage of blood for transfusions for injured animals has resulted in the introduction of a synthesized product called Oxyglo
    15·1 answer
  • What is your favourite video game??​
    5·2 answers
  • ________ was one of the first uses of the Internet
    15·2 answers
  • What is a mod in programming?<br><br> Give more Java questions
    12·1 answer
  • When you ____ an exception, you send a message that an error has occurred to another part of the program.
    7·2 answers
  • Meta is a penetration testing engineer assigned to pen test the security firm's network. So far, she cannot tunnel through the n
    12·1 answer
  • So I tried asking for help with my code on stackoverflow but the people there were very condescending and mean plus my questions
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!