COULD YOU REWRITTE THE FUNCTION ABOVE. AND BY REWRITE. I MEAN CHANGE THE FUNCTION NAME, PARAMETERS, AND ITS IMPLEMENTATION. HOWEVER, THE FUNCTION MUST STILL ACHEIVE THE SAME GOAL.
void getChar(char& c, istream& infile, int& i)
{
infile.get(c);
if (c == '\n')
i++;
}
COULD YOU REWRITTE THE FUNCTION ABOVE. AND BY REWRITE. I MEAN CHANGE THE FUNCTION NAME, PARAMETERS, AND ITS IMPLEMENTATION. HOWEVER, THE FUNCTION MUST STILL ACHEIVE THE SAME GOAL.
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Can the same thing also be done to the balance file function below
bool balanceFile(istream& infile)
{
int LineCount = 1;
stack <balancer> row;
bool found = true;
char c ;
while (infile.peek() != EOF)
{
getChar(c, infile, LineCount);
if (c == '/' && infile.peek() == '*')
{
infile.get(c);
int copy =LineCount;
getChar(c, infile,LineCount);
while ((c != '*' || infile.peek() != '/') && infile.peek() != EOF)
{
getChar(c, infile, LineCount);
}
if (infile.peek() == EOF)
{
found = false;
cout << "an unmatched /* symbol has been located on line " << copy << endl;
break;
}
cout << "pair matching /* and */" << endl;
}
else
{
if (c == '/' && infile.peek() == '/')
{
string startNew;
getline(infile, startNew);
}
}
if (c == '"' || c == '\'') {
char keep;
keep = c;
getChar(c, infile, LineCount);
while (c != keep && infile.peek() != EOF) {
getChar(c, infile, LineCount);
if (c == '\n') {
found = false;
cout << "unmatched " << keep << " symbol on line " << LineCount << endl;
break;
}
}
if (c != keep && infile.peek() == EOF && infile.peek() != '\n') {
found = false;
cout << "unmatched " << keep << " symbol on line " << LineCount << endl;
break;
}
cout << "pair matching " << keep << " and " << keep << endl;
}
if (c == '(' || c == '{' || c == '[') {
balancer b;
b.score = LineCount;
b.symbol = c;
row.push(b);
}
else if (c == ')' || c == '}' || c == ']')
{
balancer Char;
if (row.empty())
{
cout << "unmatched " << c << " symbol on line " << LineCount << endl;
found = false;
break;
}
Char = row.top();
row.pop();
if (!isMatched(Char.symbol, c))
{
found = false;
cout << "unmatched " << Char.symbol << " symbol on line " << Char.score << endl;
break;
}
else
cout << "pair matching " << Char.symbol << " and " << c << endl;
}
}
if (!row.empty() && found == true) {
cout << "unmatched " << row.top().symbol << " symbol on line " << row.top().score << endl;
found = false;
}
return found;
}
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)