Source PDF
Source PDF
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<String>
#include"Header.h"
using namespace std;
string isPalindrome(string);
void main()
{
Stack ob;
string read;
int countWords=0;
int countPalindrome = 0, countNotPalindrome = 0;
ifstream infile;
infile.open("C://Users// M Mohsin Sajjad //Desktop//read.txt");
while (!infile.eof())
{
infile >> read;
countWords++;
if (isPalindrome(read) == "1")
{
countPalindrome++;
}
else
{
countNotPalindrome++;
}
}
infile.close();
cout << "No. of total Words :" << countWords<<endl;
cout <<"NO.Total Words Which are Palindrome:"<< countPalindrome << endl;
cout << "NO.Total Words Which are Not Palindrome:" << countNotPalindrome << endl;
system("pause");
}
string isPalindrome(string read)
{
Stack ob;
int size = read.length();
char temp[100] = { 0 };
for (int i = 0; i < size; i++)
{
ob.push(read[i]);
}
for (int i = 0; i <size; i++)
{
temp[i]= ob.pop();
}
string reverse(temp);
if (read == reverse)
{
return "1";
}
else
{
return "0";
}