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



Overview... This lab asks you to program some data scraping . The key element that distinguishes data scraping from regular parsing is that the data being consumed is intended for display to an end-user, rather than as an input to another program. We will scrape data from Odin server output of the "w" command. We will start the program together in class on the big-screen. Do this...
$ cd $ cd 3350 $ cp /home/fac/gordon/p/3350/lab-start.sh . $ cp /home/fac/gordon/p/3350/lab-fix.sh . $ ./lab-start.sh $ cd 5 $ vi dslab5.cpp
Name your program /3350/5/dslab5.cpp We will now program together... • Please include a Makefile that builds your program.
Program details We are writing our own 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 2025:02:18 08:15:05 1 login: 12 users 2 logins: 5 users 3 logins: 1 user 5 logins: 1 user
Student sample outputs with corrections needed: • "(s)" not allowed. • Try to line up numbers on the decimal point.
1 login(s): 3 user(s) 11 login(s): 2 user(s) 39 login(s): 1 user(s) 1 login(s): 21 users 2 login(s): 12 users 3 login(s): 1 users 1 login(s): 22 user(s) 2 login(s): 13 user(s)
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: 2025:02:18 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/dslab5.cpp 3350/5/Makefile
Additional work - Unit Testing 1. Create a data file with known data 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. 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 fin.open("test_data.txt"); #endif