COMP1001-Problem Solving in IT Top-Down Design Objective: Upon completion of this lab, you will be able to: How to use top down design to design an Automatic teller machine (ATM) Structure of Top-Down Design in Python: Comp1001 Lab7 Page 1
Example of top-down design Notice that the main program is complete, while the rest of the functions are merely stubbed out. The interface of each function has been defined, i.e. how many and what types of parameters are expected as well as what will be returned, but the functions have not yet been implemented. Comments have been included inside the function definitions as reminders for how we expect to implement them. This program computes the probability of rolling five of a kind with six-sided dice by running a series of simulations and computing the average number of rolls required. Author: Sally CS Major Date: Spring 2011 from random import * def main(): printintro() numtrials = input("enter number of simulations to run: ") avg = simulate(numtrials) print "The average is:", avg print "The probabilty is:", 1/avg def printintro(): Returns: None Purpose: To print an introduction to the user. return def simulate(n): Inputs: An integer n representing the number of simulations to run. Returns: A float representing the average number of rolls required to get five of a kind. Purpose: Simulate n trials of rolling dice and compute the average. # will call simulateonetime n times Comp1001 Lab7 Page 2
return 100.0 def simulateonetime(): Returns: An integer representing the number of rolls required to get five of a kind. Purpose: Simulate one trial and count the number of rolls. # will call rolldice until the result is allsame return 100 def rolldice(n): Inputs: An integer n representing the number of dice to roll. Returns: A list containing the dice rolls of length n. Purpose: Randomly roll n dice. # will call rollone n times return [1] * n def allsame(ls): Inputs: A list of values. Returns: True if all the values in the list are the same. Otherwise False. Purpose: Checks whether the values in a list are equal. # will check that each value is equal to the first value return True def rollone(): Returns: An integer representing the die value between 1 and 6. Purpose: Randomly roll one die. # will use the random library to simulate a die roll return 1 main() Comp1001 Lab7 Page 3
Exercise 1: You are going to implement the login in an ATM. There is an ATM is located at our V building, where the students/staffs can perform some bank transactions without going out of the campus. The ATM has the following functions: Insert the bank card Check the balance Withdraw cash Pay the bills Deposit cheque 1. Insert the bank card a. Verify the card number i. If valid, return True b. If the card is validated, a menu will be prompted to ask users for name and password i. Verify the customer name and password 1. If valid, return True If the validation is True, a menu will be displayed: 2. Check the balance a. Display the balance of b. cheque, saving or credit card (current month and year only) 3. Withdraw cash a. Ask user input the withdrawal amount b. Check the account limit and return True if the amount is within the limit c. If account limit is allowed, give out the options for user to choose different type of dollar banknotes e.g. 100 dollars or 500 dollars. If issuing the banknotes is done, return True d. If the banknotes taken out, update the account after the transaction completed and return e. When the transaction is completed, display the balance and send out the receipt f. Ask user to get the receipt and banknotes and return g. Close all the menu items and return back to insert the bankcard 4. Pay the bills a. Ask user to input the payer s account number b. Ask users to pay from e.g. saving account c. Not allowed to pay from credit card d. Check the account limit and return True if the amount is within the limit e. Update the account after the transaction is completed and return f. When the transaction is completed, display the balance and issue the receipt 5. Deposit cheque a. Ask user to insert the cheque and which account to deposit the cheque b. Remind the customers to write all the info e.g. account no. on the cheque c. Open a box for customers to insert the cheque and return d. Update the account after the transaction is completed and return e. When the transaction is completed, display the balance and send out the receipt Using top down design to create the menu for the vending machine system Design the interface Menu for the ATM Comp1001 Lab7 Page 4
Develop all the functions of the system using Python Write a separate program to test all the function of the system ~End of the lab7~ Comp1001 Lab7 Page 5