Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18COSC 181 – Foundations of Computer ProgrammingClass 5ATM Requirements Spec.Introduce you to O.O. programming with this exampleThreaded through the next several chaptersFirst Step - Gather RequirementsATM – allow users to perform basic bankingOne account per userUsers should be able toView balanceWithdraw cashDeposit fundsHardwareScreen/Keypad/Cash Dispenser/Deposit SlotKey Elements - Things learn from talking to the bank managersATM 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 softwareneed not worry about hardware interfacesoftware first runs on your computermonitor simulates the ATM screenkeyboard simulates ATM keypadWhat are some activities performed at an ATM?User Experience ModelA.K.A - Use CasesStandard UML (Unified Modeling Language) Diagram. We’ll talk about other UML diagrams at the end of today’s slides.The User Experience1. Screen displays a welcome message and prompts for the account number2. User enters 5 digit account number3. ATM asks user to enter PIN4. User enters 5 digit PIN, using the keypad5. ATM checks Acct#/PIN comboif valid : ATM displays main menuif invalid: ATM displays an appropriate messageWhat are the items that should be on the main menu?Main MenuMain Menu: 1 - View my balance 2 - Withdraw cash 3 - Deposit funds 4 - ExitEnter a choice1 - View My BalanceATM displays a screen with the user’s balance2 - Withdraw Cash (Menu)Withdrawal options:1 - $20 4 - $1002 - $40 5 - $2003 - $60 6 - Cancel transactionChoose a withdrawal option (1-6):System States1. Withdrawal amount greater than balanceerror message : return to previous menu2. Withdrawal amount less than balance(2 cases)if enough money in dispenserdebit account and dispense moneydisplay message reminding user to take moneyif not enough money in dispenserdisplay error and return to previous menu3 - Deposit FundsEnter a deposit amount (0 to cancel): (Again – 2 Cases to Consider)3. Deposit amount enteredATM prompts user to insert envelopeonce envelope inserted ATM credits balance4. 0 enteredATM returns to previous menuDesigning the System1. Use Case Diagramsmodels how the various users will use the system2. Class Diagrams (Chapter 3)classes define objectseach noun described in requirements could be a class3. State Machine Diagrams (Chapter 3)state - value of all object attributesmodels how the classes will interactContinued1. Activity Diagrams (Chapter 5)models an objects workflow2. Communication Diagrams (Chapter 7)models interaction amongst objects3. Sequence Diagrams (Chapter 7)models when interactions occur between objectsGradeBook ClassReferencing Fig 3.1Defining a classTelling the compiler what member functions and data members belong to the classMember FunctiondisplayMessage()Displays a message on the screenDefining the GradeBook ClassLine 9 – 17//GradeBook class definitionclass GradeBook{public://function that displays a messagevoid displayMessage(){cout << “Welcome to the Grade Book!” << endl;}};Classes have identifiers, just like variables Follow same rulesBy convention, class identifiers begin with a capital letter.Uses “camel case” notation FirstSecondEasier to readEvery class is enclosed in { }, with a ; after the closing bracketpublic: indicates that the affected part of the class (members and functions) are accessible by functions outside the class (i.e. – main())Functionsvoid displayMessage() is a functionmain() is also a functionUnlike main(), displayMessage() is not called automaticallyFunctions perform tasks and might return valuesWhat about displayMessage() ?Functions (con’t) void displayMessage()void – return type displayMessage – function name (identifier)By convention, first letter lower-case() – indicates that this is a functionEmpty 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 programWant to “call” displayMessage() to display the message on the screenCan’t call a member function until you create an instance of the classLines 22 and 23 in Fig 3.1GradeBook myGradeBook;“GradeBook” type is defined because we included the GradeBook class in the codemyGradeBook.displayMessage();“dot operator”UML: Class DiagramsClasses represented as a rectangle with 3 compartmentsClasses NameClasses Attributes C++ Data Members (more on this later)Classes
View Full Document