Log off User

Write a computer program that could be used to track users' activities. Lab Number Computer Station Numbers 1 1-3 2 1-4 3 1-5 4 1-6  You run four computer labs. Each lab contains computer stations that are numbered as the above table.  There are two types of users: student and staff. Each user has a unique ID number. The student ID starts with three characters (for example, SWE or DMT), and is followed by three digits (like, 001). The staff ID only contains digits (for example: 2023007).  Whenever a user logs in, the user’s ID, lab number, the computer station number and login date are transmitted to your system. For example, if user SWE001 logs into station 2 in lab 3 in 01 Dec, 2022, then your system receives (+ SWE001 2 3 1/12/2022) as input data. Similarly, when a user SWE001 logs off in 01 Jan, 2023, then your system receives receives (- SWE001 1/1/ 2023). Please use = for end of input.  When a user logs in or logs off successfully, then display the status of stations in labs. When a user logs off a station successfully, display student id of the user, and the number of days he/she logged into the station.  When a user logs off, we calculate the price for PC use. For student, we charge 0 RMB if the number of days is not greater than 14, and 1 RMB per day for the part over 14 days. For staff, we charge 2 RMB per day if the number of days is not greater than 30, and 4 RMB per day for the part over 30 days.  If a user who is already logged into a computer attempts to log into a second computer, display "invalid login". If a user attempts to log into a computer which is already occupied, display "invalid login". If a user who is not included in the database attempts to log off, display "invalid logoff".
06-01
Here is a possible implementation of the program in Python: ```python import datetime # initialize the status of all stations to False status = [[False for j in range(4)] for i in range(5)] # initialize the dictionary of users users = {} # define the function to check if a user is already logged in def is_user_logged_in(user_id): for i in range(5): for j in range(4): if status[i][j] and users[(i+1, j+1)] == user_id: return True return False # define the function to log in a user def log_in(user_id, lab_num, station_num, login_date): if is_user_logged_in(user_id): print("invalid login") elif status[lab_num-1][station_num-1]: print("invalid login") else: status[lab_num-1][station_num-1] = True users[(lab_num, station_num)] = user_id print("user", user_id, "logged in at lab", lab_num, "station", station_num) print("status:", status) # define the function to log off a user def log_off(user_id, logoff_date): found = False for i in range(5): for j in range(4): if status[i][j] and users[(i+1, j+1)] == user_id: status[i][j] = False days = (logoff_date - datetime.date.today()).days print("user", user_id, "logged off at lab", i+1, "station", j+1) print("number of days logged in:", days) found = True break if found: break else: print("invalid logoff") return if user_id.startswith("S"): if days <= 14: price = 0 else: price = (days - 14) * 1 else: if days <= 30: price = 0 else: price = (days - 30) * 4 + 30 * 2 print("price:", price, "RMB") # example usage log_in("SWE001", 3, 2, datetime.date(2022, 12, 1)) log_in("SWE001", 3, 3, datetime.date(2022, 12, 1)) # expected output: invalid login log_in("SWE002", 3, 2, datetime.date(2022, 12, 1)) log_off("SWE001", datetime.date(2023, 1, 1)) log_off("SWE003", datetime.date(2023, 1, 1)) # expected output: invalid logoff ``` Note that this is just one possible implementation, and there may be other ways to structure the program.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值