Question

Write a program that reads each word from A1.txt and check if its a palindrome or not. Show your output in the file Bl.txt.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// header file for basic input output
#include <iostream>
// header file for string manupulation
#include <string.h>
// header file for file manipulation
#include <bits/stdc++.h>

using namespace std;

int main(){
// variable for word
char arraystr[100];
int length,i;
fstream file,file1;
// opening file in read mode
file.open("A1.txt",ios::in);
// checking wheather file exist or not
if(!file)
{
cout<<"Error in opening file!!!";
return 0;
}
// opening file i write mode
file1.open("B1.txt",ios::out);
// checking wheather file is created or not
if(!file1)
{
cout<<"Error in creating file!!!";
return 0;
}
// reading word from the file in arraystr variable
while(file>>arraystr)
{   
// variable to check the palindrome word
int flag = 0;
// finding the length of the word recorded
length = strlen(arraystr);
// loop to check whether string is pallindrome or not
for(i=0;i< length;i++){
if(arraystr[i] != arraystr[length-i-1]){
flag = 1;
break;
}
}
// checking the flag value for palindrome word and writing the output in B1.txt file
if(flag)
file1 << "No\n";
else
file1 << "Yes\n";
}
// closing the files
file.close();
file1.close();
return 0;
}

root@kali:-/Desktop/codes/temp# ls A1.txt palindrome.cpp root@kali:-/Desktop/codes/temp# cat A1.txt series madamroot@kali:-/D

In the output I have show that, at first there are just two file exists A1.txt and palindrome.txt and the content of A1.txt is series and madam. After executing the program, a new file B1.txt is creating other than palindrome binary file and content of that file is No Yes as shown in the sample code.

Add a comment
Know the answer?
Add Answer to:
Write a program that reads each word from A1.txt and check if it's a palindrome or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A palindrome is a word, phrase, number, or other sequence of characters which reads the same...

    A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar. Write a recursive method in java that accepts a integer as its argument and returns true if it is palindrome, false otherwise. public class Recursion {                 public static void main(String[] args) {                                 Recursion r = new Recursion();                                 System.out.println(“Is 12321 a palindrome? “+ra.isPalindrome(12321)); //true                 }                 public Boolean isPalindrome(int num){                                 return false;...

  • A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,...

    A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. In this program, ask the user to input some text and print out whether or not that text is a palindrome. Create the Boolean method isPalindrome which determines if a String is a palindrome, which means it is the same forwards and backwards. It should return a boolean of whether or not it was a palindrome. Create the method reverse...

  • This is a java question A palindrome is a word or phrase that reads the same...

    This is a java question A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks and punctuations, and considering uppercase and lowercase versions of the same letter to be equal. For example, the following are palindromes: warts n straw radar Able was I ere I saw Elba tacocat Write a program named Palindrome.java that will accept a file (file name) from the command argument list and decide whether each line in the file is...

  • C++ Programming Palindrome Detector: A palindrome is any word, phrase, or sentence that reads the same...

    C++ Programming Palindrome Detector: A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man,a plan, a canal, Panama Desserts, I stressed Kayak Write a book function that uses recursion to determine if a string argument is a palindrome. The function should return true if the argument reads the same forward and backward. Demonstrate the function in a program, which continues to...

  • TASK Your task is to build a palindrome from an input string. A palindrome is a...

    TASK Your task is to build a palindrome from an input string. A palindrome is a word that reads the same backward or forward. Your code will take the first 5 characters of the user input, and create a 9- character palindrome from it. Words shorter than 5 characters will result in a runtime error when you run your code. This is acceptable for this exercise – we will cover input validation in a later class. Some examples of input...

  • A palindrome is a sequence of characters that reads the same backward as forward. For example,...

    A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it's a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

  • Write a program palind.c that reads a message, then checks whether it's palindrome (the letters in...

    Write a program palind.c that reads a message, then checks whether it's palindrome (the letters in the message are the same from left to right as from right to left): Enter a message He lived as a devil, eh? Palindrome Enter a message Madam, I am Adam Not a palindrome Ignore all characters that aren't letters. Use integer variables to keep track of positions in the array. Revise the program in Part I to use a pointer instead of an...

  • please explain the answer A sequence of characters is called a palindrome if it reads the...

    please explain the answer A sequence of characters is called a palindrome if it reads the same way forward or backward. For example, 59AA95 is a six-character palindrome, and 59A95 is a five-character palindrome. Some other instances of palindromes: U NU, LON NOL, MALAYALAM, NOW ON, PUT UP, TOO HOT TO HOOT, NEVER ODD OR EVEN, ABLE WAS I ERE I SAW ELBA, and POOR DAN IS IN A DROOP. Find the number of nine-character palindromes that can be formed...

  • C++ A palindrome is a string that reads the same backward as forward. For example, the...

    C++ A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string class. The Pstring class adds a member functionbool isPalindrome( )that determines whether the string is a palindrome. Include a constructor that takes an STL string object as parameter and passes it to the string base class constructor. Test your class by having a main...

  • Problem 1. A palindrome is a sequence of characters that reads the same backward as forward....

    Problem 1. A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value. Problem 2. Modify the program to determine whether a seven-digit number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT