130 likes | 285 Views
Practice classwork on structures. Question. The bank requires a system that will store information on their customers. The bank can only facilitate a maximum of 1000 customers . Data stored on EACH customer include: Name Account number Balance
E N D
Question • The bank requires a system that will store information on their customers. The bank can only facilitate a maximum of 1000 customers . • Data stored on EACH customer include: • Name • Account number • Balance Construct the pseudocode statement for the relevant entity.
Pseudocode - Customer TABLE Customer String name String accNum Real balance END of TABLE
Question • The bank requires a system that will store information on their customers. The bank can only facilitate a maximum of 1000 customers . • Data stored on EACH customer include: • Name • Account number (this is 10 characters) • Balance Construct the corresponding C code for the entity.
Pseudocode - Customer C code - Customer TABLE Customer String name String accNum Real balance END of TABLE typedefstruct { char name [30]; char accNum [11]; float balance; }Customer;
Question • The bank requires a system that will store information on their customers. The bank can only facilitate a maximum of 1000 customers . • Data stored on EACH customer include: • Name • Account number (this is 10 characters) • Balance Declare the necessary global variable (first in pseudocode and then in C)
Pseudocode - Customer DECLARE cust AS Customer array of size 1000 DECLARE cindex AS integer C code - Customer //global variables # define SIZE 1000 //no semi-colon for #define Customercust[SIZE]; intcindex; //remember to assign index at 0 in main
Question • The bank requires a system that will store information on their customers. The bank can only facilitate a maximum of 1000 customers . • Data stored on EACH customer include: • Name • Account number (this is 10 characters) • Balance Define the module - addCustomer (first in pseudocode and then in C)
Pseudocode - addCustomer MODULE NAME : addCustomer INPUT : None OUTPUT : None PROCESS : IF cindex < SIZE THEN PRINT “Please enter name of customer and account number” READ cust[cindex].name, cust[cindex].accNum PRINT “Enter starting balance” READ cust[cindex].balance cindex ← cindex + 1 ELSE PRINT “No Space is Available to add another customer. SORRY” ENDIF
C code - addCustomer void addCustomer() { if(cindex < SIZE) { printf(“Please enter name of customer and account number”); gets(cust[cindex].name); gets(cust[cindex].accNum); printf(“Enter starting balance”); scanf(“%f”, &cust[cindex].balance); cindex ++; } else printf(“No Space is Available to add another customer. SORRY”); }
Display the info of all customers MODULE NAME : displayCustomer INPUT : None OUTPUT : None PROCESS : DECLARE i AS integer PRINT “Customer Name Account Number Balance” FOR i← 0 TO cindex-1 DO PRINTLN cust[i].cname, cust[i].accNum, cust[i].balance ENDFOR ENDMODULE
Display the info of all customers void displayCustomer () { inti; printf( “Customer Name \tAccount Number \tBalance”); for(i =0 ; i<=cindex-1; i ++) printf(“%s\t%s\t$%.2f\n”, cust[i].cname, cust[i].accNum, cust[i].balance); }
HOPE YOU ARE OK, NOW • We move on to files next week. • HOME-WORK – due on Tuesday Jan 29, 2013 • Write the pseudocode and corresponding C code for your ENTIRE SYSTEM (except for files). • Page for Tables • Page global variables • Start each module on a new page • The hardcopy is to be submitted at the beginning of class. • Remember to use the online forum and/or email to communicate with me if you have any questions.