Hamid is designing a computerized system for a grocery store. The document provides specifications for subroutines to:
1) Get item input from the user and validate the item ID format.
2) Calculate pricing statistics like average price and minimum/maximum prices for 10 items.
3) Validate the item ID format and return true/false.
4) Apply conditional discounts to prices based on item category and output discounted price.
5) Test the input, validation, and discount application subroutines.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
19 views
Worksheet1 Control Structures
Hamid is designing a computerized system for a grocery store. The document provides specifications for subroutines to:
1) Get item input from the user and validate the item ID format.
2) Calculate pricing statistics like average price and minimum/maximum prices for 10 items.
3) Validate the item ID format and return true/false.
4) Apply conditional discounts to prices based on item category and output discounted price.
5) Test the input, validation, and discount application subroutines.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
Q1. Hamid is designing a computerized system for ABC Grocery shop.
(a) Write program code for a subroutine INPUT( )
That takes ItemID as STRING parameter Inputs ID from the user and assigns it to the ItemID so that it can be updated.
(b) Write program code for a subroutine Expensive that
Uses a precondition loop to input 10 Prices Calculates and outputs the price of the most Expensive Item and Least expensive Item Calculates and returns the Average price
(c) Write a subroutine Validate( ) that
Validates the parameter ItemID according to the following criterion o Must be 9 characters long o Must Start with “ABC” o Last 4 characters must be digits o Remaining characters should be lower case letters Return TRUE if valid, otherwise return FALSE
(d) Write a subroutine ApplyDiscount( )
Takes ItemId as parameter Assume Price is a global variable Local variable TodayDate is assigned Today’s Date using a built-in function Item IDs are divided into the following categories
ItemID ending with Category DiscountRate
7 Décor 10% 8 Stationery 20% 9 Dairy 15% Use Case Structure to apply the appropriate discount rate and calculate the DiscountedPrice. Output DiscountedPrice, category and TodayDate
( e) Hamid writes a subroutine TEST( ) to test some of the modules.
Declare local variable ItemID as String
Calls INPUT Calls validate to check if ItemID is valid or Invalid. If it is Valid Call ApplyDiscount, otherwise display an error message