Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a program that will determine if an inputted c-string is a palindrome or

ID: 3565125 • Letter: C

Question

create a program that will determine if an inputted c-string is a palindrome or not. In main, the user will input a c-string into a character array and send to user-defined functions.

This c-string will be sent to a function that will remove all spaces and punctuation marks from its c-string as well as change any uppercase letters to lowercase. Use string tokens to eliminate the spaces & punctuation marks. Make sure you include the NULL as you concatenate the tokens into a c-string. Then copy back into the original c-string for the pass by reference.

Back in main, you will then send the c-string to a function that will see if it is really a palindrome or not. You will need to create another c-string (that contains the ) that is filled up as the reverse of the argument c-string. Then check to see if the c-string is a palindrome and return the boolean result.

Back in main, print the c-string (now in all lowercase and without the spaces and punctuation marks) and tell whether it is a palindrome or not.

Include Comments if you can.

Explanation / Answer

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

void removeSpaces(char str[]){
int i = 0,j=0;
char temp[100];
while(str[i] != ''){
if(str[i] >= 97 && str[i] <= 122){
temp[j] = str[i];
j++;
}
if(str[i] >= 65 && str[i] <= 90 ){
temp[j] = str[i] + 32;
j++;
}
i++;
}
temp[j] = '';
i = 0;
while(temp[i] != ''){
str[i] = temp[i];
i++;
}
str[i] = '';
}

bool checkPalindrome(char str[]){
int length = strlen(str);
char rev[100];
int flag = 1;
int i;
for(i=0; i<length; i++){
rev[i] = str[length-i-1];
}
rev[i] = '';

for(int i=0; i<length; i++){
if(str[i] != rev[i]){
flag = 0;
break;
}
}

if(flag == 1){
return true;
}
else{
return false;
}
}

int main(){
char str[100];

cout << "Input a string : ";
gets(str); //TAke input

removeSpaces(str); //Removes spaces and puntuation And convert upper cases to lower cases

bool flag = checkPalindrome(str); // Checks for palindrome

if(flag == true){
cout << str << " is a Palindrome" << endl;
}else{
cout << str << " is not a Palindrome" << endl;
}

return 0;
}