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

There is a weblog. When a visitor goes to their web site, the visitor\'s browser

ID: 3679176 • Letter: T

Question

There is a weblog. When a visitor goes to their web site, the visitor's browser makes a request to the web server to view a web page, which is a file residing on the server. Each time a page is requested by a browser, the web server records information about that request. This weblog.txt holds the details of some of those requests. See below for a list of fields with an example:

Web Log Example

Example entry from weblog.txt (this is a single line that wraps):

140.184.37.105 - - [08/Aug/2001:21:06:36 -0300] "GET /~csc226/outline.htm HTTP/1.0" 200 9748 "http://cs.stmarys.ca/~csc226/" "Mozilla/4.73 [en] (WinNT; U)"

Description of the fields from left to right with excerpts from the example:

ip Address: 140.184.37.105

field not included: -

field not included: -

Date and Time enclosed in brackets: [08/Aug/2001:21:06:36 -0300]

Page Requested in quotes: "GET /~csc226/outline.htm HTTP/1.0"

HTTP Status Code returned to the client (200= successful): 200

Length in Bytes of the page transferred: 9748

Referring Site (site that the client was referred from) in quotes: "http://cs.stmarys.ca/~csc226/"

Requesting Software (software that made the request) in quotes: "Mozilla/4.73 [en] (WinNT; U)"

you can use each line of the web log file as one string. An array of size 2990 will hold all of the lines in this file.

Minimum Requirements:

Create a separate class that contains the following: Note: This class should be separate and apart from the public class that holds the main method. You can either make a class that is not a public class in the same file or you could make it public and put it in a separate .java file:

Create a method to read each line of the web log file.

Each line should then be stored in a private array created in the class, such that the first element of the array is the first line of the web log file. Because each element will hold an entire line from the file, the array should be declared as an array of strings.

Create one more method to use the Arrays class sort method to sort the contents of the array and write the contents of the array to a file. The contents of the new file should look like the original input file once your program completes, but in sorted order.

In the primary class for your package, create a main method that calls all of your methods.

Explanation / Answer

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>

using namespace std;

class webstuff
{
public:
void ReadFile();
void WriteFile();
};
void webstuff::ReadFile()
{
ofstream myfile("weblog.txt");
if (myfile.is_open())
{
cout << "File was opened." << endl;
}
else cout << "Error. File was not opened." << endl;

vector <string> readLines;
string temp;
while ( getline (myfile, temp ) )
readLines.push_back("weblog.txt");
}

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