1 CSE1301 Computer Programming Lecture 27 Recursion (Part 1)
CSE1301 Computer Programming: Lecture 28 Transaction Processing.
-
date post
20-Dec-2015 -
Category
Documents
-
view
221 -
download
0
Transcript of CSE1301 Computer Programming: Lecture 28 Transaction Processing.
CSE1301 Computer Programming:
Lecture 28Transaction Processing
Topics
• Dataflow Diagrams
• Data structures (structs, arrays)
• Transaction Processing Example – Dataflow Diagram– Structs as parameters
• Reading: Brookshear, 6.4
Structure chart with labels showing data coupling
inviteToParty ( name , date , venue ){ ringUp ( name ) askToParty (date , venue ) sayGoodbye ( name )}
askToParty sayGoodbyeringUp
inviteToParty
name
date
venue
namename
date
venue
control coupling
data coupling
Recall:
Dataflow Diagrams (DFD)
• Pictorial representation of data paths:
– origin (source)
– destination (sink, storage)
– processing points (location of data manipulation, modules)
Dataflow diagram showing data paths
inviteToParty
Mom
Ad
dre
ss B
oo
k
date & venue
name
Invitatio
n List
ringUp
name
phone
Friendgreeting
askToParty
date & venue
date & venue
sayGoodbye
name
salu
tatio
n
Friend
sayGoodbye
ringUp
inviteToParty
askToParty
Mom
Ad
dre
ss B
oo
k
date & venue
name
Invitatio
n List
name
phone
greeting
date & venue
date & venue
name
salu
tatio
n
Arrows: Data Paths
Friend
sayGoodbye
ringUp
inviteToParty
askToParty
Mom
Ad
dre
ss B
oo
k
date & venue
name
Invitatio
n List
name
phone
greeting
date & venue
date & venue
name
salu
tatio
n
Boxes: Data Sources and Sinks
Friend
sayGoodbye
ringUp
inviteToParty
askToParty
Mom
Ad
dre
ss B
oo
k
date & venue
name
Invitatio
n List
name
phone
greeting
date & venue
date & venue
name
salu
tatio
n
Circles (Bubbles): Processing Points
Friend
sayGoodbye
ringUp
inviteToParty
askToParty
Mom
Ad
dre
ss B
oo
k
date & venue
name
Invitatio
n List
name
phone
greeting
date & venue
date & venue
name
salu
tatio
n
Heavy Straight Lines: Data Storage
Friend
sayGoodbye
ringUp
inviteToParty
askToParty
Mom
Ad
dre
ss B
oo
k
date & venue
name
Invitatio
n List
name
phone
greeting
date & venue
date & venue
name
salu
tatio
n
Note: You are not included in the diagram!
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.
Transaction Processing: Dataflow Diagram
• What are the actions / data manipulation?
• What are the data sources / sinks?
• What data is stored?
• Example: ATM Transaction
Example: Transactions
• Actions / Data Processing:– withdraw cash
– transfer funds
– determine balance
– deposit money (??)
– authenticate customer
Authenticate: Algorithm
read card number from ATM cardask the Customer for PIN numbersearch the Customer Database for that card numberif 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
Authenticate: Dataflow Diagram
Authenticate
Customer
PIN
Cu
sto
mer
Dat
abas
e
PIN on record
card number
ATM Card
card number
Transfer
Withdraw
result
& card number
resu
lt
& ca
rd n
umbe
r
Authenticate: Data
struct CustomerIDRec{ long cardNumber; int pin;};
typedef struct CustomerIDRec CustomerID;
• card number– an integer of many digits
• PIN– a 4-digit number
Withdraw: Dataflow Diagram
Withdraw
Customer
account type and amount
Cu
sto
mer
Dat
abas
e
balance
card number and account type result and
card number Authenticate
new balance
cash
Customer Record
• How would you represent a record in the customer database?
struct CustomerRec{ char name[NAMELEN]; long cardNumber; int pin; long chequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance;};
typedef struct CustomerRec Customer;
Customer Record
struct CustomerRec{ char name[NAMELEN]; long cardNumber; int pin; long chequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance;};
typedef struct CustomerRec Customer;
Already defined as: CustomerID
Customer Record
struct CustomerRec{ char name[NAMELEN]; CustomerID id; long chequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance;};
typedef struct CustomerRec Customer;
struct CustomerRec{ char name[NAMELEN]; CustomerID id; long chequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance;};
typedef struct CustomerRec Customer;
Customer RecordProblems:• Cumbersome• How do we know which ones are open?
struct CustomerRec{ char name[NAMELEN]; CustomerID id; Account accounts[2];};
typedef struct CustomerRec Customer;
Customer Recordstruct AccountRec{ int open; /* boolean */ long number; float balance;};
typedef struct AccountRec Account;
struct CustomerRec{ char name[NAMELEN]; CustomerID id; Account accounts[2];};
typedef struct CustomerRec Customer;
Customer Recordstruct AccountRec{ int open; /* boolean */ long number; float balance;};
typedef struct AccountRec Account;
Index determines account type:accounts[0]: cheque accountaccounts[1]: savings account
More scalable!
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”);}
Customer Database
struct DatabaseInfo{ int count; /* Number of records. */ Customer customers[MAXRECORDS];};
typedef struct DatabaseInfo Database;
void printAllbalance ( Database db ){ int i;
for (i=0; i < db.count; i++) { printBalance ( db.customer[i] ); }}
Example 2: printAllBalance
Transaction Data
ATM BANK’SMAINFRAME
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.
ATM BANK’SMAINFRAME
request
response
Transaction Data
Transaction Data
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.
Transaction Data
struct responseRec{ int code; /* 0=ok, 1=wrong pin, 2=no funds, .. */ float amount;};
typdef struct responseRec Response;
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); }
Updating StructsCustomer 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 avoidlong identifies?
new id
Hierarchy and Data Coupling
updateID updateAccountupdateName
updateCustomer
customer
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.
Hierarchy and Data CouplingCustomer 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;}
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
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