Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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

#include #include #include "string.hpp" #include "logentry.hpp" /** * @pre * @post */ log_entry::log_entry(const String & s) { // ... std::vector vec = s.split(' '); } /** * @pre * @post */ std::vector parse(std::istream & in) { std::vector result; //.... return result; } /** * @pre * @post */ void output_all(std::ostream & out, const std::vector & vect) { //.... } /** * @pre * @post */ void by_host(std::ostream & out, const std::vector & vect) { //......... } ////////////////////////////////////////////////////////// /** * @pre * @post */ int byte_count(const std::vector & vect) { //...... return 0; } 

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

logentry.hpp

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

#ifndef LOGENTRY_HPP #define LOGENTRY_HPP #include #include #include "string.hpp" /** date_type class */ class date_type { public: date_type() {}; private: String day, month; int year; }; /** time_type class */ class time_type { public: time_type() {}; private: int hour, minute, second; }; /** log_entry class */ class log_entry { public: log_entry() {}; log_entry(const String &); friend std::ostream & operator<<(std::ostream &, const log_entry &); private: String host; date_type date; time_type time; String request; String status; int number_of_bytes; }; // free functions std::vector parse (std::istream &); void output_all (std::ostream &, const std::vector &); void by_host (std::ostream &, const std::vector &); int byte_count (const std::vector &); #endif //if entry is blank you just call default ctor ... Logentry(); 

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

string.hpp

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

#ifndef CS23001_STRING_INTERFACE_HPP #define CS23001_STRING_INTERFACE_HPP #include #include /** * @invariant str[length()] == 0 * && length() == capacity() * && capacity() == stringSize - 1 */ class String { private: // helper constructors and methods String(int); String(int, const char *); void reset_capacity (int); char * str; // size includes NULL terminator int string_size; public: // constructor: empty string, String('x'), and String("abcd") String(); String(char); String(const char *); // copy ctor, destructor, constant time swap, and assignment String(const String &); ~String(); void swap (String &); String & operator= (String); // subscript: accessor/modifier and accessor char & operator[](int); char operator[](int) const; // max chars that can be stored (not including null terminator) int capacity() const; // number of char in string int length () const; //milestone 3 String substr(int, int) const; int find(char, int) const; int find(const String&, int) const; std::vector split(char) const; // concatenation String operator+ (const String &) const; String & operator+=(String); // relational methods bool operator==(const String &) const; bool operator< (const String &) const; // i/o friend std::ostream& operator<<(std::ostream &, const String &); friend std::istream& operator>>(std::istream &, String &); }; // free functios for concatenation and relational String operator+ (const char *, const String &); String operator+ (char, const String &); bool operator== (const char *, const String &); bool operator== (char, const String &); bool operator< (const char *, const String &); bool operator< (char, const String &); bool operator<= (const String &, const String &); bool operator!= (const String &, const String &); bool operator>= (const String &, const String &); bool operator> (const String &, const String &); #endif 

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

string.cpp

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

