Pascal Programming
Task 19 Searching Data
Searching refers to the problem of finding a particular element from a list.
Different Techniques of Searching
| Sequential Search | Binary Search |
| Simple algorithm and easy to implement | Algorithm rather complex |
| The list need not be sorted | The list must be sorted |
| Requires many comparisons | Requires very few comparisons |
| Slow in locating a search value | Very fast in locating a search value |
Using a Module Design technique to write a Pascal program to search for and print the details of stock items held by ABC Electric Appliance Company :
Below are the sample outputs of a Pascal program. In these outputs, the information in purple colour are entered through the keyboard by the user. All other items are output from the program.
Sample Output |
|
| << ABC Electric Appliance Company >> Code no. to search : C13 Search completed ! More searching (Y/N) : Y Code no. to search : C@3 Code No. :
C33 Search completed ! More searching (Y/N) : Y Code no. to search : @@2 Code No. :
F02 Search completed ! More searching (Y/N) : Y Code no. to search : A124 Code no. to search : A1 Code no. to search : A1A Code no. to search : 213 Code no. to search : A13 Search completed ! More searching (Y/N) : N CODE NO ITEM PRICE QUANTITY STOCK
VALUE Total stock value = 35775 |
The follwoing is the content of part of the stock information (fstock.dat) of the company.
fstock.dat |
Description |
||
| T12 TV 2500 8 20000 |
Code number Item Description Price Quantity Stock value |
Main Program
Sub-program (procedure)