Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In class this week, we will develop a Stack class and a Queue class. Use these c

ID: 3546376 • Letter: I

Question

In class this week, we will develop a Stack class and a Queue class. Use these classes to implement

an HTML balanced tag checker. Your assignment is to write a program that prompts the user for an

.html file name, opens the file and scans it to ensure that each start tag has a matching end tag.

This is a simple html file with properly matched tags. The opening tag and closing tag match by name,

with the closing tag beginning with a /.

<html>

<body>

This is my first web page

</body>

</html>

? It is acceptable for tags to be nested.

? To make the assignment more manageable, we will assume that each tag must be opened and closed

(true in XHTML but not HTML).

? Tag matches should be case insensitive. It is ok to convert all tags to lower (or upper) case.

? You should prompt the user for a filename. If that file does not exist, you may exit gracefully, you

do not need to ask again

The objectives of this assignment do not include practice with file parsing. To that end, you may make

the following (some realistic, some unrealistic) assumptions:

? tags can not cross multiple lines

? tags may contain no white space

? tags may have no attributes, they are one, single word (or character)

Plan of Attack

Create a Tag class capable of holding the information of one tag. To make life easier, you'll want a Tag to

be able to identify its base tag (ie, b, body, html) as well as whether it's an opening or closing tag.

The algorithm:

Load all tags from the file into a queue

Create a stack

for each tag in the queue

if it is an opening tag

push it onto the stack

if it is a closing tag,

if stack is empty

MISMATCH

otherwise

pop the top element from the stack - and you should have a

match

if match

keep going

otherwise

MISMATCH

If you find a mismatch, report the error and terminate the program. If your program was run on this file:

<body>

<html>

<B>This is an html file</B>

</body>

The output would be:

Explanation / Answer

In class this week, we will develop a Stack class and a Queue class. Use these c

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote