CPT overview
Program Purpose and Function The program serves to provide a public platform for customers to share their experiences and opinions about the restaurant. Additionally the program serves the purpose of organizing customer feedback in a way which can be analyzed by the business. The program allows the user to input their name, written review, and numerical rating of their experience. The user data is validated and then added to a database and displayed in a well organized table for future users to view. Additionally, the program updates the average rate value with every new review added and gives authorized users to delete certain reviews.
Managing Complexities The list being used here is ratesList. ratesList is used to store an array of the rates taken from each user’s review in the database. This ratesList is used in two ways. For one, it is averaged to provide for the average rate, which updates for every review added. Additionally, ratesList is used in creating the rates distribution table. For this task each rate must be accounted for, checked, and then assigned to its proper distribution value. To do this task with variables or another method would be inefficient and time consuming as the number of rates in the database increases. A list also maintains the necessary information in one location making it easier to access and keep track of for operations. In ratesList is a change were to be made, such as a change in the number of rates, an additional object in the list would be created rather than a new variable.
Procedural Abstraction This procedure countRates() takes a list as a parameter. First the variables ratevalue_1, ratevalue_2 …. ratevalue_5 are assigned to the value 0. The function will count the number of each rate value present in the list and add it to the counter variables to return a dictionary of key-value pairs containing the counted rates data.
Algorithmic Implementation The program iterates through the list defined in the parameters beginning with a for statement, stating to iterate through all values in the list within the length of the list. The program then uses if/elif statements to see if the value being passed matches the certain parameter, and therefore what ratevalue_num counter variable should be updated accordingly. The loop repeats for the length of the list, therefore accounting for every rate in the database. The function will count the number of each rate value present in the list and add it to the counter variables to return a sequenced dictionary of key-value pairs containing the counted rates data.
Testing Condition(s) tested by the first call: This call will include an unhappy review, with a rate of 1. Condition(s) tested by the first call: This call will include an happy review, with a rate of 5. Result(s) tested by the first call: The average rate will decrease due to an addition of a rate lesser than the original average. The rate will be appended to ratesList, and an increase of one will be accounted for in ratevalue_1 and displayed in the reviews distribution table . Result(s) tested by the first call: The average rate will increase due to an addition of a rate greater than the original average. The rate will be appended to ratesList, and an increase of one will be accounted for in ratevalue_5 and displayed in the reviews distribution table.