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

Checking Palindrome Design and implement a class NumberOfPalindromes . The class

ID: 3786720 • Letter: C

Question

Checking Palindrome

Design and implement a class NumberOfPalindromes.
The class has a String data member, default and one parameter constructor, accessor (get) and mutator (set) methods for the field, getNumberOfPalindromes() method that returns the number of palindrome words in the string, and isPalindrome(String str) utility (helper – can be private) method to check in particular string is a palindrome.

Override the equals() (assume the string are equal) and toString() (returns the string and the number of palindromes) methods for the class inherited from Object class.

Design and implement a driver (client) class Driver1 to check the functionality of NumberOfPalindromes class on a string example:

Hint:
In getNumberOfPalindromes() you can split() method to find tokens (words) in a string. You can use equals() or compareTo() method to compare strings.
You can design and implement String reverseString(String str) helper (private) method for isPalindrome(String str) that returns a reverse of a string. As a String is final, consider StringDuffer or StringBuilder classes for reversing a string in place.

**Please provide specific details as to what is happening so I fully understand what is going on. Please and thank you.

Explanation / Answer

here is the program to find the total number of palidromes present in the entered string. this program initially uses the logic to find the palindrome

#include<stdio.h>

#include<conio.h>

int stpal(char str[50],int st,int ed);

void main()

{

char str[50];

int pal=0,len=0,i,start=0,end;

clrscr();

printf(" ENTER A SENTENCE..........:");

gets(str);

while(str[len]!='')

len++;

len-;

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

{

if((str[i]==' '&&str[i+1]!=' ') || i==len)

{

if(i == len)

end=i;

else

end = i-1;

if(stpal(str,start,end))

pal++;

start = end+2;

}

}

printf(" THE TOTAL NUMBER OF RANDOMES ARE..:%d",pal);

getch();

}

int stpal(char str[50],int st,int ed)

{

int i,pal=0;

for(i=0;i<=(ed-st)/2;i++)

if(str[st+i]==str[ed-i])

pal=1;

else

{

pal=0;

break;

}

}

return pal;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote