bartleby

Videos

Textbook Question
Book Icon
Chapter 9, Problem 3P

Palindrome testing with pointers

This Practice Program requires that you read the optional section about pointer arithmetic. Complete the function isPalindrome so that it returns true if the string cstr is a palindrome (the same backwards as forwards) and false if it is not. The function uses the cstring library.

bool isPalindrome(char* cstr)

{

char* front = cstr;

char* back = cstr + strlen(cstr)−1;

while (front < back)

{

// Complete code here

}

return true;

}

 Here is a sample main function for quick and dirty testing:

int main()

{

char s1[50] = "neveroddoreven";

char s2[50] = "not a palindrome";

cout << isPalindrome(s1) << endl; // true

cout << isPalindrome(s2) << endl; // false

return 0;

}

Blurred answer
Students have asked these similar questions
Shared pointers keep a count of all of the shared pointers that appear in the program code.  True  False
Topic: pointers, dynamic array and command line arguments Write a complete C++ program named “showHelp” that accepts command line arguments. It checks whether there is a command line argument of “/help” or“/?” or “-help” followed by a topic number.  It will print out “yes, topic number(<number>) if there is one. Otherwise, it prints out “no, topic number(N/A)  For example, if you run this program with correct arguments as follows, it willprint out yes and its associated topic number respectivelyshowHelp /? 101showHelp /debug /help 102showHelp /print /help 103 /verboseshowHelp -verbose -debug -help And if you run the program with invalid arguments, it will print no, in all casesshowHelp -helpshowHelp 101 /?showHelp 101 102 /help /verboseshowHelp /? /help -helpNote: command line arguments are simply an array of pointers to C-string.   example code: #include <iostream> using namespace std;   int main(int argc, char** argv){...}
3. Pointers – Arrays: initializing content • Using the pointer ptrArray, you now want to write values in those integers. Use a loop to go through each element in that array, and initialize them all to 42. This is done in the main. 4. Pointers – Arrays: printing • Write a function that will print the elements in the array-pointer. The function should accept a pointer to an integer, and the size of this array. The function should not return anything. Here is your function prototype: void printArray(int* ptr, int nb); • Your function needs to use a loop to go through all the elements in the array, and simply prints them on a new line. • In the main function, call this function with your pointer ptrArray and the size given by the user.

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License