0% found this document useful (0 votes)
44 views

Source PDF

This C++ program reads words from a text file, counts the total words, and determines how many words are palindromes and how many are not. It uses a stack to reverse each word and check if it is equal to the original, returning 1 if it is a palindrome and 0 if not. It outputs the total word count and counts of palindrome and non-palindrome words.

Uploaded by

mexiwe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Source PDF

This C++ program reads words from a text file, counts the total words, and determines how many words are palindromes and how many are not. It uses a stack to reverse each word and check if it is equal to the original, returning 1 if it is a palindrome and 0 if not. It outputs the total word count and counts of palindrome and non-palindrome words.

Uploaded by

mexiwe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1

#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";
}

You might also like