1 / 13

Practice classwork on structures

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

adie
Download Presentation

Practice classwork on structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Practice classworkonstructures

  2. 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.

  3. Pseudocode - Customer TABLE Customer String name String accNum Real balance END of TABLE

  4. 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.

  5. 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;

  6. 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)

  7. 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

  8. 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)

  9. 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

  10. 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”); }

  11. 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

  12. 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); }

  13. 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.

More Related