Ds 9
Ds 9
Nisha Kadam
Department : Computer
Engineering
Class : SE C
Roll No. : 75
Subject : Fundamentals of Data
Structure
---------------------------------------------------------------------------------------------------------------
Assignment – 9
PROBLEM STATEMENT:-
A palindrome is a string of character that‘s the same forward and backward. Typically, punctuation,
capitalization, and spaces are ignored. For example, ‖Poor Dan is in a droop‖ is a palindrome, as can be
seen by examining the characters ―poor danisina droop‖ and observing that they are the same forward
and backward. One way to check for a palindrome is to reverse the characters in the string and then
compare with them the original- in a palindrome, the sequence will be identical. Write C++ program with
functions1. To check whether given string is palindrome or not that uses a stack to determine whether a
string is a palindrome. 2. To remove spaces and punctuation in string, convert all the Characters to
lowercase, and then call above Palindrome checking function to check for a palindrome 3. To print string in
----------------------------------------------------------------------------------------
PROGRAM:-
#include<iostream>
#include<string.h>
#define max 30
using namespace std;
class MYSTACK
{
private:
char a[max];
int top;
public:
MYSTACK()
{
top=-1;
}
void push(char);
void reverse_string();
void convert(char[]);
void palindrome();
};
void MYSTACK::push(char c)
{
top++;
a[top] = c;
a[top+1]='\0';
}
void MYSTACK::reverse_string()
{
char str[max];
cout<<endl;
}
//ASCII a to z = 97 to 122 , A to Z = 65 to 90
void MYSTACK::convert(char str[])
{
int j,k,len = strlen(str);
k++;
}
}
str[k]='\0';
void MYSTACK::palindrome()
{
char str[max];
int i,j;
int main()
{
MYSTACK stack;
char str[max];
int i=0;
cin.getline(str , 50);
stack.convert(str);
while(str[i] != '\0')
{
stack.push(str[i]);
i++;
}
stack.palindrome();
stack.reverse_string();
OUTPUT :-
(base) tpo@tpo-Vostro-3902:~$ cd SECOC75
(base) tpo@tpo-Vostro3902:~/SECOC75$
g++ i.cpp
(base) tpo@tpo-Vostro-3902:~/SECOC75$ ./a.out