Problem 2. Processing donut selection (24-marks) The system should use multipleListsto maintain a history of the donuts purchased by all users in the system. Specifically, fiveListsshould be usedto...

1 answer below »

Problem 2. Processing donut selection (24-marks)


The system should use multipleListsto maintain a history of the donuts purchased by all users in the system. Specifically, fiveListsshould be usedto keep track of various elements of each purchase:



  1. List 1 - Names:The first list should contain the names of all the users who have purchased donuts in the system.

  2. List 2 - Chocolate:The second list contains the number of chocolate donuts purchased by each user.

  3. List 3 - Strawberry:The third list contains the number of strawberry donuts purchased by each user.

  4. List 4 - Vanilla:The fourth list contains the number of vanilla donuts purchased by each user

  5. List 5 - Honey:The fifth list contains the number of honey donuts purchased by each user.


For example, if Sana is the first user in the system and bought 10 chocolate donuts, 2 strawberry donuts, 9 vanilla donuts, and 5 honey donuts. Then, the five Lists specified above will contain the following values:




























List 1 (Names)





List 2 (Chocolate)





List 3 (Strawberry)





List 4 (Vanilla)





List 5 (Honey)



Sana





10





2





9





5



After this, if the user Jane bought 2 chocolate donuts, 0 strawberry donuts, 1 vanilla, and 2 honey donuts, then the Lists would have the following values:







































List 1 (Names)





List 2 (Chocolate)





List 3 (Strawberry)





List 4 (Vanilla)





List 5 (Honey)



Sana





10





2





9





5



Jane





2





0





1





2



Thus, the first element in each List stores the user’s name, number of chocolate donuts, number of strawberry donuts, number of vanilla donuts, and number of honey donuts respectively. Essentially, theNthelement of each List stores information about the Nth purchase. Each user only has one entry in each of the five Lists regardless of how many purchases they make.


Let's say the user Sana, buys 2 more honey donuts, then their respective value in the Honey list is increased. In this case, the Lists would have the following values:







































List 1 (Names)





List 2 (Chocolate)





List 3 (Strawberry)





List 4 (Vanilla)





List 5 (Honey)



Sana





10





2





9





7



Jane





2





0





1





2



Adding donuts to Lists


After creating the five lists, write code for processing the user’s selection in menu2. Specifically, when a user buys a donut, information about their purchase should be added to the five Lists. For example, if the user Sana bought 5 chocolate donuts, then the following values should be added to each of the five lists:



  • Value of“Sana”should be added to the names list

  • Value of5should be added to the chocolate donuts list

  • Value of0should be added to the strawberry donuts list

  • Value of0should be added to the vanilla donuts list

  • Value of0should be added to the honey donuts list


After this, if Sana buys 2 vanilla donuts, then the followingupdatesshould be made to each of the five lists:



  1. Retrieve the index of where“Sana”is located in the names List

  2. In the chocolate donuts List, add0to the value associated with Sana (use index from step 1)

  3. In the strawberry donuts list, add0to the value associated with Sana (use index from step 1)

  4. In the vanilla donuts list, add2to the value associated with Sana (use index from step 1)

  5. In the honey donuts list, add0to the value associated with Sana (use index from step 1)


Problem 3. Displaying a receipt (6-marks)


Create a function called receipt, which takes five parameters and uses them to display a receipt to the user about their purchase.


Specifically, the receipt function should take the following five parameters:



  1. Name

  2. number of chocolate donuts purchased

  3. number of strawberry donuts purchased

  4. number of vanilla donuts purchased, and

  5. number of honey-drizzled donuts purchased


The function should use these parameters to display a receipt in the following format:



Sana, here is your receipt:


12 Chocolate-dipped Maple Puffs


11 Honey-drizzled Lemon Dutchies


Total cost: $63.89


Thank you, have a nice day!


The receipt function should be called when the user selects the “No more donuts” option from menu2.


Problem 4. Displaying statistics (10-marks)


Create a function called statistics(), which takes no parameters and displays the following statistics about the purchases made using the system.



  1. Number of customers who bought donuts using the system.

  2. Total cost of all chocolate donuts purchased in the system.

  3. Total cost of all strawberry donuts purchased in the system.

  4. Total cost of all vanilla donuts purchased in the system.

  5. Total cost of all honey donuts purchased in the system.


The statistics() function should be called when the user presses q in menu1().

Answered 2 days AfterNov 26, 2021

Answer To: Problem 2. Processing donut selection (24-marks) The system should use multipleListsto maintain a...

Kondalarao answered on Nov 28 2021
110 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here