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

Web page coding in HTML includes pairs of what are called \"tags\": and /HTML>,

ID: 3760933 • Letter: W

Question


Web page coding in HTML includes pairs of what are called "tags": and /HTML>, TITLE and ITITLE>, H6> and . Tags are surrounded by pointed brackets () and tags that occur in pairs have a forward slash just inside the left bracket of the closing tag. The last tag started must be the first one closed. Using a stack, write a program which takes HTML input and determines whether the tags are properly matched. Note that there are some tags that do NOT have a match-e.g. P, BR, IMG ..> do not have a matching ending tag. Also, count the number of times each non-ending tag appears in the code -e.g. count but do not count

Explanation / Answer

2) The code for reading the entire file and then printing it on the console and also to the output file.

#include <iostream.h>
#include <fstream.h>
#include <string.h>

void main ()
{
string str;
fstream ifile,ofile;
ifile.open ("demo.txt");

while(!demo.eof) // To get you all the lines.
{
getline(infile,str); // Saves the line in STRING.
freopen("output.txt","w",stdout);
cout<<str; // Prints our STRING.
}
ifile.close();
  
}

This normally requires the file handling techniques which are there in C++.

4) Printing the error into the console and saving it to the text file.

/* strerror example : error list */
#include <stdio.h>
#include <string.h>
#include <errno.h>

int main ()
{
FILE * pFile;
Ofstream ofile;
pFile = fopen ("unexist.ent","r"); //This opens the file in the readable mode.
if (pFile == NULL)
{
freopen("ofile.txt","w",stdout);
cout<<"Error opening file unexist.ent: <<" ",strerror(errno));
}
return 0;
}

3)

Counting the number if the tags.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
   //ifstream inputFile; // File stream Object
   char ch;
   const char TAG_OPEN = '<';
   bool link = false;
   int tagCount = 0;
   string line;
   string filename;      
   ifstream inputFile;

cout << "Enter valid filename ";
cin >> filename;

inputFile.open(filename.c_str());
while(!inputFile)
   {
   inputFile.clear();
   cout << "Re-Enter a valid filename: ";
   cin >> filename;
   inputFile.open(filename.c_str());
   }
inputFile.get (ch); //Reading the text to file
while (inputFile)
   {
       charCount ++;
       cout << ch;
if (ch == TAG_OPEN)
       {
           tagCount ++;
       }
inputFile.get (ch);

  
cout<<endl<<tagCount;
}

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