Question
DO NOT COPY PASTE ANSWERS FROM OTHER PEOPLE'S QUESTIONS THIS ONE IS DIFFERENT! Write a C or C++ program that implements a home security policy.
DO NOT COPY PASTE ANSWERS FROM OTHER PEOPLE'S QUESTIONS THIS ONE IS DIFFERENT!
Write a C or C++ program that implements a home security policy.
The name of the simulator should be secure_home
The policy states that only users with an authorized key can enter the home. To enter the home, the user must first put their key in the lock, then turn the lock, then enter the home, only if the key is valid. A home can be rekeyed with new keys only by the owner, and only if the owner is inside the home.
Firefighters can enter with the secret key (literal string) : FIREFIGHTER_SECRET_KEY
Police can enter as long as their user_name starts with OFFICER_WITH_WARRANT and their key is POLICE_SECRET_KEY.
You must implement the following command-line interface for your server:
./secure_home
where
All inputs to the program (keys and names) will be [a-zA-Z0-9_\-] (alphanumeric, underscore, and dash). All matching is case-sensitive.
The input to the program (on standard input)) will be a series of events separated by a newline. The program must track these events and respond appropriately, while enforcing the security policy.
Every input will end in a newline, and every response must end in a newline.
INSERT KEY
User_name inserts key key into the door. Response should be: KEY
TURN KEY
ENTER HOUSE
WHO'S INSIDE?
Who is currently inside the home? Response should be a comma-separated list of user names, ordered by access time (earlier access first):
CHANGE LOCKS
LEAVE HOUSE
If any events are received that are not according to this specification, the response must be: ERROR.
Example Running the program as follows:
./secure_home that lady
Given the input:
INSERT KEY sadaf key
TURN KEY sadaf
ENTER HOUSE sadaf
INSERT KEY that lady
TURN KEY that
ENTER HOUSE that
WHO'S INSIDE?
The program will produce the following output:
KEY key INSERTED BY sadaf
FAILURE sadaf UNABLE TO TURN KEY key
ACCESS DENIED
KEY lady INSERTED BY that
SUCCESS that TURNS KEY lady
ACCESS ALLOWED
Pat
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started