Pascal Programming

Task 19 Searching Data


Searching refers to the problem of finding a particular element from a list.

Different Techniques of Searching

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
Code No.
           : C13
Item
               : COOKER

Unit Cost          : 450
Quantity
           : 14

Search completed !

More searching (Y/N) : Y

Code no. to search : C@3
Code No.
           : C13
Item
               : COOKER

Unit Cost          : 450
Quantity
           : 14

Code No.           : C33
Item
               : COOKER

Unit Cost          : 285
Quantity
           : 5

Search completed !

More searching (Y/N) : Y

Code no. to search : @@2
Code No.
           : T12
Item
               : TV

Unit Cost          : 2500
Quantity
           : 8

Code No.           : F02
Item
               : FAN

Unit Cost          : 300
Quantity
           : 5

Search completed !

More searching (Y/N) : Y

Code no. to search : A124
Invalid data !

Code no. to search : A1
Invalid data !

Code no. to search : A1A
Invalid data !

Code no. to search : 213
Invalid data !

Code no. to search : A13

Search completed !

More searching (Y/N) : N

CODE NO     ITEM     PRICE   QUANTITY   STOCK VALUE
-------
   --------   -----   --------   -----------
    T12         TV    2500          8         20000
    F02        FAN     300          5          1500
    C13     COOKER     450         14          6300
    R51      RADIO     500          5          2500
    H03     HEATER     270         15          4050
    C33     COOKER     285          5          1425

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

  1. Declare the following Global Constants with suitable value within the main program
  2. Declare the following Global Variables within the main program with the suitable data type (integer, real , char or string[x])
  3. Initialize corresponding arrays and count the number of items within the code table by calling the procedure readdata(no_of_items).
  4. Prompt the user to enter the serached code and display the details of the searched items by calling the procedure searchdata(no_of_items).
  5. If no more searching is needed then display item details and calculate total stock value by calling the procedure disptotal(no_of_items).

Sub-program (procedure)

  1. Details of the procedure readdata
  2. Details of the procedure searchdata
  3. Details of the procedure disptotal
  4. After coding, save your file as t19.pas at the drive S:\www\0507cit\programming\.
  5. Execute your program and fix any problem occurred.
Hosted by www.Geocities.ws

1