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
Mohammed’s parents learn that his classmates have begun sending him text messages making fun of his heritage. Mohammed says he’s
pychu [463]

Answer:

Mohammed doesn't believe the cyberbullying exists.

Explanation:

If he knew he wouldn't say they are teasing him. I mean, how would their parents know he is being cyberbullied without evidence? Text messages(such as imessages) are most likely on phones, and not on computers.(Unless its an mac I believe.) And they are bullying him; its not using technology positively.

7 0
3 years ago
Read 2 more answers
Define the role of websites in internet.also write the importance of internet in our daily life.
BabaBlast [244]

Answer:

       

      <u> </u><u>Role of websites in internet</u>

  • Websites give the online way to the business,it helps the business to grow and reach the higher audience. There was a time,at which there is no apps only HTML/CSS websites are there so it is a building step for reaching the audience.
  • Time is a one of the major factors for growth in online sector, and websites provide a interface to use their resources and services at less time ,you don't have to go somewhere now you can order from anywhere and anytime. 24/7 hour services gives a boost to the websites.
  • Some of the Applications are Very big but you can access them in very less amount of internet. Apps never replace websites.
  • Most of the billionaires are the ones who builds there website like amazon, twitter etc. It is very important to have a website for the business        

        <u>Importance of internet in our daily life</u>

  • Internet provides various resources and services which we need at every time like booking a cab,hotel,flight,trains and tutoring services . It consist a vast variety of information which is required at every moment .
  • We really don't need any physical presence of someone to learn something , to understand or for asking it is enough up on internet. Things are changing as technology grows.
  • For leisure time, it provide social sites to enjoy and there are much good options to ask the question of any subject.      
  • It also give option to promote business , it helps to reach to higher audience, many companies give services to us as there business. Digital marketing is also up there to promote on social sites.
3 0
3 years ago
Insert XXX to output the student's ID. public class Student { private double myGPA; private int myID; public getID) { return myI
Aleonysh [2.5K]

Answer:

Explanation:

The question above is missing many details and are actually various questions in one. I will answer each one seperately below...

A. The piece of code to get the ID in this code snippet that needs to replace XXX would be the following ... System.out.println("Student ID: " + s.getID());

B. A static main() can declare and create objects. Once these objects are created their instance methods can then be called.

C. Integer score1 = 72;

    int score2 = 85;

    Character grade = 'C';

     In the above code snippet, the information stored in score1, score2, and grade are the following... obj reference, 85, obj reference. This is becasue both Integer and Character are classes and the values being passed to their variables are referencing that object class, while score2 is a primitive type of int and is therefore simply a number.

D. The statement that is true is ... Contents of a Double instance can be modified after initialization. Objects can be modified by calling its setter methods after initializing it.

7 0
2 years ago
When listing columns in the select list, what should you use to separate the columns?
Gala2k [10]
The answer is commas.  <span>When listing columns in the select list, commas should be used to separate the columns.</span>
6 0
3 years ago
________ is a markup language that allows for tagging selected elements of the content of documents for their meanings and is us
trasher [3.6K]

Answer:

E)nXML

Explanation:

XML is a short for Extensible Markup Language. It is a markup language like the Hypertext markup language (HTML) and are both used in the development of web applications. However while the HTML describes the content of the Web page that is the graphics, images and videos and how they are displayed, the XML handles the description of data and information formats, their storage and the transportation and sharing over the internet.

4 0
3 years ago
Read 2 more answers
Other questions:
  • A ____ document identifies the purpose of the program being developed, the application title, the procedures to be followed when
    11·1 answer
  • 8) Which of the following statements is FALSE?
    14·1 answer
  • What aspect of web design is Gloria following when she uses the same color scheme throughout a web page?
    12·1 answer
  • Tony is in charge of all presentations for a Fortune 500 pharmaceutical company. In addition to creating powerful and persuasive
    9·1 answer
  • To print data sideways on a piece of paper, use the _______ page orientation setting.
    6·2 answers
  • How does this app work?
    11·2 answers
  • What is the correct process for selecting an entire row in a spreadsheet?
    8·2 answers
  • Which are two main areas of the properties inspector
    7·1 answer
  • PLEASE HURRY!!!!<br> Look at the image below
    8·1 answer
  • Which statement best describes the computers all around us?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!