-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment9.cpp
150 lines (129 loc) · 2.22 KB
/
assignment9.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#DSL assignment no.9
using namespace std;
class stack
{
char s[25];
int top;
public:
stack()
{
top=-1;
}
void push(char val);
char pop();
int isfull();
int isempty();
};
class str
{
char inputstr[25], revstr[25];
stack stobj;
public:
void readstring();
void revstring();
void convertstring();
void checkpalindrome();
};
int stack::isempty()
{
if(top==-1)
return 1;
else
return 0;
}
int stack::isfull()
{
if(top==24)
return 1;
else
return 0;
}
void stack::push(char val)
{
if(!isfull())
{
top++;
s[top]=val;
}
else
cout<<endl<<"stack overflows/full......"<<endl;
}
char stack::pop()
{
char val='\0';
if(!isempty())
{
val=s[top];
top--;
}
else
cout<<endl<<"stack underflow/empty......"<<endl;
return val;
}
void str::readstring()
{
cout<<"\nEnter string ";
gets(inputstr);
cout<<"\nYou entered:-> "<<inputstr;
}
#
void str::revstring()
{
int i;
char ch;
for(i=0;inputstr[i]!='\0';i++)
{
stobj.push(inputstr[i]);
}
i=0;
cout<<"\n\nAfter reverse your string:-> ";
while(!stobj.isempty())
{
ch=stobj.pop();
cout<<ch;
revstr[i]=ch;
i++;
}
}
void str::convertstring()
{
int i,j=0;
char tempstr[25];
for(i=0;inputstr[i]!='\0';i++)
{
if(inputstr[i]>=97 && inputstr[i]<=122)
{
tempstr[j]=inputstr[i];
j++;
}
else if(inputstr[i]>=65 && inputstr[i]<=90)
{
tempstr[j]=inputstr[i]+32;
j++;
}
}
tempstr[j]='\0';
strcpy(inputstr,tempstr);
cout<<"\n\nYour converted string:-> "<<inputstr;
}
void str::checkpalindrome()
{
cout<<"\n\n\n\n\n";
cout<<"\nCheck for palindrome"<<endl;
readstring();
convertstring();
revstring();
if(strcmp(inputstr,revstr)==0)
cout<<"\n\nYour string is PALINDROME";
else
cout<<"\n\nYour string is NOT PALINDROME";
}
int main()
{
str obj;
obj.readstring();
obj.convertstring();
obj.revstring();
obj.checkpalindrome();
return 0;
}