Question: I need help with this C++ code (need to add a loop): It basically needs to output what's in the out.txt and out2.txt files, as

I need help with this C++ code (need to add a loop): It basically needs to output what's in the out.txt and out2.txt files, as shown in the sample output, but it only outputs the first line. Please help.

DriverPalindrom.cpp

#include #include #include #include #include

using namespace std;

istream& getline_portable(istream& is, string& str) {

istream& ris = std::getline(is, str);

if (str.size() && str[str.size() - 1] == ' ')

str.resize(str.size() - 1);

return ris;

}

int main()

{

ifstream fin;

ofstream fout;

string fileNameI, fileNameO;

const string endOfData = "end";

cout << "Enter input and output fileNames: ";

cin >> fileNameI >> fileNameO;

fin.open(fileNameI.c_str());

fout.open(fileNameO.c_str());

stack s;

queue q;

char c, choice;

string str;

string ignoreSpaces;

int i = 0;

int count = 0;

getline_portable(fin, ignoreSpaces);

cout << "Ignore spaces? y/n ";

cin >> choice;

bool a = true;

cin.ignore();

getline_portable(fin, str);

int len = str.size();

/*

* LOOP (recall PA1)

* use stack s and queue q

cout<<"Inputed line {"<

fout<<"Inputed line {"<

OR

cout<<"Inputed line {"<

fout<<"Inputed line {"<

}

*/

if (choice == 'n')

{

for (int j = 0; j < str.size(); j++)

{

c = str[j];

q.push(c);

s.push(c);

}

}

else if (choice == 'y')

{

for (int j = 0; j < str.size()-count; j++)

{

c = str[j];

if (isspace(c))

{

}

else if (!isspace(c))

{

q.push(c);

s.push(c);

}

}

}

do

{

if (q.front() != s.top())

{

i = false;

break;

}

else

{

i = true;

s.pop();

q.pop();

}

} while (!q.empty() && !s.empty());

if (i == true)

{

cout << "Inputed line {" << str << "} is a palindrome ";

fout << "Inputed line {" << str << "} is a palindrome ";

}

else

cout << "Inputed line {" << str << "} is not a palindrome ";

fout << "Inputed line {" << str << "} is not a palindrome ";

fin.close();

fout.close();

system ("pause");

}

Input and output files: https://drive.google.com/drive/folders/1qFa9UanRYMfM8GoIRy9px5kpjOq_i5sG?ogsrc=32

input file in.txt corresponds output file out.txt

input file in2.txt corresponds output file out2.txt

Sample Output:

enter input and output fileNames: in.txt out.txt

ignore spaces = y

Inputed line {abba} is a palindrome

Inputed line {ab bA} is a palindrome

Inputed line {An N a} is a palindrome

Inputed line {An NA} is a palindrome

Inputed line {helicoptor} is not a palindrome

Inputed line {something very important} is not a palindrome

OR

enter input and output fileNames: in2.txt out2.txt

ignore spaces = n

Inputed line {abba} is a palindrome

Inputed line {ab bA} is a palindrome

Inputed line {An N a} is not a palindrome

Inputed line {An NA} is a palindrome

Inputed line {helicoptor} is not a palindrome

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!