0% found this document useful (0 votes)
82 views3 pages

9608 w20 PM 22 Pseudocode

This document defines variables and functions to manage product inventory stored in an array. It prompts the user to input product details like item code, description, price, and quantity into arrays. It then validates the item code format and other field values. Valid products are written to a file. Search functions allow looking up products by description, quantity level, item code, and price.

Uploaded by

Adnan Saleem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views3 pages

9608 w20 PM 22 Pseudocode

This document defines variables and functions to manage product inventory stored in an array. It prompts the user to input product details like item code, description, price, and quantity into arrays. It then validates the item code format and other field values. Valid products are written to a file. Search functions allow looking up products by description, quantity level, item code, and price.

Uploaded by

Adnan Saleem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

// The following varibale is used to create the array of a particular size

DECLARE NumberOfItems : INTEGER


PRINT "Enter the number of Items : "
INPUT NumberOfItems

// ItemCode will be having the format of AAA123456- 3 alphabets with 6 numbers


DECLARE ItemCode : ARRAY[1:NumberOfItems] OF STRING
DECLARE ItemDescription : ARRAY[1 : NumberOfItems] OF STRING
DECLARE Price : ARRAY[1 : NumberOfItems] OF REAl
DECLARE NumberInStock : ARRAY[1 : NumberOfItems] OF INTEGER
DECALRE NumberInStockLevel : INTEGER
DECLARE SearchDescription : STRING
DECALRE LineOfText : STRING
DECLARE isAlpha : BOOLEAN
DECALRE isNum : BOOLEAN
DECALRE ItemLenght : INTEGER
DECALRE ItemCodetoSearch : STRING
DECALRE PricetoSearch : STRING

OPENFILE ProductDetails.txt FOR WRITE

FOR INDEX = 1 to NumberOfItems


PRINT "Enter The Item Code"
INPUT ItemCode[INDEX]
PRINT "Enter the Item Desciption"
INPUT ItemDescription[INDEX]
PRINT "Enter the Price"
INPUT Price[INDEX]
PRINT "Enter the Number In Stock
INPUT NumberInStock[INDEX]

// ItemCode validation
isAlpha = FALSE
isAlpha = isAlphabets(LEFT(ItemCode[INDEX],3))

isNum = FALSE
isNum = isNumbers(RIGHT(ItemCode[INDEX],6))

ItemLenght = 0
ItemLenght = LENGHT(ItemCode[INDEX])

IF isAlpha AND isNum AND ItemLenght==9


THEN

ELSE
PRINT "You Have Entered A Invalid ItemCode, Please reenter itemcode"

ENDIF

IF LENGHT(ItemDescription[INDEX]>100)
THEN
PRINT "Item Description Should Be less than 100 characters"
ENDIF

IF Price[INDEX] > 1000000 OR Price[INDEX]<0


THEN
PRINT " Please Enter A Valid Price"
ENDIF
IF NumberInStock[INDEX]>100 OR NumberInStock[INDEX]<0
THEN
PRINT "Please Enter A Valid Number In Stock"
ENDIF

LineOfText = ItemCode[INDEX] & "," & ItemDescription[INDEX] & "," &


Price[INDEX] & "," & NumberInStock[INDEX]
WRITEFILE ProductDetails.txt,LineOfText

NEXT INDEX

PRINT "Enter the Value For search Descrition"


INPUT SearchDescription

FOR INDEX = 1 to NumberOfItems


IF ItemDescription[INDEX]==SearchDescription
THEN
PRINT ItemCode[INDEX]
PRINT ItemDescription[INDEX]
PRINT Price[INDEX]
PRINT NumberInStock[INDEX}
ENDIF
NEXT INDEX

PRINT "Enter the number in stock in level"


INPUT NumbeInStockLevel

FOR INDEX = 1 to NumberOfItems


IF NumberInStock[INDEX] < NumberInStockLevel
THEN
PRINT ItemCode[INDEX]
PRINT ItemDescription[INDEX]
PRINT Price[INDEX]
PRINT NumberInStock[INDEX}
ENDIF
NEXT INDEX

PRINT "Enter the item code to search"


INPUT ItemCodetoSearch

FOR INDEX = 1 to NumberOfItems


IF ItemCode[INDEX] == ItemCodetoSearch
THEN
PRINT ItemCode[INDEX]
PRINT ItemDescription[INDEX]
PRINT Price[INDEX]
PRINT NumberInStock[INDEX}
ENDIF
NEXT INDEX

PRINT "Enter the price to search"


INPUT PricetoSearch
FOR INDEX = 1 to NumberOfItems
IF ItemCode[INDEX] > PricetoSearch
THEN
PRINT ItemCode[INDEX]
PRINT ItemDescription[INDEX]
PRINT Price[INDEX]
PRINT NumberInStock[INDEX}
ENDIF
NEXT INDEX

CLOSEFILE ProductDetails.txt

//this function is used to check whether the givne string is having only alphabets
FUNCTION isAlphabets(ItemNumber : String) RETURNS BOOLEAN
DECLARE Alphabets : ARRAY[1:52] OF CHAR
DECLARE Count : INTEGER
DECLARE isAlphabet : BOOLEAN

isAlphabet = TRUE
Alphabets = ["A","B","C","D","E","F","G","H","]
Count = 0
WHILE ItemNumber[Count] != ""
FOR Index = 1 to 52
IF ItemNumber[Count] != Alphabets[Index] THEN
isAlphabet = FALSE
ENDIF
NEXT Index
Count = Count + 1
END WHILE
RETURN isAlphabet
ENDFUNCTION

//this function tells whether the given string is full of integer


FUNCTION isNumbers(ItemNumber : String) RETURNS BOOLEAN
DECLARE Count : INTEGER
DECALRE Numers : ARRAY[1:10] OF CHAR
DECALRE isNumbers : BOOLEAN

isNumbers = TRUE
Numbers = ["0","1","2","3","4","5","6","7","8","9"]
Count = 0
WHILE ItemNumber[Count] != ""
FOR Index = 1 to 10
IF ItemNumber[Count] != Numbers[Index] THEN
isNumbers = FALSE
ENDIF
NEXT Index
Count = Count + 1
END WHILE
RETURN isNumbers
ENDFUNCTION

You might also like