Web Log
General
- All submissions must include a work history to earn credit.
- Make sure your program accepts input in exactly the order and format specified. Do not ask for extra input or change the order of inputs. (If you want to make an expanded version of a program and get feedback on it, email it to me or show me in person.)
- Output the requested information in the specified order. Slight variations in output wording/formatting are usually fine, as long as formatting isn't part of the assignment. If you cannot get the right final output, print out some evidence of the work your program did to demonstrate your progress.
- Readability and maintainability of your code counts. Poor formatting, confusing variable names, unnecessarily complex code, etc. can result in deductions from your score.
Objective
Upon completion of this assignment, the student will be able to read data from a file and format output. They will also be able to use exception handling.
Assignment Instructions
Setup
It is assumed that you will use a codespace to do this assignment.
Start with the Combo Project template. Make your codespace from that repository.
Open tests.cpp and replace it with the starter code from this copy of tests.cpp.
Make a new file named WebLog.txt in the same folder as your code and
copy the contents of this
sample data file into it.
Make SURE the file is named exactly WebLog.txt (capitalization matters).
While working on this assignment, MAKE sure that you are generating a worklog with time stamped entries.
Background
The file WebLog.txt has lines of text that consist of the following pieces of data separated by a space:
IPAddress Username Time Minutes
Something like:
195.32.239.235 chardwick0 17:54:48 1
Time is in 24-hour format as hh:mm:ss (the hour will always have two digits), so 3:42 AM
is 03:42:00 and 3:42 PM is 15:42:00.
You will be writing a program that parses the log and extracts information about a particular visitor. First start by building some helper functions.
Time Processing
Begin in tests.cpp by implementing the two functions:
formatTimeToAMPM: Given an hour (0-23) and minutes (0-59), return a string representing that time in 12-hour format with AM/PM. If the hour or minutes are out of range (0-23 for hour and 0-59 for minutes), throw alogic_errorexception.reformatTime: Given a time string in 24-hour format (hh:mm:ss), return a string representing that time in 12-hour format with AM/PM. You may assume the input string is always in the correct format. For full credit, this MUST get the hour and minute values and then callformatTimeToAMPMto produce the final output. IfformatTimeToAMPMthrows an exception, you should catch it and return"???".
You can use these functions in your main program to convert the time from 24-hour format to 12-hour format.
If you get stuck on one or both of these functions, you can do the main program and not convert the time.
You are NOT expected to use a date or time library to work with the dates and times.
Trying to figure out how to do so will NOT make the problem easier. Focus on working with the data as strings and/or integers.
Main Program
In main.cpp implement a program to report data about a particular user.
If you built the time functions, you can use them in your main program by copy/pasting them above main().
Your program should ask for a username. The user will then type in something like chardwick0.
Your program should then read in the data from the file WebLog.txt.
For each line in the file where the username matches the user input your program should transform the data and print it to the screen so it looks like the table below.
At the top of the output, you should label the columns. The columns of data on each row should be lined up nicely:
- Name (You can assume no username will be longer than 20 characters)
- Time Left Justified (in 12-hour format with AM/PM)
- Minutes Right Justified (you can assume no entry will be more than 999 minutes)
Your final output should look something like:
Enter username:
chardwick0Name Time Minutes --------------------------------------------- chardwick0 5:54 PM 1 chardwick0 4:49 AM 14 chardwick0 12:07 PM 16 ...(rest of chardwick0 records) --------------------------------------------- Total minutes: 89
Hints
While testing, you may want to hard code in the username instead of reading it from the keyboard. It will be quicker to run the program if you don't have to type in
chardwick0each time. Just make sure to change your code back to reading in the username before you submit it!Work your way to a final program! Start by reading in all the items on the first line and printing them out unmodified. Then add a loop to do the same for each line. Then you can worry about cleaning the time. Then worry about formatting the output. Then worry about totaling the minutes. If you get stuck on one part, try working on something else.
Submission
Submit file: project.zip
See the codespace guide for instructions on how to create a .zip file of your project.
Recommended: Before submitting, practice building and running the code by hand. Open the Terminal in your codespace and do:
g++ -std=c++20 tests.cpp -o tests.exe
./tests.exe
g++ -std=c++20 main.cpp -o program.exe
./program.exe
Here is a link to the: command line guide