Tuesday, July 30, 2019

AS Computer Science 9608 October 2019 Pre - Release 22

It's time again for Cambridge AS Examination for October / November 2019 series and for all students preparing for  computer science 9608 subject, here is your pre - release material.

WHile pre-release material provides only a glimpse of the possible problems or tasks in the actual CIE paper, it is best to still answer this pre-release material for mastery and confidence. Answer all tasks using structured English, pseudocode, flowchart, and actual program using the language you are comfortable in like Python, Visual Basic or Delphi Pascal. All the best!

Saturday, March 23, 2019

Serial, Sequential and Random Access File Organization Using Python

Records in a file can be stored in different ways:

  • Serial - records are kept without defined /specific order.They are stored as they happened like how we store deposit/withdrawal transactions. We append them after each other.
  • Sequential - Unlike serial, sequential requires the use of key field (like an ID) and organize them using this ID. 
  • Random - Serial and sequential records may be searched from beginning until the record is found. This cant be possible if we need fast access (like ATM bank query or withdrawal). So, random file requires that we store and search a record in any address (usually defined by a hash function).
See the program code below in Python how records are stored and searched using serial organization in a text file:

Now, using random file organization, we can use binary file to implement random access where seek ( ) is used to locate an address and dump( )  is used to write into the binary file and load( ) to read from the binary file. Know that we can also use text files to implement random and sequential organization. We only use binary file as these are the common file formats used be executable files and other software.

Unlike text files where we use the file mode: w (write), r (read),a (append), binary files use the following file mode: wb (write binary), rb (read binary), rb+ (read and append), you may use other file modes  too.

Writing to binary file:

Reading from binary file:

Please note that unlike text files, binary file keep records in its internal representation, meaning, you may special characters in the file as you open it in a text editor like Notepad.

Now try these and explore.

Friday, March 15, 2019

Palindrome using Recursion in Python

Recursion is one that calls itself.  Any loop can be represented in recursion.

Take for instance the example I wrote to check whether a word is a palindrome or not.

Palindrome is  a word, number, phrase or other sequence of characters which reads the same backward as forward such as madam, racecar or the number 10801.

See how the two functions are implemented, one using ordinary loop and one using recursion.

You can try the code and see whether the words are palindrome or not.

Monday, February 18, 2019

Integrating all Database Modules Using Python

We have done all CRUD operations of inserting records, reading records from the tables, updating records and finally deleting the records if necessary.  Click on the links if you need to review these blog articles.

The modules are all useless if they are called separately and you check your XAMPP SQL database back and forth  to see if changes have indeed happened.

This is now where we create our user interface by having a menu.  Now you may want to create hierarchical menus like the example below.

You can modify this, so, you may just have one main menu only.

 The import commands above are to link your menu to the CRUD modules you have done previously. So, modify the names if your files are named  differently.

Once the menu is shown, the if . . else  condition executed. So, if I choose 1, the insertSalesPerson module found in the file named connectsqlinsertdynamic will be called. 

Remember, however, that once we are done with one module (example Insert), we make sure that our main menu will appear again until we choose to exit.

Now, it is your turn to create the menu interface to call all CRUD modules of insert, read, update and delete database records.