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

using string.cpp, string.hpp, and logentry.hpp write the functions for logentry

ID: 3864290 • Letter: U

Question

using string.cpp, string.hpp, and logentry.hpp write the functions for logentry.cpp using the following Instructions. ALL instructions must be implemented. Thats all you have to do is write logentry.cpp but using the following stipulations.

You DO NOT need to write anything for string.cpp, string.hpp, or logentry.hpp

******** The file that needs to be implemented is ( https://web.cs.kent.edu/~jmaletic/data/log_4_large.txt ) *************

implementation:

logentry.cpp defines an ADT for log_entry. You will need to add functionality to this class to solve the problem. logview.cpp is the main and compiles and runs as is. You need to write the functions inside of it to solve the problem.

For each line in the log file split the line on blanks (or spaces). This should result in 10 strings.

If the entry is invalid (not 10 strings), store a blank log_entry.

For all valid entries you will need to do further processing and properly construct the log_entry data structure. See logentry.hpp

Testing:

Write a function (called parse) to read all the lines from the file and create a log_entry object for each line. This function will return a vector of log_entry's. See code in svn/shared/project2/

Write a function that given the vector of log_entry's computes the total number of bytes in all the entries.

Write a function that given the vector of log_entry's prints out the host member of each log entry (one per line).

Write a main that takes a file name and an option as command line parameters. The program will open the file name given on the command line and read from that file. Based on the command line options it will:

1) Print all the log_entry entries (neatly one per line, similar to what was read in).

2) Print the total number of bytes.

3) Print the host member for each log_entry (one per line).

-----------------------------------------------------------------------------------------------------------------------------------

logentry.cpp

-----------------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------------

logentry.hpp

-----------------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------------

string.hpp

-----------------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------------

string.cpp

-----------------------------------------------------------------------------------------------------------------------------------

Explanation / Answer

The required file is below.

logentry.cpp
________________________________________________________
#include "logentry.hpp"
#include "string.hpp"
#include <vector>
#include <fstream>
#include <iostream>
#include <stdlib.h>

/**
* @pre
* @post
*/
std::vector<logEntry> parse(std::istream& in)
{
std::vector<logEntry> result;
int i=0;
while(! in.eof())
{
    char temp;
    String raw("");
    in >> temp;
    while(temp != ' ' && !in.eof())
    {
      raw += String(temp);
      in.get(temp);
    }
    if(raw != String())
    {
      std::cout << "Parsing Record: " << i << " ";
      ++i;
      result.push_back(logEntry(raw));
    }
}

return result;
}

void output_all(std::ostream& out, const std::vector<logEntry> &logs)
{
   for(int i=0; i < (int)logs.size(); ++i)
     out << logs[i] << std::endl;
}

void by_host(std::ostream& out, const std::vector<logEntry> &logs)
{
for(int i=0; i < (int)logs.size(); ++i)
    out << logs[i].host() << std::endl;

}

int byte_count(const std::vector<logEntry> &logs)
{
int total_bytes =0;
for(int i=0; i < (int)logs.size(); ++i)
   total_bytes += logs[i].bytes();

return total_bytes;
}