Kat H.

asked • 04/26/21

Web Log Parser. Submit to elearn: Make sure to name files EXACTLY as specified - including capitalization. Do not submit extra files. Do not zip or otherwise compress files unless told to.


Objective


Youwill be able to read data from a file and use string functions to process text.


Assignment Instructions

Should be able to compile and run your program with:


g++ -std=c++11 assign5.cpp -o program.exe
program.exe (./program.exe on a mac)

Your task is to write a program that parses the log of visits to a website to extract some information about the visitors. Your program should read from a file called WebLog.txt which will consist of an unknown number of lines. Each line consists of the following pieces of data separated by tabs:

IPAddress Username Date Time Minutes

Where Date is in the format d-Mon-yy (day, Month as three letters, then year as two digits) and time is listed in 24-hour time.

Read in the entire file and print out each record from April (do not print records from other months) in the format:

username m/d/yy hour:minuteAM/PM duration

Where mm/dd/yy is a date in the format month number, day number, year and the time is listed in 12-hour time (with AM/PM).

For example, the record:

82.85.127.184 dgounin4 19-Apr-18 13:26:16 13

Should be printed as something like:

dgounin4 04/19/18 1:26PM 13

Make sure that you read the right input file name. Capitalization counts!

Do not use a hard-coded path to a particular directory, like "C:\Stuff\WebLog.txt". Your code must open a file that is just called "WebLog.txt".

Do not submit the test file; I will use my own.

Here is a sample data file you can use during development. Note that this file has 100 lines, but when I test your program, I will not use this exact file. You cannot count on there always being exactly 100 records.

Hints

  1. Start small! Making sure your program works correctly on 1 line, or three lines is a lot easier than 100.
  2. Remember, my test file will have a different number of lines.
  3. You can read in something like 13:26:16 all as a string, or as an int, a char (:), an int, a char (:), and another int.
  4. If you need to turn a string into an int or a double, you can use this method:
string foo = "123";
int x = stoi(foo); //convert string to int

string bar = "123.5";
double y = stod(bar); //convert string to double



Patrick B.

C string libraries are REQUIRED!!! ifstream.getline requires C-style string.. Also C string libraries make parsing easier
Report

04/28/21

1 Expert Answer

By:

Patrick B. answered • 04/28/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.