{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}


INF1511_2010_SA_03_CalculateDisplay - SELF 1ASSIGNMENT...

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

View Full Document Right Arrow Icon
The following user interface and code calculates and displays the total cost of items selected.  Implement this code and then answer the questions that follow. unit CalculateDisplayCost; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Spin, ExtCtrls; type TfrmCalculateDisplay = class(TForm) btnCalculateDisplay: TButton; rgpProducts: TRadioGroup; sedNumber: TSpinEdit; lblNumber: TLabel; lblCost: TLabel; procedure btnCalculateDisplayClick(Sender: TObject); private { Private declarations } procedure CalculateTotalCost (nNumber : Integer; rCost : Double; var rTotalCost : Double); procedure DisplayTotalCost (sProduct : String; rTotalCost : Double); public { Public declarations } end; var frmCalculateDisplay: TfrmCalculateDisplay; implementation {$R *.dfm} procedure TfrmCalculateDisplay.CalculateTotalCost (nNumber : Integer; rCost : Double; var rTotalCost : Double); begin SELF 1ASSIGNMENT Chapters 1 – 13 (Events, methods, procedures, functions and parameters)
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
rTotalCost := nNumber * rCost; end; procedure TfrmCalculateDisplay.DisplayTotalCost (sProduct : String; rTotalCost : Double); begin lblCost.Caption := IntToStr(sedNumber.value) + ' ' + sProduct + ' costs ' + FloatToStrF(rTotalCost, ffCurrency, 15,2); end; procedure TfrmCalculateDisplay.btnCalculateDisplayClick(Sender: TObject); var sProduct : String; rTotalCost : Double; const rCost = 5.00; begin CalculateTotalCost(sedNumber.Value, rCost, rTotalCost); sProduct := rgpProducts.Items[rgpProducts.ItemIndex]; DisplayTotalCost(sProduct, rTotalCost); end; end. 1.1 Discuss the procedure CalculateTotalCost in terms of the structure of a simple procedure (see page  296).  (3) Procedure tells Delphi that it is a procedure. The class name for this procedure is  TfrmCalculateDisplay The fullstop connects that class name to the procedure name, in this case CalculateTotalCost. After the procedure name, a list of parameters are included in the brackets, in this case  (nNumber : Integer; rCost : Double; var rTotalCost : Double) There are three parameters: there are two value parameters (nNumber is of type integer, and rCost is of type  double), and one var (or reference) parameter (rTotalCost is of type Double). The begin statement tell Delphi that the program statements of the procedure are about to begin. In this  case, there is only one line of code between the begin and the end statements. The code that is executed takes the two input parameter values, calculates the product and then assigns the  answer of the calculation to the reference parameter (i.e. the value is passed back to the calling program!) 1.2 Explain how the use of procedures contributes to a well structured program and the advantages  thereof. (see page 297 and 306)  (3)
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 ]}