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

Hi Chegg experts i need some help on this project as i am confused on what to do

ID: 3581353 • Letter: H

Question

Hi Chegg experts i need some help on this project as i am confused on what to do.

For this project, download the text file weblog.txt

This file is an Apache web log taken from the web server for St. Mary's University. 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.csc2.sort.clean holds the details of some of those requests. See below for a list of fields with an example:

Web Log Example

This file does not include all possible information that could be collected by a web server. The full description of the apache log file format can be found here:http://httpd.apache.org/docs/2.2/logs.html

For this project, you can use each line of the web log file as one string. Remember, each line of the file represents one page request.

Requirements:

Create a class that includes the following functions to work with the weblog.cpp file:

void openWebLog(); a function to open the weblog.txt file. Save each line of the file in a string array or vector of strings that is defined as a private data member of the class so all of the functions can access it. Line 1 of the file will be in index 0 of the array or vector. Line 2 of the file will be in index 1 of the array or vector, and so on.

int size(); a function to return the total number of lines in the weblog. Your main function should then display the return value.

void lineNum( int index); a function to display a line from the file when a line number is provided. Your main function should send over an index number in the parentheses when it calls this function.  Use the index number of the array (+1) to pull the requested line from the array or vector.

Create a main function in a separate .cpp file that creates an object of your class and calls each of the functions. Remember to #include your header file!

Upload your .h and .cpp files here

If you have questions or concerns, do not include them in your submission or you will have to wait for the project to be graded. Getting help requires a two-way conversation and this submission page doesn't allow that. Instead, if you need help, start a conversation and get help right away! Post to the discussion board, or contact me directly via email

Explanation / Answer

As you have not provided weblog.txt file, I have created a sample file as below and written the program.

SAMPLE FILE: - weblog.txt file

this is test file
to simulate WebLog
to check if the program works

WEB.h FILE:

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

// create class WebLog with one vector instance.
class WebLog{
vector<string> log;

public:
// 3 functions created as given in description.
void openWebLog();
int size();
void lineNum( int index);
};

// openWebLog function to open the log file and read the contents to vector.
void WebLog::openWebLog(){
string line;
string filename = "weblog.txt";
ifstream file(filename);

if(file.is_open()){
while(getline(file,line)){
log.push_back(line);
}
file.close();
}
else{
cout << "Could not open the file" << endl;
}
}

// size function to get the size of log file.
int WebLog::size(){
return log.size();
}

// lineNum to return the line of the logfile based on the given index.
void WebLog::lineNum(int index){
cout << "Line at index " << index << " is" << endl;
cout << log[index - 1] << endl;
}

SEPERATE.cpp FILE ->

#include<iostream>
#include "web.h"

using namespace std;

int main(){

// Create an instance of WebLog
WebLog wl ;

// call openWebLog to open the weblog.txt file
wl.openWebLog();

// to output number of lines in the log file.
cout << "Size of vector is " << wl.size() << endl;

// to find the line in weblog.txt file given the index.
wl.lineNum(3);
}

OUTPUT:

$g++ seperate.cpp

$./a.out

3
Line at index 3 is
to check if the program works