Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include using namespace std; string xml(string shuru); int main() { string input; cout < < Enter the input < < endl; getline(cin, input);

#include

#include #include using namespace std; string xml(string shuru); int main() { string input; cout << "Enter the input" << endl; getline(cin, input); cout << "Output:" < } string xml(string shuru) { char token ,topToken; stackopStack; string out; const string BLANK = " "; for (int i = 0; i < opStack.size(); i++) { token = shuru[i]; switch (token) { case '<': opStack.push(token); break; case '>': for (;;) { if (!opStack.empty()) { topToken = opStack.top(); opStack.pop(); if (topToken == '<') break; out.append(BLANK + topToken); } } break; case ' default: for (;;) { if (!isalnum(shuru[i + 1])) break; i++; token = shuru[i]; out.append(1, token); } } } return out; } Help me fix this code(C++) so it can: 1. Readthe input until the beginning of a tag is detected. (i.e. tagsbegin with <: if the next character is a / (slash), then it isan end-tag; otherwise it is a start-tag). 2. Readthe tag's identity. (e.g. both tags and havethe same identity: 'x'). 3. Ifthe tag was a start-tag, push it onto the Stack. 4.Otherwise, it is an end-tag. In this case, pop the Stack (whichcontains a previously pushed start-tag identity) and verify thatthe popped identity is the same as the the end-tag just processed.Note: if the stack cannot be popped (because it isempty), the input is invalid; the algorithm should STOP. 5. Ifthe identities do not match, the XML expression isinvalid. STOP. 6. Ifthey do match, then no error has been detected (yet!). 7. Ifthere is still input that has not yet been processed, go back tothe first step. 8. Otherwise (no moreinput) then the input is valid unless the Stack isnot empty. Indicate whether theinput is valid (Stack empty) or invalid and STOP.

Example of XML tags: XML

Valid?

Explanation

Yes

"a" tags balance

Yes

"a" outer tags and "b" inner tags balance

No

"a" end-tags does not match start-tag ("b")

Yes

all tags balance

No

"Baker" end-tag does not matchstart-tag ("baker") (i.e. the tag names arecase-sensitive.)

My code doesn't have any output.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions