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

Hi Expert:) Can anyone help with this homework problem please please please? The

ID: 3688898 • Letter: H

Question

Hi Expert:) Can anyone help with this homework problem please please please? The homework gonna DUE soon, please help please!!!! Thank you in advance!!! Please!!! Project 3: Dynamic Container Class You will need to download these files for this project: weblog_small.txt Here is the link: http://www.santarosa.edu/~lmeade/cs11/weblog_small.txt weblog_medium.txt here's the link: http://www.santarosa.edu/~lmeade/cs11/weblog_medium.txt These files are Apache web logs 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. See below for a list of fields with an example: Web Log Example (link: http://www.santarosa.edu/~lmeade/cs11/weblog.html) The files for this project do not include all possible information that could be collected by a web server. If you are interested, 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. For this project, create a dynamic container class so your program can be used for any sized Apache weblog. Each line of the file will be a single string that will be stored in a dynamic array (do not use vector for this assignment!). The dynamic array should be declared in the private section of your class. Requirements The container class should include the following functions to work with the weblog.cpp file (8 points). void add(); a function to open the weblog.txt file and add a line from the file as a string to the private array. int size(); a function to return the total number of lines in the container. void lineNum( int index); a function to display a line from the container when a line number is provided. Note: This is the line number, which is the array's index number + 1. void lineSearch(std::string key); a function to search the container for a specific search string, such as an ip address, and display all lines that contain that search string. Dynamic Array Requirements The original private array should be initialized to a starting size of 50. Include a class private function to grow the array when it is filled to capacity. (5 points) Create another function that adds to the array. If the array is filled to capacity, the private function should be called to grow the array before the add is performed. (5 points) Write a main function to run the program. Your program should be able to test your class functions with both the weblog_small.txt and weblog_medium.txt. (2 points)

Explanation / Answer

weblogclient.cpp

#include <iostream>
#include <fstream>
#include <cassert>
#include <string>
#include "mybag.h"

using namespace std;

void getData(MyBag& webLog);
void printResults(MyBag& webLog);

int main()
{
   MyBag webLog;

   getData(webLog);
   printResults(webLog);

   return 0;
}

//********************************************************************

void getData(MyBag& webLog)
// This function gets the data from a file.

{
   ifstream inFile;
   string webLine;

   inFile.open("weblog.txt");
   assert(inFile);

   while (getline(inFile, webLine))
   {
      webLog.add(webLine);
   }
   inFile.close();
   inFile.clear();

}

//********************************************************************

void printResults(MyBag& webLog)


{

   cout << "There were " << webLog.size()
       << " total page requests." << endl << endl;

   cout << "Line number 5: ";

   webLog.lineNum(5);

   cout << "Search for IP 24.138.48.78: ";

   webLog.lineSearch("24.138.48.78");
}


mybag.cpp

#include "mybag.h"

// Adds a new string to the next available spot in the array.
void MyBag::add(string line)
{
   if ( index == capacity-1 )
      expandArray();             // should double array size.

   logs[index] = line;
   index++;
}


// Returns the amount of strings held in the 'bag'.
int MyBag::size()
{
   return index;
}


// Allows the client to see what content is stored at a particular line number.
void MyBag::lineNum(int index)
{
   cout << logs[index-1] << " ";
}


// Allows the user to search for all instance where the key is found in the data.
void MyBag::lineSearch(string key)
{
   int count = 1;
   int arraySize = START_SIZE;

   for (int i = 0; i < arraySize; i++){
      if (logs[i].find(key) != string::npos){
         cout << count << ") " << logs[i] << " ";
         count++;
      }
   }
}


void MyBag::expandArray(){
   // create instance array, make it bigger, change pointer back.
   // update size of 'capacity' int.
   string *grow = new string[capacity*2];

   for (int i = 0; i < capacity; i++)
      grow[i] = logs[i];
   delete [] logs;
   logs = grow;
   capacity *= 2;
}


mybag.h
// Spencer Thompson project #1
//
// Class MyBag works as a container for weblogclient.cpp.
// This class gives some added functionality to an array structure.
// The client can search for a given input, find the total size, and
// call for the content on a particular line, as well as add to data to the
// end of the array.
//


#ifndef __CS2Bproject1__mybag__
#define __CS2Bproject1__mybag__

#include <stdio.h>
#include <string>
#include <iostream>
#include <array>
using namespace std;

class MyBag {

public:
   static const int START_SIZE = 10;

private:
   string *logs = new string [START_SIZE];
   int capacity = START_SIZE;
   int index = 0;
   void expandArray();

public:
   void add(string line);
   int size();
   void lineNum(int index);
   void lineSearch(string key);

};
#endif /* defined(__CS2Bproject1__mybag__) */

weblog.txt
172.138.80.174 - - [05/Aug/2001:21:06:27 -0300] "GET /~csc226 HTTP/1.0" 301 303 "http://www.goto.com/d/search/?Keywords=stringVar+%2B+savitch&view=2+80+0&did=" "Mozilla/4.61 [en] (Win98; I)"
172.138.80.174 - - [05/Aug/2001:21:06:28 -0300] "GET /~csc226/ HTTP/1.0" 200 3387 "http://www.goto.com/d/search/?Keywords=stringVar+%2B+savitch&view=2+80+0&did=" "Mozilla/4.61 [en] (Win98; I)"
172.138.80.174 - - [05/Aug/2001:21:06:37 -0300] "GET /~csc226/class HTTP/1.0" 301 309 "http://cs.stmarys.ca/~csc226/" "Mozilla/4.61 [en] (Win98; I)"
172.138.80.174 - - [05/Aug/2001:21:06:37 -0300] "GET /~csc226/class/ HTTP/1.0" 200 2777 "http://cs.stmarys.ca/~csc226/" "Mozilla/4.61 [en] (Win98; I)"
172.138.80.174 - - [05/Aug/2001:21:06:49 -0300] "GET /~csc226/ HTTP/1.0" 200 3387 "http://www.goto.com/d/search/?Keywords=stringVar+%2B+savitch&view=2+80+0&did=" "Mozilla/4.61 [en] (Win98; I)"
140.184.71.52 - - [06/Aug/2001:10:42:36 -0300] "GET /~csc226 HTTP/1.1" 403 287 "http://cs.stmarys.ca/~pawan/" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"
140.184.71.52 - - [06/Aug/2001:10:43:02 -0300] "GET /~csc226 HTTP/1.1" 301 315 "http://cs.stmarys.ca/~pawan/" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"
140.184.71.52 - - [06/Aug/2001:10:43:02 -0300] "GET /~csc226/ HTTP/1.1" 200 8830 "http://cs.stmarys.ca/~pawan/" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"
206.135.248.66 - - [07/Aug/2001:15:04:49 -0300] "GET /~csc226/ HTTP/1.1" 200 8830 "-" "Mozilla/4.5 [en] (Win98; I)"
142.177.53.120 - - [07/Aug/2001:18:28:33 -0300] "GET /~csc226/ HTTP/1.0" 200 8802 "-" "Mozilla/4.04 [en]C-SYMPA (Win95; I)"
24.138.27.124 - - [08/Aug/2001:00:41:38 -0300] "GET /~csc226/ HTTP/1.0" 200 8802 "[unknown origin]" "Mozilla/4.7 [en] (Win98; U)"
216.35.103.54 - - [08/Aug/2001:16:42:44 -0300] "GET /~csc226 HTTP/1.0" 301 303 "-" "Mozilla/3.0 (Slurp/cat; slurp@inktomi.com; http://www.inktomi.com/slurp.html)"
216.35.103.54 - - [08/Aug/2001:16:43:09 -0300] "GET /~csc226/ HTTP/1.0" 200 8802 "-" "Mozilla/3.0 (Slurp/cat; slurp@inktomi.com; http://www.inktomi.com/slurp.html)"
140.184.44.130 - - [08/Aug/2001:17:06:35 -0300] "GET /~csc226/ HTTP/1.0" 200 8802 "[unknown origin]" "Mozilla/4.73 [en] (WinNT; U)"
140.184.44.130 - - [08/Aug/2001:17:06:53 -0300] "GET /~csc226/ HTTP/1.0" 200 8802 "[unknown origin]" "Mozilla/4.73 [en] (WinNT; U)"
140.184.44.130 - - [08/Aug/2001:17:07:01 -0300] "GET /~csc226/ HTTP/1.0" 200 8802 "[unknown origin]" "Mozilla/4.73 [en] (WinNT; U)"
140.184.44.130 - - [08/Aug/2001:17:09:10 -0300] "GET /~csc226/rules.htm HTTP/1.0" 200 7342 "http://cs.stmarys.ca/~csc226/" "Mozilla/4.73 [en] (WinNT; U)"
140.184.44.130 - - [08/Aug/2001:17:09:15 -0300] "GET /~csc226/lab HTTP/1.0" 301 307 "http://cs.stmarys.ca/~csc226/" "Mozilla/4.73 [en] (WinNT; U)"
140.184.44.130 - - [08/Aug/2001:17:09:15 -0300] "GET /~csc226/lab/ HTTP/1.0" 200 2066 "http://cs.stmarys.ca/~csc226/" "Mozilla/4.73 [en] (WinNT; U)"
140.184.44.130 - - [08/Aug/2001:17:09:20 -0300] "GET /~csc226/class HTTP/1.0" 301 309 "http://cs.stmarys.ca/~csc226/" "Mozilla/4.73 [en] (WinNT; U)"
140.184.44.130 - - [08/Aug/2001:17:09:20 -0300] "GET /~csc226/class/ HTTP/1.0" 200 2064 "http://cs.stmarys.ca/~csc226/" "Mozilla/4.73 [en] (WinNT; U)"
140.184.44.130 - - [08/Aug/2001:17:09:23 -0300] "GET /~csc226/class/week-01/ HTTP/1.0" 200 820 "http://cs.stmarys.ca/~csc226/class/" "Mozilla/4.73 [en] (WinNT; U)"
140.184.44.130 - - [08/Aug/2001:17:09:25 -0300] "GET /~csc226/class/week-01/thursday.doc HTTP/1.0" 200 21504 "http://cs.stmarys.ca/~csc226/class/week-01/" "Mozilla/4.73 [en] (WinNT; U)"
140.184.37.105 - - [08/Aug/2001:21:05:46 -0300] "GET /~csc226 HTTP/1.0" 301 303 "-" "Mozilla/4.73 [en] (WinNT; U)"

sample output

There were 0 total page requests.                                                                                                                           
                                                                                                                                                            
Line number 5:                                                                                                                                              
                                                                                                                                                            
                                                                                                                                                            
Search for IP 24.138.48.78: