Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Assignment 3: Source file:

Source Code:
#include<iostream> #include<fstream> #include<conio.h> #include<string> using namespace std; int main() { getting the file name from the user string str!ile"ame#str!ile$ine#str%e&erse!ileContent; string str!ileContent'())*; int i!lag+(#iString+); cout<<,-nter the name of the te.t file:,; cin>>str!ile"ame; chec/ing the content in the file ifstream if0nput!ile; if0nput!ile.open(str!ile"ame1 ,.t.t,); error 2hile opening the file if(3if0nput!ile) cerr<<,-rror opening the file.,; reading each line of the file till it ends

2hile(3if0nput!ile.eof()) { getline(if0nput!ile#str!ile$ine); str!ileContent'iString* + str!ile$ine; iString11; 4 looping the lines in the file for(int i+);i<iString;i11) { int i$ength+str!ileContent'i*.length(); using string 5at5 function for(int 6+(;6<+i$ength;611) { if(str!ileContent'i*.at(67() 3+ str!ileContent'i*.at(i$ength76)) { i!lag+(; 8rea/; 4 else i!lag+); 4 e.iting th2e loop if it doesnt contain atleast ( palindrome 2ord if(i!lag ++ () 8rea/; 9 using string compare function str%e&erse!ileContent + ,,; for(int 6+i$ength7(;6>+);677) { str%e&erse!ileContent 1+ str!ileContent'i*.at(6); 4 i!lag+str!ileContent'i*.compare(str%e&erse!ileContent); e.iting th2e loop if it doesnt contain atleast ( palindrome 2ord if(i!lag 3+ )) 8rea/; 9 4 if(i!lag++)) { cout<<,:he content in the file is palindrome.,<<endl<<,:rue,; 4 else cout<<,:he file content is not a palindrome.,<<endl<<,!alse,; getch(); return );

-.ecution:

Choosing other source file:

;ence# m< program 2or/s 2ith space# special characters and multiple palindromes.

You might also like