#include #include #include #include "string.hpp" String::String(int n){ string_size = n; str = new char[n]; str[0] = '\0'; } String::~String(){ delete [] str; } String::String(int x, const char *str1){ string_size = x; str = new char[x]; int pos = 0; while(str1[pos] != '\0') { str[pos] = str1[pos]; ++pos; } str[pos] = '\0'; } void String::reset_capacity(int x){ String str1(x, str); swap(str1); } String::String(){ str = new char[1]; str[0] = '\0'; string_size = 1; } String::String(char ch){ string_size = 2; str = new char[string_size]; str[0] = ch; str[1] = '\0'; } String::String(const char* s){ int counter = 0; while(s[counter] != '\0'){ ++counter; } string_size = counter + 1; str = new char[string_size]; for(int i = 0; i < counter ; i++){ str[i] = s[i]; } str[counter] = '\0'; } String::String(const String& s){ string_size = s.string_size; str = new char[string_size]; int pos = 0; for(int i = 0; i < string_size; ++i){ str[i] = s.str[i]; ++pos; } } int String::length() const{ int size = 0; while(str[size] != '\0') ++size; return size; } int String::capacity() const{ return string_size - 1; } String String::substr(int pos, int count) const{ char charArray[count + 1]; int position = 0; for(int i = pos; (i < string_size - 1) && (position < count); i++){ charArray[position++] = str[i]; } charArray[position] = '\0'; return String(charArray); } int String::find(char s, int pos) const{ int x = pos; for(int i = pos; (i <= string_size - 1); i++){ if(str[i] == s){ x = i; break; } } return x - pos; } int String::find(const String& str1, int pos) const{ int newLen = str1.length(); int x = pos; for(int i = pos; i < string_size - 1; i++){ bool strFound = true; for(int j = 0; ((j + i) < string_size - 1) && j < newLen; j++) { if(str[i + j] != str1.str[j]) { strFound = false; x = i; break; } } if(strFound) { return i - pos; } } return x; } std::vector String::split(char s) const{ std::vector vect; int begin = 0; for(int i = 0; i < string_size - 1; i++){ if(str[i] == s){ if(i > begin){ vect.push_back(substr(begin, i - begin)); begin = i + 1; } } } if(begin < string_size - 1){ vect.push_back(substr(begin, string_size - 1)); } return vect; } String& String::operator=(String str1){ string_size = str1.string_size; for(int i = 0; i < string_size; i++){ str[i] = str1.str[i]; } return *this; } char& String::operator[](int i){ assert(i >= 0); assert(i <= length()); return str[i]; } void String::swap(String& str1){ int tempStr = string_size; string_size = str1.string_size; str1.string_size = tempStr; char* tempStr1 = str; str = str1.str; str1.str = tempStr1; } char String::operator[](int i) const{ assert(i >= 0); assert(i <= length()); return str[i]; } bool String::operator==(const String& rhs) const{ int pos = 0; while(str[pos] != '\0' && str[pos] == rhs.str[pos]){ ++pos; } return str[pos] == rhs.str[pos]; } std::istream& operator>>(std::istream& in, String& rhs){ int counter = 0; in >> rhs.str; while(rhs[counter] != '\0'){ ++counter; in >> rhs.str; } rhs.string_size = counter + 1; rhs.str = new char[rhs.string_size]; for(int i = 0; i < counter ; i++){ rhs.str[i] = rhs[i]; } rhs.str[counter] = '\0'; return in; } std::ostream& operator<<(std::ostream& out, const String& rhs){ out << rhs.str; return out; } bool String::operator<(const String& rhs) const{ int pos = 0; while(str[pos] != '\0' && rhs.str[pos] != '\0' && str[pos] == rhs.str[pos]){ ++pos; } return str[pos] < rhs.str[pos]; } String String::operator+(const String& rhs) const{ int offset2 = (length() + rhs.length()) + 1; String result(offset2); int offset = length(); int count = 0; int pos = 0; while(str[count] != '\0'){ result.str[count] = str[count]; ++count; } while(rhs.str[pos] != '\0'){ result.str[offset + pos] = rhs.str[pos]; ++pos; } result.str[offset2 - 1] = '\0'; return result; } String& String::operator+=(String rhs){ int offset = length(); int pos = 0; int newSize = (length() + rhs.length()) + 1; String result(newSize); reset_capacity(newSize); for(int x = offset; x < newSize; ++x){ str[x] = rhs.str[pos]; ++pos; } str[newSize - 1] = '\0'; return *this; } String operator+(const char charArray[], const String& rhs){ String s(charArray); return rhs + s; } String operator+(char s, const String& rhs){ return s + rhs; } bool operator==(const char charArray[], const String& rhs){ if(charArray == rhs){ return true; } else{ return false; } } bool operator==(char s, const String& rhs){ if(s == rhs){ return true; } else{ return false; } } bool operator<(const char charArray[], const String& rhs){ if(charArray < rhs){ return true; } else{ return false; } } bool operator<(char s, const String& rhs){ if(s < rhs){ return true; } else{ return false; } } bool operator<=(const String& lhs, const String& rhs){ if(lhs < rhs || lhs == rhs){ return true; } else{ return false; } } bool operator!=(const String& lhs, const String& rhs){ if(lhs.length() != rhs.length()){ return true; } int pos = 0; while(lhs[pos] != rhs[pos]){ pos++; } if(pos == lhs.length()){ return true; } return false; } bool operator>=(const String& lhs, const String& rhs){ if(lhs > rhs || lhs == rhs) { return true; } else{ return false; } } bool operator>(const String& lhs, const String& rhs){ if(!(lhs <= rhs)){ return true; } else{ return false; } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions

Question

l,n=Dncone ico,e=ln0 0,n=00

Answered: 1 week ago

Question

What are the features of Management?

Answered: 1 week ago

Question

Briefly explain the advantages of 'Management by Objectives'

Answered: 1 week ago

Question

Explain the various methods of job evaluation

Answered: 1 week ago