Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 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 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 7/15/2020
  • Answered Same Day Oct 03, 2021

    Solution

    Shivani answered on Oct 06 2021
    151 Votes
    #include #include #include #include using namespace std;
    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 use
        
    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;
                
    eak;
            }
        }
        
        
    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