Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Similar presentations


Presentation on theme: "CSE1301 Computer Programming: Lecture 28 Transaction Processing."— Presentation transcript:

1 CSE1301 Computer Programming: Lecture 28 Transaction Processing

2 Topics Dataflow Diagrams Data structures (structs, arrays) Transaction Processing Example –Dataflow Diagram –Structs as parameters Reading: Brookshear, 6.4

3 Structure chart with labels showing data coupling inviteToParty ( name, date, venue ) { ringUp ( name ) askToParty (date, venue ) sayGoodbye ( name ) } askToPartysayGoodbyeringUp inviteToParty name date venue name date venue control coupling data coupling Recall:

4 Dataflow Diagrams (DFD) Pictorial representation of data paths: –origin (source) –destination (sink, storage) –processing points (location of data manipulation, modules)

5 Dataflow diagram showing data paths inviteToParty Mom Address Book date & venue name Invitation List ringUp name phone Friend greeting askToParty date & venue sayGoodbye name salutation

6 Friend sayGoodbye ringUpinviteToPartyaskToParty Mom Address Book date & venue name Invitation List name phone greeting date & venue name salutation Arrows: Data Paths

7 Friend sayGoodbye ringUpinviteToPartyaskToParty Mom Address Book date & venue name Invitation List name phone greeting date & venue name salutation Boxes: Data Sources and Sinks

8 Friend sayGoodbye ringUpinviteToPartyaskToParty Mom Address Book date & venue name Invitation List name phone greeting date & venue name salutation Circles (Bubbles): Processing Points

9 Friend sayGoodbye ringUpinviteToPartyaskToParty Mom Address Book date & venue name Invitation List name phone greeting date & venue name salutation Heavy Straight Lines: Data Storage

10 Friend sayGoodbye ringUpinviteToPartyaskToParty Mom Address Book date & venue name Invitation List name phone greeting date & venue name salutation Note: You are not included in the diagram!

11 Dataflow diagrams (DFD) Emphasise the data (information) to flow through system. (rather than procedures to be executed) By following data paths, discover where data units merge, split, are altered.

12 Transaction Processing: Dataflow Diagram What are the actions / data manipulation? What are the data sources / sinks? What data is stored? Example: ATM Transaction

13 Example: Transactions Actions / Data Processing: –withdraw cash –transfer funds –determine balance –deposit money (??) –authenticate customer

14 Authenticate: Algorithm read card number from ATM card ask the Customer for PIN number search the Customer Database for that card number if card number is found { retrieve Customer’s PIN on record if PIN on record matches the PIN keyed in { return card number and PIN Okay } } return BAD card number and PIN

15 Authenticate: Dataflow Diagram Authenticate Customer PIN Customer Database PIN on record card number ATM Card card number Transfer Withdraw result & card number result & card number

16 Authenticate: Data struct CustomerIDRec { longcardNumber; int pin; }; typedef struct CustomerIDRec CustomerID; card number –an integer of many digits PIN –a 4-digit number

17 Withdraw: Dataflow Diagram Withdraw Customer account type and amount Customer Database balance card number and account type result and card number Authenticate new balance cash

18 Customer Record How would you represent a record in the customer database? struct CustomerRec { charname[NAMELEN]; longcardNumber; intpin; longchequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance; }; typedef struct CustomerRec Customer;

19 Customer Record struct CustomerRec { charname[NAMELEN]; longcardNumber; intpin; longchequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance; }; typedef struct CustomerRec Customer; Already defined as: CustomerID

20 Customer Record struct CustomerRec { charname[NAMELEN]; CustomerID id; longchequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance; }; typedef struct CustomerRec Customer;

21 struct CustomerRec { charname[NAMELEN]; CustomerIDid; longchequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance; }; typedef struct CustomerRec Customer; Customer Record Problems: Cumbersome How do we know which ones are open?

22 struct CustomerRec { charname[NAMELEN]; CustomerIDid; Accountaccounts[2]; }; typedef struct CustomerRec Customer; Customer Record struct AccountRec { intopen;/* boolean */ longnumber; floatbalance; }; typedef struct AccountRec Account;

23 struct CustomerRec { charname[NAMELEN]; CustomerIDid; Accountaccounts[2]; }; typedef struct CustomerRec Customer; Customer Record struct AccountRec { intopen; /* boolean */ longnumber; floatbalance; }; typedef struct AccountRec Account; Index determines account type: accounts[0]: cheque account accounts[1]: savings account More scalable!

24 Example 1: printBalance void printBalance ( Customer cust ) { int type; printf(“Customer name: %s\n”, cust.name); for (type=0; type < 2; type++) { if (cust.accounts[type].open) { printf(“Account number: “); printf(“%ld\n”, cust.accounts[type].number); printf(“Balance: “); printf(“%.2f\n”, cust.accounts[type].balance); } } printf(“\n”); }

25 Customer Database struct DatabaseInfo { int count;/* Number of records. */ Customer customers[MAXRECORDS]; }; typedef struct DatabaseInfo Database;

26 void printAllbalance ( Database db ) { int i; for (i=0; i < db.count; i++) { printBalance ( db.customer[i] ); } } Example 2: printAllBalance

27 Transaction Data ATMBANK’S MAINFRAME card number and request for PIN PIN on record card number and request for balance balance card number and balance update confirmation Potential problems with this setup: security, link break-up, traffic.

28 ATMBANK’S MAINFRAME request response Transaction Data

29 struct requestRec { int type; /* 0=balance, 1=withdraw, etc */ CustomerID id; /* card no. and PIN keyed in */ int accountFrom; /* account type */ int accountTo; /* account type */ float amount; }; typdef struct requestRec Request; Disadvantages: Large record, some fields unused. Advantages: Security, processed in mainframe, shorter response, less traffic.

30 Transaction Data struct responseRec { int code; /* 0=ok, 1=wrong pin, 2=no funds,.. */ float amount; }; typdef struct responseRec Response;

31 Transaction Processing Response processRequest ( Request req ) { Response response; if (req.type == 0) response = doBalance(req); else if (req.type == 1) response = doWithdraw(req); else if (req.type == 2) response = doTransfer(req); else /*...and so on... */ return (response); }

32 Updating Structs Customer updateCustomer ( Customer cust ) { printf(“Customer name: %s\n, cust.name); printf(“Enter new card number: “); scanf(“%ld”, &(cust.id.cardNumber)); printf(“Enter new PIN: “); scanf(“%d”, &(cust.id.pin)); return cust; }... cust = updateCustomer(cust);... Can we avoid long identifies?

33 new id Hierarchy and Data Coupling updateIDupdateAccountupdateName updateCustomer customer old account old name old id new name new account The size of the data coupling corresponds roughly to the level of the module in the hierarchy.

34 Hierarchy and Data Coupling Customer updateCustomer ( Customer cust ) { updateName ( cust.name ); cust.id = updateID ( cust.id ); cust.account[0] = updateAccount ( cust.account[0] ); cust.account[1] = updateAccount ( cust.account[1] ); return cust; }

35 Exercise: Dataflow diagram Draw a dataflow diagram depicting the flow of information between a lecturer, a student, and a textbook. Include the fact that an end of semester examination is given. Data sources? –Lecturer, textbook Data storage? –Student memory, notebooks Data manipulation? –Read textbook, compile information, answer questions

36 Summary Dataflow diagrams are an alternative representation of a system. Transaction processing: focus on dataflow and data structures. Combination of: –top down and bottom up; –design tools and techniques. Readings: Brookshear. 6.4, Fig 6-6


Download ppt "CSE1301 Computer Programming: Lecture 28 Transaction Processing."

Similar presentations


Ads by Google