{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}


INF1511_2010_SA_03_FoodCurrency - SELF ASSESSMENT Functions...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
SELF ASSESSMENT – Functions, procedures, parameters Question 1 A program was required to capture the meal orders of the Delphi students attending the FunInTheSun  workshop held recently in Utopia! Consider the following Delphi code and the user interfaces presented. To calculate the  percentage of discount  to allow, the  number of meals and  the number of  beverages are  considered. If  there are more than  ten items, 10%  discount is allowed, if  there are five or  more items then 5%.  If the number of items is less than five, then no discount is given. 1.1 Write the code for the procedure PlaceOrder. The number of meals and the number of beverages  must be passed as input parameters (integers), and the cost of the order as well as the percentage  of discount that was given is retuned as output parameters from the procedure. (5) procedure TfrmMyProcMCQ.PlaceOrder(nMeal, nBev : Integer; var rCost,rDiscount : Double); const MealCost = 12.50; BevCost = 5.00; begin if ((nMeal + nBev) > 10) then rDiscount := 0.1 else if ((nMeal + nBev) > 5) then rDiscount := 0.05 else rDiscount := 0.0; rCost := ((nMeal * MealCost) + (nBev * BevCost)) * (1- rDiscount); end;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
1.2 Write the code for the event handler procedure TfrmMyProcMCQ.btnOrderClick(Sender: TObject); that  includes the procedure call : PlaceOrder(sedMeal.Value, sedBev.Value, rOrderCost, rOrderDiscount); The  results of the procedure call must be displayed in the ListBox. The results of the previous order must first be  cleared! (5) procedure TfrmMyProcMCQ.btnOrderClick(Sender: TObject); var sOrder : String; rOrderCost, rOrderDiscount : Double; nMealIndex, nBevIndex : Integer; begin PlaceOrder(sedMeal.Value, sedBev.Value, rOrderCost, rOrderDiscount); nMealIndex := rgpMeal.ItemIndex; nBevIndex := rgpBev.ItemIndex; lstOrder.Clear; sOrder := IntToStr(sedMeal.value) + ' - ' + rgpMeal.Items[nMealIndex]; lstOrder.Items.Add(sOrder); sOrder := IntToStr(sedBev.value) + ' - ' + rgpBev.Items[nBevIndex];
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}