Homework 5

Due: October 20th, 2021 12:00pm


Background

The Codemon Academy is incredibly satisfied with your work (give yourself a pat on the back...because we can’t afford to pay you anything else). So the academy wants to up their security system to get control make students safer.

To up their security system, the academy has introduced “zones” with a sign-in system that logs the profile of the entrant as they enter the zone. A zone is a specific section of the academy. Each zone should only be entered by specific people. However, a few rascals sometimes sneak past the security guards. To catch these meddling brats, the academy has installed an entrant detection system that gives them information on each entrant. This information will be outputted to a log file which will be provided. There will be one log file for each zone.

Specifications

This homework will build off the last assignment with a few additions. One of the big ones being that you will no longer be taking input from standard in (cin). Instead you will be taking input from FILES! The files can be found here under “Homework 5” on this website.

In order to get all the data, all you have to do is issue these commands from the directory in which you want the files to reside:

wget https://henrycwong.com/homework/fs2021/hw5/the_library.log
wget https://henrycwong.com/homework/fs2021/hw5/training_room.log
wget https://henrycwong.com/homework/fs2021/hw5/faculty_lounge.log 
wget https://henrycwong.com/homework/fs2021/hw5/the_chamber_of_ekans.log
The input files will be in the format:
fname lname age occupation num_of_codemon security_level
      

Zones

The Codemon Academy has introduced 4 different zones:

  1. The Library
  2. Training Room
  3. Faculty Rager Lounge
  4. The Chamber of Ekans (for even more copyright infringement)

You will need to create a struct to represent the zones. To get data for each zone, each zone will have its own log file. Therefore, you will be required to read through 4 files that are provided.

Each zone and entrant will be assigned a “security level” ranging from 1-4. The Library has a security level of 1, the Training Room with a security level of 2, the Faculty Lounge with a security level of 3, and finally The Chamber of Ekans with a security of 4. The higher the number, the more strict the security is.

Each zone will also have a name and a “total number of potential violations”, which is the total number of potential violations that have occurred within that specific zone.

Potential Violations

You are to detect whenever there is a potential violation and provide a warning in the output file.

Potential Team Picket members will now be logged as warnings, so no need to print out if a entrant was suspected to be from team Picket.

A potential violation is committed if:

  1. the entrant is at or over the age of 30 and tries to enter as a student
  2. an entrant is logged as entering a zone with a security level higher than themselves
    • e.g. a student with a security level of 2 is logged to have entered the Faculty Lounge will result in a violation
    • To do this you will be required to overload at least one operator
  3. The number of codemon an entrant has is greater than the 3rd quartile of all codemon within the zone the entrant has entered.

Finding the 3rd Quartile

To find the quartile of an array, you must:

  1. Sort the array (sorting should be its own function)
  2. Find the index of the 3rd quartile by calculating (3/4) * (n+1) where n is the number of useful data
    • Find what element is in the index found from the formula above
    • If the index is not a full number, round down to the nearest integer
  3. The number at the index calculated will be the 3rd quartile if the index started at 1.

Recording Warning/Potential Violations

To record these warnings. You will write to a file specifically for the zone where the potential violation occurred. Therefore, you will be writing to 4 different files, each called the_library_warnings.log, training_room_warnings.log, faculty_lounge_warnings.log, and the_chamber_of_ekans_warnings.log (if you already made your program output .txt, that's ok. But if you can change it to .log).

The warnings per zone will be placed in their respective files.

Each warning will contain the following information in order:

Notice the format is similar to the printEntrant function in the previous homework. However, for this homework we will expect you to overload the << operator.

If one entrant has more than one warning, treat each warning as a separate entity regardless of the entrant. Therefore, there will be one warning for each recorded potential violation. The order of which the warning should be presented first is in the following order:

  1. over age of 30 and occupation is “student”
  2. entrant has security level lower than zone
  3. number of codemon is greater than the third quartile

Therefore, in the output file, the first entrants to be listed are entrants who were over 30 and occupation was “student”. The next entrants listed will be entrants who have a security level less than the security level of the zone they entered. Finally, the last entrants listed in the output file will be entrants who had more Codemon than the 3rd quartile.

You will then have a “summary” section that will print out each zone followed by the total number of violations for that zone in descending order.

Example Output (To Standard Out):

This will be what is in standard out. We will also be grading you on the output files you generate.

Summary

Training Room: 7 potential violations
The Chamber of Ekans: 3 potential violations
The Library: 2 potential violations
Faculty Lounge: 0 potential violations
      

Algorithm

Read in input from first zone
Store data as appropriate
For every potential violation
    record a warning in the output file
Repeat 1-3 for every input file
Print out the number of total violations per zone in descending order
      

Note: