CMPS-3350 Lab-5 - C++ programming challenge - Data Scraping

Note:
Some test files for utest are at: /home/fac/gordon/p/3350/code/lab5/

I will still make some new test files that you do not have.


Overview... This lab is an example of data scraping. Getting data onto your screen, then collecting and processing the data. We will scrape data from Odin. We will start the program together in class on the big-screen. Name your program /3350/5/mylab5.cpp • Please include a Makefile that builds your program(s).
Program details We are writing a Linux utility program. We want to know how many users are logged in once, twice, 3-times, 4-times, etc. Use the Linux w utility to create a file, then scrape the file. sample output...
$ ./lab5 Odin current login statistics 2024:09:24 08:15:05 1 login: 12 users 2 logins: 5 users 3 logins: 1 user 5 logins: 1 user
Rules... Your program should have at least one function outside of main. Do not use the STL, vectors, <algorithm>, etc. If you find any code online... 1. Put the URL in a comment just above the code. 2. Briefly explain why you could not write the code yourself. You may use the C++ string class. You may use printf and sprintf. You may use arrays, temporary files, sorting, hash tables, C++ string class, Cstring arrays, string searching, multiple file passes, etc. You may apply the -h flag to your w command. You may apply the PROCPS_USERLEN=15 modifier to your w command. Help... Code sample to show date and time like this: 2024:09:24 08:15:05 #include <time.h> time_t T; time(&T); printf("time: %s\n", ctime(&T));
Program files to be collected at 9:50am... 3350/5/mylab5.cpp 3350/5/Makefile
Additional work as homework 1. Create a data file with known values. This file will contain data in a structure similar to the file your program will construct for the live Odin data. To do this Unit Test, run your program like this: ./utest myfile.txt When your program sees a command-line file name, it will use that file for a test rather than scraping live data from Odin server. 2. You must put this functionality in a second executable. This compile option will activate your Unit Test... -D UNIT_TEST Isolate all unit test functionality from your production program using #define pre-processor directives. Gordon will test your program with live data, and unit-test file input. 3. How to isolate test code from production code. Choose a section of code such as... ifstream fin; fin.open("live_data.txt"); Change it to this... ifstream fin; #ifdef UNIT_TEST fin.open("live_data.txt"); #else //UNIT_TEST fin.open("test_data.txt"); #endif //UNIT_TEST