COSC 181 Foundations of Computer Programming Class 5 ATM Requirements Spec Introduce you to O O programming with this example Threaded through the next several chapters First Step Gather Requirements ATM allow users to perform basic banking One account per user Users should be able to View balance Withdraw cash Deposit funds Hardware Screen Keypad Cash Dispenser Deposit Slot Key Elements Things learn from talking to the bank managers ATM begins each day stocked with 500 20 bills Each user is asked to type in his own account id All output from ATM occurs on screen Bank wants you to write the software need not worry about hardware interface software first runs on your computer monitor simulates the ATM screen keyboard simulates ATM keypad What are some activities performed at an ATM User Experience Model A K A Use Cases Standard UML Unified Modeling Language Diagram We ll talk about other UML diagrams at the end of today s slides The User Experience 1 2 3 4 5 Screen displays a welcome message and prompts for the account number User enters 5 digit account number ATM asks user to enter PIN User enters 5 digit PIN using the keypad ATM checks Acct PIN combo if valid ATM displays main menu if invalid ATM displays an appropriate message What are the items that should be on the main menu Main Menu Main Menu 1 View my balance 2 Withdraw cash 3 Deposit funds 4 Exit Enter a choice 1 View My Balance ATM displays a screen with the user s balance 2 Withdraw Cash Menu Withdrawal options 1 20 4 100 2 40 5 200 3 60 6 Cancel transaction Choose a withdrawal option 1 6 System States 1 Withdrawal amount greater than balance 2 error message return to previous menu Withdrawal amount less than balance 2 cases if enough money in dispenser debit account and dispense money display message reminding user to take money if not enough money in dispenser display error and return to previous menu 3 Deposit Funds Enter a deposit amount 0 to cancel Again 2 Cases to Consider 3 Deposit amount entered 4 ATM prompts user to insert envelope once envelope inserted ATM credits balance 0 entered ATM returns to previous menu Designing the System 1 Use Case Diagrams 2 Class Diagrams Chapter 3 3 models how the various users will use the system classes define objects each noun described in requirements could be a class State Machine Diagrams Chapter 3 state value of all object attributes models how the classes will interact Continued 1 Activity Diagrams Chapter 5 2 Communication Diagrams Chapter 7 3 models an objects workflow models interaction amongst objects Sequence Diagrams Chapter 7 models when interactions occur between objects GradeBook Class Referencing Fig 3 1 Defining a class Telling the compiler what member functions and data members belong to the class Member Function displayMessage Displays a message on the screen Defining the GradeBook Class Line 9 17 public indicates that the affected GradeBook class definition part of the class members and class GradeBook functions are accessible by functions outside the class i e public main function that displays a message void displayMessage cout Welcome to the Grade Book endl Classes have identifiers just like variables Follow same rules By convention class identifiers begin with a capital letter Uses camel case notation FirstSecond Easier to read Every class is enclosed in with a after the closing bracket Functions void displayMessage is a function main is also a function Unlike main displayMessage is not called automatically Functions perform tasks and might return values What about displayMessage Functions con t void displayMessage void return type displayMessage function name identifier indicates that this is a function By convention first letter lower case Empty parenthesis indicate that no additional data is needed for the function to perform its task all statements in a function appear between braces no semicolon Using the GradeBook class in a program Want to call displayMessage to display the message on the screen Can t call a member function until you create an instance of the class Lines 22 and 23 in Fig 3 1 GradeBook myGradeBook GradeBook type is defined because we included the GradeBook class in the code myGradeBook displayMessage dot operator UML Class Diagrams Classes represented as a rectangle with 3 compartments Classes Name Classes Attributes C Data Members more on this later Classes Operations
View Full Document