Answered step by step
Verified Expert Solution
Question
1 Approved Answer
We will be implementing menu item number 3 ( Edit room filter ) from the menu. Lists and Dictionary This module uses the two lists
We will be implementing menu item number Edit room filter from the menu.
Lists and Dictionary
This module uses the two lists sensorlist & filterlist and a dictionary sensors that we created in previous assignments. Ensure that the recursivesort function is also included in this module. The recursivesort function definition should be at the top of the module with the other function definitions. The lists and dictionary should come just before the while loop that runs the menu in main
sensorlist
The list, sensorlist has information room number, description, sensor number about each sensor sorted by room number It is static it is not changed Place this list within main
filterlist
The list filterlist will initially contain all sensor numbers from sensorlist. It will be updated by the function changefilter as the user makes changes to which sensors are active. It is a dynamic list. Place this list within main
sensors
The dictionary, named sensors contains the room name, the room number, and sensor number from sensorlist. It is a dict. When the user enters a room number, we will use this dictionary to find the sensor number. It will stay static. Place this list within main
Functions
printfilter
We need a function that will print the list of filters, and display which ones are currently active. Name this function printfilter printfilter should take two arguments, sensorlist and filterlist. It doesn't return anything since its sole job is to print to the screen.
changefilter,
The function changefilter should take three required arguments: sensors sensorlist, and filterlist. It returns nothing. Why does it return nothing, don't we need to know which filters are active in other parts of the program? Please discuss this in the forums.
changefilter will repeatedly print the filtered sensor list use the printfilter function and ask the user to enter the room number for the sensor that we want to add to or remove from the filter list. The user can also enter x to exit. If the user enters an invalid sensor the user gets an error message see the sample run but the loop continues. The function should be updating filterlist as the user adds or removes filters.
Finally, update the main menu so that it correctly calls changefilter
Sort the Sensor List
Have your program run the recursive sort function on sensorlist before the while loop that handles the menu we only need to sort once. We want our sort to be on the room number string.
Here's a sample output, assuming that all but filter sensor is active:
: Foundations Lab ACTIVE
: CS Lab
: Tiled Room ACTIVE
: STEM Center ACTIVE
: Workshop Room ACTIVE
Out: Outside ACTIVE
filterlist indicates which sensors should show the "ACTIVE" tag above. If filterlist contained you would get the result above because sensor room is not in filterlist.
In a future Lab Assignment, our program will display summary data from all the sensors in the STEM Center. We want to be able to restrict this to one room, or a group of rooms.
Program Test the User Interaction Loop
In a while loop, print the filtered sensor list by calling printfilter
Then ask the user to enter one of the sensors room numbers, like or Out to add to or remove from the filter list.
The user will enter the room number not the sensor number or room name though keep in mind that 'Out' is considered a room number to toggle the filter.
This repeats until the user enters x to exit.
If the user enters an invalid sensor number, the user gets an error message see the sample run but the loop continues.
At the least, provide the same unit tests in your submission as are provided in the sample run below.
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