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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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. 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

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

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education