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.

Step by step
Solved in 2 steps

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








