1 Programming Assignment 3: HTML File Analyzer COP XXXXXXXXXXFall Term 2020 Point Value: 100 points Project Due: 11:59 PM on Wednesday 10/7/2020 This assignment requires you to write a program to...

1 answer below »
1 Programming Assignment 3: HTML File Analyzer COP 3014 - Fall Term 2020 Point Value: 100 points Project Due: 11:59 PM on Wednesday 10/7/2020 This assignment requires you to write a program to analyze a web page HTML file. Your program will read one character at a time from the file specifying the web page, count various attributes in the code for the page, and print a report to the console window giving information about the coding of the page. Note that a search engine like Google uses at least one technique along similar lines. To calculate how popular (frequently visited or cited) a web page is, one technique is to look at as many other worldwide web pages as possible which are relevant, and count how many links the world's web pages contain back to the target page. Learning Objectives o To utilize looping structures for the first time in a C++ program o To develop more sophisticated control structures using a combination of selection and looping o To read data from an input file o To gain more experience using manipulators to format output in C++ o To consider examples of very simple hypertext markup language (HTML) Problem Statement Your program will analyze a few things about the way in which a web page is encoded. The program will ask the user for the name of a file containing a web page description. This input file must be stored in the correct folder with your program files, as discussed in class, and it must be encoded using hypertext markup language, or HTML. The analysis requires that you find the values of the following items for the page:  number of lines (every line ends with the EOLN marker; there will be an EOLN in front of the EOF)  number of tags (includes links and comments)  number of links  number of comments in the file  number of characters in the file (note that blanks and EOLNs do count)  number of characters inside tags  percentage of characters which occur inside tags, out of the total 2 Here is an example of a very simple HTML file: This course is about programming in C++.

  • Click here
    You may assume that the HTML files you must analyze use a very limited subset of basic HTML, which includes only the following "special" items: tag always starts with '<' and="" ends="" with="" '="">' link always starts with "' comment always starts with "" You may assume that a less-than symbol ('<') always="" indicates="" the="" start="" of="" a="" tag.="" a="" tag="" in="" html="" denotes="" an="" item="" that="" is="" not="" displayed="" on="" the="" web="" page,="" and="" often="" gives="" instructions="" to="" the="" web="" browser.="" for="" example,="" indicates="" the="" end="" of="" that="" section.="" in="" tags,="" both="" upper="" and="" lowercase="" letters="" can="" be="" used.="" note="" on="" links="" and="" comments:="" to="" identify="" a="" link,="" you="" may="" just="" look="" for="" an="" 'a'="" or="" 'a'="" which="" occurs="" just="" after="" a=""><'. to="" identify="" a="" comment,="" you="" may="" just="" look="" for="" a="" '!'="" which="" follows="" just="" after="" a=""><' (that="" is,="" you="" do="" not="" have="" to="" check="" for="" the="" two="" hyphens).="" you="" may="" assume="" that="" these="" are="" the="" only="" html="" language="" elements="" you="" need="" to="" recognize,="" and="" that="" the="" html="" files="" you="" process="" contain="" absolutely="" no="" html="" syntax="" errors.="" note:="" it="" is="" both="" good="" style="" because="" readability="" is="" increased,="" and="" convenient,="" to="" declare="" named="" constants="" for="" characters="" that="" are="" meaningful,="" for="" example="" const="" char="" tag_open='<' ;="" sample="" input="" files="" program="" input="" is="" to="" be="" read="" from="" a="" text="" file.="" your="" program="" must="" ask="" the="" user="" for="" interactive="" input="" of="" the="" file="" name.="" you="" can="" declare="" a="" variable="" to="" store="" the="" file="" name="" and="" read="" the="" user's="" response="" exactly="" as="" shown="" in="" lecture.="" we="" declared="" the="" name="" as="" a="" string="" of="" characters="" using="" the="" c++="" string="" class.="" then,="" if="" your="" variable="" is="" called="" filename,="" you="" can="" open="" the="" file="" using="" 3="" infile.open(filename.c_str());="" if="" the="" file="" will="" not="" open="" using="" the="" name="" entered="" (that="" is,="" the="" value="" of="" infile="" is="" null="" (zero)="" just="" after="" the="" call="" to="" open),="" re-prompt="" the="" user="" for="" a="" file="" name,="" and="" continue="" to="" do="" so="" until="" you="" finally="" are="" able="" to="" open="" the="" file="" successfully.="" you="" may="" assume="" that="" file="" names="" do="" not="" contain="" blanks.="" the="" only="" data="" error="" checking="" required="" is="" that="" described="" for="" the="" interactive="" input="" of="" the="" file="" name.="" how="" to="" obtain="" the="" data="" files:="" two="" sample="" files="" are="" provided="" to="" you="" on="" canvas.="" download="" the="" files="" and="" put="" them="" in="" the="" correct="" folder="" where="" you="" have="" saved="" your="" program="" files,="" as="" shown="" in="" lecture.="" the="" two="" sample="" files="" are="" 3xyz.html="" and="" test.html.="" start="" by="" testing="" your="" program="" on="" the="" smaller="" file,="" test.html.="" when="" your="" program="" works="" for="" that="" file,="" run="" it="" using="" the="" longer="" file="" 3xyz.html.="" you="" may="" want="" to="" test="" your="" program="" using="" other="" html="" files="" that="" you="" create="" yourself,="" or="" even="" obtain="" from="" the="" internet.="" the="" grader="" may="" use="" other="" files="" in="" testing="" your="" program.="" the="" only="" characters="" in="" the="" files="" will="" be="" printable="" characters,="" blanks,="" eoln="" markers="" and="" the="" one="" eof="" marker.="" your="" output="" with="" results="" of="" the="" analysis="" your="" program="" must="" contain="" the="" usual="" titles,="" labels,="" interactive="" prompts="" etc.="" as="" required="" by="" the="" programming="" style="" guidelines="" for="" this="" course="" (see="" style="" handout="" on="" course="" web="" site).="" you="" must="" also="" echoprint="" the="" complete="" input="" data="" file="" as="" is.="" after="" the="" file="" has="" been="" echoprinted,="" print="" the="" values="" of="" all="" of="" the="" required="" items="" described="" above.="" print="" the="" percentage="" in="" the="" format="" xx.xx="" %,="" where="" each="" 'x'="" represents="" a="" decimal="" digit="" (but="" do="" not="" show="" leading="" zeros).="" sample="" output="" for="" the="" test.html="" input="" file="" is="" provided="" on="" your="" class="" web="" site.="" miscellaneous="" tips="" and="" information="" you="" should="" not="" read="" the="" file="" more="" than="" once="" to="" perform="" the="" analysis.="" reading="" the="" file="" more="" than="" once="" is="" very="" inefficient.="" the="" simplest,="" most="" reliable="" and="" consistent="" way="" to="" check="" for="" an="" end="" of="" file="" condition="" on="" a="" loop="" is="" by="" checking="" for="" the="" fail="" state,="" as="" shown="" in="" lectures.="" the="" eof="" function="" is="" not="" as="" reliable="" or="" consistent="" and="" is="" simply="" deemed="" "flaky"="" by="" many="" programmers="" as="" it="" can="" behave="" inconsistently="" for="" different="" input="" files="" and="" on="" different="" platforms.="" you="" may="" use="" only="" while="" loops="" on="" this="" project="" if="" you="" wish;="" you="" are="" not="" required="" to="" choose="" amongst="" while,="" do="" while="" and/or="" for="" loops="" until="" project="" 4="" and="" all="" projects="" thereafter.="" do="" not="" create="" any="" functions="" other="" than="" main()="" for="" this="" program.="" do="" not="" use="" data="" structures="" such="" as="" arrays.="" you="" may="" only="" have="" one="" return="" statement="" and="" no="" exit="" statements="" in="" your="" code.="" you="" may="" only="" use="" break="" statements="" inside="" a="" switch="" statement="" in="" the="" manner="" demonstrated="" in="" class;="" do="" not="" use="" break="" or="" continue="" statements="" inside="" loops.="" be="" sure="" to="" read="" and="" understand="" the="" sections="" in="" the="" course="" syllabus="" on="" general="" project="" requirements.="" also="" study="" the="" style,="" documentation="" and="" formatting="" guidelines="" discussed="" in="" the="" 4="" programming="" style="" guidelines="" handout="" and="" in="" the="" lecture,="" textbook="" and="" recitation="" sections.="" check="" the="" syllabus="" for="" relevant="" required="" readings.="" miscellanous="" be="" sure="" to="" read="" and="" understand="" the="" sections="" in="" the="" course="" syllabus="" on="" general="" project="" requirements.="" also="" be="" sure="" to="" study="" the="" style,="" documentation="" and="" formatting="" guidelines="" discussed="" in="" the="" programming="" style="" guidelines="" handout="" and="" in="" the="" lecture,="" textbook="" and="" recitation="" sections.="" also="" pay="" attention="" to="" your="" code's="" efficiency.="" check="" the="" project="" faq="" and="" clarifications="" section="" on="" canvas="" for="" any="" updates.="" what="" file="" to="" turn="" in,="" file="" naming="" requirements,="" and="" turning="" in="" your="" work="" to="" canvas="" turn="" in="" your="" single="" c++="" program="" source="" file="" which="" must="" be="" named="" as="" follows.="" use="" this="" format:="" yourlastnamelowercase_fsuid_p3.cpp="" your="" fsuid="" will="" be="" unique="" to="" you,="" will="" typically="" be="" your="" fsu="" email="" id,="" and="" will="" be="" something="" like="" "ab23c."="" hence="" file="" names="" will="" look="" something="" like="" "smith_ab23c_p3.cpp"="" submit="" your="" single="" c++="" file="" (.cpp)="" to="" canvas="" using="" the="" submit="" button="" for="" this="" assignment.="" be="" sure="" to="" download="" the="" file="" from="" canvas="" also="" after="" you="" submit="" it="" in="" order="" to="" verify="" that="" you="" submitted="" the="" correct="" program="" file="" to="" canvas="" and="" that="" it="" was="" successfully="" received="" by="" canvas.="" last="" update:="" af="" tyson="">
  • Answered Same DayOct 03, 2021

    Answer To: 1 Programming Assignment 3: HTML File Analyzer COP XXXXXXXXXXFall Term 2020 Point Value: 100 points...

    Shivani answered on Oct 06 2021
    149 Votes
    #include
    #include
    #include
    #include
    using namespace st
    d;
    const char TAG='<';
    int main()
    {
        ifstream fp;
        char filename[30];
        string line;
        
        char fileChar;
        
        int num_lines=0;
        int num_tags=0;
        int num_links=0;
        int num_comments=0;
        int num_chars=0;
        int num_chars_in_tags=0;
        
        cout << "\n++++++++HTML File Analyzer++++++++";
        
        // Getting file name from the user
        // and opening the file
        while(1)
        {
            cout << "\nEnter the filename of the HTML file: ";
            cin >> filename;
            
            fp.open(filename);
            
            if(!fp)
                cout << "ERROR: File could not be opened for writing. Try again.\n";
            else
            {
                cout << "File successfully opened." << endl << endl;
                break;
            }
        }
        
        // printing the file contents line by line
        // and counting the total number of lines
        cout << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
        cout <<...
    SOLUTION.PDF

    Answer To This Question Is Available To Download

    Related Questions & Answers

    More Questions »

    Submit New Assignment

    Copy and Paste Your Assignment Here