Answer to Question #309694 in C++ for Rohit

Question #309694

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

1
Expert's answer
2022-03-11T07:24:23-0500


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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment