Write a program to do the following tak
Four Strings are accepted through command line arguments.
Each string is passed to a function inPalindrome) that checks whether the string is a palindume or net and retums true or falser accordingly
If the string is a palindroene it is stored in a text file named "Palindrome.txt"
and print a user friendly message on console also
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool isPalindrome(string inputString){
string reverseString="";
for(int j=inputString.length()-1;j>=0;j--){
reverseString+=inputString[j];
}
return inputString.compare(reverseString)==0;
}
int main(int argc, char *argv[]) {
if(argc>0){
ofstream palindromeFile;
palindromeFile.open("Palindrome.txt");
for(int i=0;i<argc;i++){
if(isPalindrome(argv[i])){
cout<<argv[i]<<" is palindrome\n";
palindromeFile<<argv[i]<<"\n";
}else{
cout<<argv[i]<<" is NOT palindrome\n";
}
}
palindromeFile.close();
}else{
cout<<"No words\n\n";
}
system("pause");
return 0;
}
Comments
Leave a comment