Marking rubric
Question One
1.1 ImgQ1_1.Picture.LoadFromFile('feature.jpg');
ImgQ1_1.Stretch:=true;
pnlQ1_1.Caption:='NEW LIFESTYLE MALL';
pnlQ1_1.Font.Name:='Verdana'; (5)
pnlQ1_1.Font.Style:=[fsbold];
1.2 Declare Const P=3.14
Declare 2 real values
rVol:= rsize*rsize*rsize + 4/3*P*power(rsize/2,3) ; (8)
lblQ1_2.Caption :='Quantity of concrete required: ' +
FloatToStrF(rVol, ffFixed,10,2)+ ' cubic meters';
1.3 Read 2 values from edit boxes
Set a counter to 1
Repeat
Multiply the minimum of the 2 numbers by the counter
Increase i
Until the product mod the maximum of the 2 numbers = 0 (8)
Output the product in the edit box
1.4 Read sGraph from combo box
Extract the number coefficient of ‘a’, convert to integer and store in a
Delete from sgraph position 1 to the position after the position of ‘a’
Convert sgraph to integer and store in c.
Loop from 7 downto 1 (9)
memQ1_4.Lines.Add('('+intTostr(loop) +';'+intTostr(a*loop+c)+')');
1.5 Convert sline to lowercase
Loop from ‘a’ to ‘z’
Begin loop
if loop variable is part of sline set highest to loop variable
end loop
display highest
add space to end of sLine
loop
x:=copy(sline,1,ipos(‘ ‘,sLine)-1);
if pos(h,x)>0 then redQ1_5.Lines.Add(x);
delete(sline,1,ipos);
until length(sline)=0; (10)
40
2.1.1 'SELECT StoreName
FROM tblShops (4)
WHERE Floor = "Upper"
AND StoreType = "Fashion"';
2.1.2 'SELECT Distinct StoreType FROM tblShops';
(2)
2.1.3 'SELECT StoreName, StoreType, Floor FROM tblShops WHERE RiskFactor =
"'+sLevel+'" ORDER BY Floor DESC'; (5)
2.1.4 'SELECT StoreType,format (sum(rentAmount) ,"currency")
AS [Total Rental] ' +
'FROM tblShops,TblRental WHERE (tblRental.ShopID=tblShops.ShopID)
GROUP BY StoreType HAVING sum(rentAmount)>100000'; (8)
2.1.5 'UPDATE tblShops SET ManagerGender = "Male"
WHERE ManagerGender LIKE
"gender%"'; (4)
23
2.2.1 Total:=0;
Countpaid:=0;
CountUnpaid:=0; //initialize 3 counters
tblRental.First;
while not tblRental.Eof do
begin
if tblRental['paid'] then
begin
Total:=Total+tblRental['rentAmount'];
inc(Countpaid);
end
Else
Begin (8)
inc(CountUnpaid);
End;
tblRental.Next;
end;
redQ2_2_1.Lines.Add('Total rental paid: '+floatToStrF(Total,ffCurrency,10,2));
redQ2_2_1.Lines.Add('No. of stores paid: '+inttostr(countPaid));
redQ2_2_1.Lines.Add('No. of stores unpaid: '+intTostr(countUnpaid));
2.2.2 tblShops.First;
while not tblShops.Eof do
begin
if tblShops['StoreName']= sStoreName then
begin
tblRental.First;
while not tblRental.eof do
begin`
if (tblRental['ShopID'] = tblShops['ShopID']) then
begin
redQ2_2_1.Lines.Add(tblShops['ManagerName']+#9+floatTostrF(tblRental['rentAmount'],
ffCurrency,10,2));
end; (9)
tblRental.Next;
end;
end;
tblShops.Next;
end;
end;
17
QUESTION THREE
3.1.1 constructor tBottle.create(sOrd,sTyp: string; fQuantity: integer);
begin
fOrdernum:=sOrd;
fType:=styp;
self.fQuantity:= fQuantity;
fDiscount:=0; (4)
end;
3.1.2 Procedure tBottle.setOrderNum(orderNum:string ); (2)
begin
//3.1.2
fOrdernum:=orderNum;
end;
3.1.3 function tBottle.CalcCases: integer; (5)
begin
//3.1.3
if fType='STILL'
then result := Ceil (fQuantity/24)
Else result := Ceil(fQuantity/12);
end;
3.1.4 procedure tBottle.Calcdiscount; (4)
var temp:integer;
begin
//3.1.4
temp:=fQuantity div 500;
if temp <=5 then
begin
fDiscount:=temp*2;
end
Else
begin
fDiscount:=10;
end;
end;
3.1.5 function tBottle.determineAmount: real; (4)
var Tot : real;
begin
if fType = 'STILL'
then Tot:= CalcCases*89.99
Else tot := CalcCases*59.99;
result:=tot*(100-fDiscount)/100;
end;
3.1.6 procedure tBottle.AdjustQuantity (iNum: integer); (4)
begin
fQuantity:=fQuantity +iNum;
end;
3.1.7 function tBottle.ToString: String; (3)
begin
calcdiscount; calling calcdiscount
result:='OrderNo: '+fOrderNum+#13+'Type: '+fType+#13+
'Quantity: '+intTostr(fQuantity)+' bottles'+
#13+'Charge for: '+intTostr(calccases)+' cases'+#13+ correct datatypes
'Discount: '+ floattostr(fDiscount)+' %'+#13+
'Total: '+floatToStrF(determineAmount,ffCurrency,10,2); correct values
end;
26
3.2.1 procedure TForm1.btnInstantiateClick(Sender: TObject); (4)
var sorder: String;
iQuantity: integer;
sType : String;
begin
sorder:=edtOrderNum.Text; read 3 values correctly
iQuantity:=sedQuantity.Value;
sType:=uppercase(rgpChoice.Items[rgpChoice.ItemIndex]);
objBottle :=tBottle.create (sorder,stype,iQuantity); 3 parameters in correct
order
showmessage('Object created');
end;
3.2.2 procedure TForm1.btnShowClick(Sender: TObject); (2)
begin
//3.2.2
redQ3_2.Lines.Add (objBottle.ToString );
end;
3.3.3 procedure TForm1.btnAdjustClick(Sender: TObject); (5)
var nQuant, diff :integer;
begin
//3.2.3
nQuant:= strToint(edtNewQuantity.Text);
diff := nQuant-objBottle.getQuantity;
objBottle.AdjustQuantity(diff);
redQ3_2.lines.Add('CORRECTED INVOICE');
redQ3_2.Lines.Add(objBottle.ToString);
end;
3.2.4 procedure TForm1.btnSubmitClick(Sender: TObject); (5)
var lFile: textFile;
begin
//3.2.4
AssignFile(lFile,'Invoice.txt');
Rewrite(lFile);
Writeln(lFile,objBottle.ToString);
closefile(lfile);
PnlMessage.Caption:='Invoice submitted';
end
16
QUESTION FOUR
4.1 procedure TForm1.Q4_1_btnLoadGuardsClick(Sender: TObject);
var
r, c, count: integer;
begin
count := 0; (7)
for r := 1 to 3 do
begin
for c := 1 to 4 do
begin
inc(count);
arrEntrances[r, c] := arrNames[count];
end;
end;
Showmessage('Roster populated');
end;
4.2 procedure TForm1.Q4_2_btnDisplayRosterClick(Sender: TObject);
var
r, c: integer; (6)
sLine: string;
begin
RedQ4Display.Lines.Add(#9 + 'Ent 1' + #9 + 'Ent 2' + #9 + 'Ent 3' + #9 +
'Ent 4');
for r := 1 to 3 do
begin
sLine := 'Level ' + inttostr(r - 1) + #9;
for c := 1 to 4 do
begin
sLine := sLine + arrEntrances[r, c] + #9;
end;
RedQ4Display.Lines.Add(sLine);
end;
RedQ4Display.Lines.Add('');
end;
4.3 procedure TForm1.Q4_3_btnReverseClick(Sender: TObject); (8)
var
r, c, m: integer;
temparr : array[1..4] of String;
begin
for r := 1 to 3 do
begin
for c := 1 to 4 do
begin
temparr[c]: =arrEntrances[r,5-c]; //reverse row in temparr
end;
for m := 1 to 4 do
begin
arrEntrances[r,m] :=temparr[m]; //assign temparr to row
end;
end;
end;
4.4 procedure TForm1.Q4_4_btnLeaveClick(Sender: TObject); (7)
var r,c,x : integer;
sLine: string;
begin
for r := 1 to 3 do
begin
x := random(4) + 1;
arrEntrances[r, x] := 'X';
RedQ4Display.Lines.Add('level ' + inttostr(r - 1) + ' Entrance ' + inttostr (x) + ' is
closed');
end;
end;
28
Question1_U;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, Spin,Math, jpeg;
type
TfrmQuestion1 = class(TForm)
grpQ1_1: TGroupBox;
btnQ1_1: TButton;
pnlQ1_1: TPanel;
grpQ1_2: TGroupBox;
lbl1: TLabel;
lblQ1_2: TLabel;
btnQ1_2: TButton;
sedQ1_2: TSpinEdit;
grpQ1_3: TGroupBox;
lblQ1_3_1: TLabel;
lblQ1_3_2: TLabel;
lblQ1_3: TLabel;
edtQ1_3_1: TEdit;
edtQ1_3_2: TEdit;
btnQ1_3: TButton;
edtQ1_3: TEdit;
grpQ1_4: TGroupBox;
btnQ1_4: TButton;
grpQ1_5: TGroupBox;
redQ1_5: TRichEdit;
btnQ1_5: TButton;
lblLabel: TLabel;
cmbGraph: TComboBox;
memQ1_4: TMemo;
ImgQ1_1: TImage;
procedure btnQ1_5Click(Sender: TObject);
procedure btnQ1_4Click(Sender: TObject);
procedure btnQ1_1Click(Sender: TObject);
procedure btnQ1_2Click(Sender: TObject);
procedure btnQ1_3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmQuestion1: TfrmQuestion1;
implementation
{$R *.dfm}
procedure TfrmQuestion1.btnQ1_1Click(Sender: TObject);
begin
ImgQ1_1.Picture.LoadFromFile('feature.jpg');
ImgQ1_1.Stretch:=true;
pnlQ1_1.Caption:='NEW LIFESTYLE MALL';
pnlQ1_1.Font.Name:='Verdana';
pnlQ1_1.Font.Style:=[fsbold];
end;
procedure TfrmQuestion1.btnQ1_2Click(Sender: TObject);
const P = 3.14;
var
rVol,rsize : real;
begin
//=================Provided Code ==========================
rsize:=sedQ1_2.Value/100;
//=======================================================
rVol:= rsize*rsize*rsize + 4/3*P*power(rsize/2,3);
lblQ1_2.Caption:='Quantity of concrete required: ' +
FloatToStrF(rVol, ffFixed,10,2)+ ' cubic meters';
end;
procedure TfrmQuestion1.btnQ1_3Click(Sender: TObject);
var num1,num2,Lcm,multiple, i : integer;
begin
num1 := strToint((edtQ1_3_1.Text));
num2 := strToint((edtQ1_3_2.Text));
i:=1;
repeat
multiple := min(num1,num2)*i;
inc(i);
until (multiple mod max(num1,num2)=0);
edtQ1_3.Text:=intTostr(multiple);
end;
procedure TfrmQuestion1.btnQ1_4Click(Sender: TObject);
var a, c ,p : integer;
sgraph,sLine : string;
i: Integer;
j: Integer;
begin
// Provided code
memQ1_4.Lines.Clear;
// Question 1.4
sgraph:= cmbGraph.Text;
p := pos('a',sgraph);
a:=strToint(copy(sGraph,1,p-1));
delete(sgraph,1,p+1);
p:=pos(' ', sgraph);
delete(sgraph,1,p);
c:=strToint(sGraph);
for i := 7 downto 1 do
begin
memQ1_4.Lines.Add('('+intTostr(i)+';'+intTostr(a*i+c)+')');
end;
end;
procedure TfrmQuestion1.btnQ1_5Click(Sender: TObject);
var sText,x,sLine: string;
isize,iPos, icount:integer;
j: Integer;
k,h: char;
begin
//Provided code
redQ1_5.Clear;
sText := InputBox('','Enter sentence','Coding is a necessity for every child.');
isize := length(sText);
sline:=lowercase(sText);
for k := 'a' to 'z' do
begin
if pos(k,sline)>0 then h:=k;
end;
redQ1_5.Lines.Add('Highest letter: '+h);
redQ1_5.Lines.Add('Words that contain the highest letter: ');
sline:=sLine+' ';
repeat
ipos := pos(' ',sline);
x:=copy(sline,1,ipos-1);
if pos(h,x)>0 then redQ1_5.Lines.Add(x);
delete(sline,1,ipos);
until length(sline)=0;
end;
end.
unit Question2_U;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, ConnectDB_U, DB, ADODB, Grids,
DBGrids, ComCtrls, DateUtils, DBCtrls, Spin;
type
TfrmDBQuestion2 = class(TForm)
pnlBtns: TPanel;
bmbClose: TBitBtn;
bmbRestoreDB: TBitBtn;
pnlQDB: TPanel;
pgcDBAdmin: TPageControl;
tabsQ2SQL: TTabSheet;
btnQ2_1_5: TBitBtn;
grpresults: TGroupBox;
dbgrdSQL: TDBGrid;
btnQ2_1_1: TBitBtn;
btnQ2_1_2: TBitBtn;
grpQ2: TGroupBox;
btnQ2_1_3: TBitBtn;
cmbQ2_1_3: TComboBox;
btnQ2_1_4: TButton;
b: TTabSheet;
grpQ2_2_1: TGroupBox;
redQ2_2_1: TRichEdit;
btnQ2_2_1: TButton;
dbgrdONE: TDBGrid;
dbgrdMany: TDBGrid;
grpQ2_2_2: TGroupBox;
btnQ2_2_2: TButton;
cmbQ2_2_2: TComboBox;
procedure bmbRestoreDBClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnQ2_1_1Click(Sender: TObject);
procedure btnQ2_1_2Click(Sender: TObject);
procedure btnQ2_1_3Click(Sender: TObject);
procedure btnQ2_1_4Click(Sender: TObject);
procedure btnQ2_1_5Click(Sender: TObject);
procedure btnQ2_2_1Click(Sender: TObject);
procedure btnQ2_2_2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
end;
var
frmDBQuestion2: TfrmDBQuestion2;
dbCONN: TConnection;
// --- Global variables to be used ---
tblShops, tblRental: TADOTable;
implementation
{$R *.dfm}
{$R+}
// =====================================================
// Question 2.1 - SQL SECTION
// =====================================================
// {$REGION 'Question 2.1'}
// =====================================================
procedure TfrmDBQuestion2.btnQ2_1_1Click(Sender: TObject);
var
sSQL1: String;
begin
// Question 2.1.1
sSQL1 := 'SELECT StoreName FROM tblShops WHERE Floor = "Upper" AND StoreType = "Fashion"';
// Provided code
dbCONN.RunSQL(sSQL1);
end;
// ===================================== ================
procedure TfrmDBQuestion2.btnQ2_1_2Click(Sender: TObject);
var
sSQL2: String;
begin
// Question 2.1.2
sSQL2 := 'SELECT Distinct StoreType FROM tblShops';
// Provided code
dbCONN.RunSQL(sSQL2);
end;
// =====================================================
procedure TfrmDBQuestion2.btnQ2_1_3Click(Sender: TObject);
var
sSQL3, sLevel : String;
begin
//Provided code
sLevel := cmbQ2_1_3.Text;
// Question 2.1.3
sSQL3 := 'SELECT StoreName, StoreType, Floor FROM tblShops WHERE RiskFactor = "'+sLevel+'" ORDER
BY Floor DESC';
// Provided code
dbCONN.RunSQL(sSQL3);
end;
// =====================================================
procedure TfrmDBQuestion2.btnQ2_1_4Click(Sender: TObject);
var
sSQL4: String;
begin
// Question 2.1.4
sSQL4 := 'SELECT StoreType,format(sum(rentAmount),"currency") AS [Total Rental] ' +
'FROM tblShops,TblRental WHERE (tblRental.ShopID=tblShops.ShopID) GROUP BY StoreType HAVING
sum(rentAmount)>100000';
// Provided code
dbCONN.RunSQL(sSQL4);
end;
// =====================================================
procedure TfrmDBQuestion2.btnQ2_1_5Click(Sender: TObject);
var
sSQL5: String;
bChanged: Boolean;
begin
// Question 2.1.5
sSQL5 := 'UPDATE tblShops SET ManagerGender = "Male" WHERE ManagerGender LIKE "gender%"';
// Provided code
dbCONN.ExecuteSQL(sSQL5,bChanged);
if bChanged then
ShowMessage('Records were updated.')
else ShowMessage('Records were not updated.');
end;
// =====================================================
// {$ENDREGION}
// =====================================================
// Question 2.2 - Delphi code section
// =====================================================
// {$REGION 'QUESTION 2.2'}
// =====================================================
procedure TfrmDBQuestion2.btnQ2_2_1Click(Sender: TObject);
var Total : real;
Countpaid, CountUnpaid: integer;
begin
// Question 2.2.1
Total:=0;
Countpaid:=0;
CountUnpaid:=0;
tblRental.First;
while not tblRental.Eof do
begin
if tblRental['paid'] then
begin
Total:=Total+tblRental['rentAmount'];
inc(Countpaid);
end
Else
Begin
inc(CountUnpaid);
End;
tblRental.Next;
end;
redQ2_2_1.Lines.Add('Total rental paid: '+floatToStrF(Total,ffCurrency,10,2));
redQ2_2_1.Lines.Add('No. of stores paid: '+inttostr(countPaid));
redQ2_2_1.Lines.Add('No. of stores unpaid: '+intTostr(countUnpaid));
// Provided code
dbCONN.SetupGrids(dbgrdONE, dbgrdMany, dbgrdSQL);
end;
// =====================================================
procedure TfrmDBQuestion2.btnQ2_2_2Click(Sender: TObject);
var sStoreName : string;
begin
sStoreName := cmbQ2_2_2.Text;
// Question 2.2.2
tblShops.First;
while not tblShops.Eof do
begin
if tblShops['StoreName']= sStoreName then
begin
tblRental.First;
while not tblRental.eof do
begin
if (tblRental['ShopID'] = tblShops['ShopID']) then
begin
redQ2_2_1.Lines.Add(tblShops['ManagerName']+#9+floatTostrF(tblRental['rentAmount'],ffCurrency,10,
2));
end;
tblRental.Next;
end;
end;
tblShops.Next;
end;
end;
// =====================================================
// =====================================================
// {$ENDREGION}
// =====================================================
// {$REGION 'Provided code: Setup DB connections - DO NOT CHANGE!'}
// =====================================================
procedure TfrmDBQuestion2.bmbRestoreDBClick(Sender: TObject);
begin
// Restore the Database
dbCONN.RestoreDatabase;
redQ2_2_1.Clear;
dbCONN.SetupGrids(dbgrdONE, dbgrdMany, dbgrdSQL);
end;
// =====================================================
procedure TfrmDBQuestion2.FormClose(Sender: TObject;
var Action: TCloseAction);
begin // Disconnect from database and close all open connections
dbCONN.dbDisconnect;
end;
procedure TfrmDBQuestion2.FormCreate(Sender: TObject);
begin
redQ2_2_1.Paragraph.TabCount := 4;
redQ2_2_1.Paragraph.Tab[0] := 70;
redQ2_2_1.Paragraph.Tab[1] := 150;
redQ2_2_1.Paragraph.Tab[2] := 300;
redQ2_2_1.Paragraph.Tab[3] := 400;
end;
// =====================================================
procedure TfrmDBQuestion2.FormShow(Sender: TObject);
begin // Sets up the connection to database and opens the tables.
dbCONN := TConnection.Create;
dbCONN.dbConnect;
tblShops := dbCONN.tblOne;
tblRental := dbCONN.tblMany;
dbconn.RunSQL('SELECT * FROM tblRental');
dbCONN.SetupGrids(dbgrdONE, dbgrdMany, dbgrdSQL);
pgcDBAdmin.ActivePageIndex := 0;
end;
// =====================================================
// {$ENDREGION}
end.
unit bottle_U;
interface
uses SysUtils,Math;
Type
tBottle = class(tObject)
private
fOrdernum,fType: string;
fQuantity : integer;
fDiscount: real;
Public
//Provided Code
function getDiscount:real;
function getType:String;
function getQuantity:integer;
//==============================
Constructor create(sOrd,sTyp:string;fQuantity:integer);
Procedure AdjustQuantity(iNum:integer);
Procedure setOrderNum(orderNum:string);
Procedure Calcdiscount;
function CalcCases:integer;
function determineAmount : real;
function ToString:String;
end;
implementation
{ tBottle }
constructor tBottle.create(sOrd,sTyp: string; fQuantity: integer);
begin
//3.1.1
fOrdernum:=sOrd;
fType:=styp;
self.fQuantity:= fQuantity;
fDiscount:=0;
end;
Procedure tBottle.setOrderNum(orderNum:string);
begin
//3.1.2
fOrdernum:=orderNum;
end;
function tBottle.CalcCases: integer;
begin
//3.1.3
if fType='STILL' then result := Ceil(fQuantity/24)
Else result := Ceil(fQuantity/12);
end;
procedure tBottle.Calcdiscount;
var temp:integer;
begin
//3.1.4
temp:=fQuantity div 500;
if temp <=5 then
begin
fDiscount:=temp*2;
end
Else
begin
fDiscount:=10;
end;
end;
function tBottle.determineAmount: real;
var Tot : real;
begin
//3.1.5
if fType = 'STILL' then Tot:= CalcCases*89.99
Else tot := CalcCases*59.99;
result:=tot*(100-fDiscount)/100;
end;
procedure tBottle.AdjustQuantity(iNum: integer);
begin
//3.1.6
fQuantity:=fQuantity+iNum;
end;
function tBottle.ToString: String;
begin
//3.1.7
calcdiscount;
result:='OrderNo: '+fOrderNum+#13+'Type: '+fType+#13+
'Quantity: '+intTostr(fQuantity)+' bottles'+
#13+'Charge for: '+intTostr(calccases)+' cases'+#13+
'Discount: '+ floattostr(fDiscount)+' %'+#13+
'Total: '+floatToStrF(determineAmount,ffCurrency,10,2);
end;
//Provided code : do to alter
function tBottle.getQuantity: integer;
begin
result:=fQuantity;
end;
function tBottle.getType: String;
begin
result:=fType;
end;
function tBottle.getDiscount: real;
begin
result:=fDiscount;
end;
end.
unit BottledWater;
//Name:
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls,bottle_U, Spin;
type
TForm1 = class(TForm)
edtOrderNum: TEdit;
sedQuantity: TSpinEdit;
rgpChoice: TRadioGroup;
redQ3_2: TRichEdit;
btnShow: TButton;
btnInstantiate: TButton;
btnAdjust: TButton;
Q3_2_1: TGroupBox;
lblOrder: TLabel;
lblQuantity: TLabel;
Q3_2_2: TGroupBox;
GroupBox1: TGroupBox;
edtNewQuantity: TEdit;
Label1: TLabel;
Q3_2_4: TGroupBox;
btnSubmit: TButton;
PnlMessage: TPanel;
procedure btnShowClick(Sender: TObject);
procedure btnInstantiateClick(Sender: TObject);
procedure btnAdjustClick(Sender: TObject);
procedure btnSubmitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
objBottle: tBottle;
implementation
{$R *.dfm}
procedure TForm1.btnInstantiateClick(Sender: TObject);
var sorder: String;
iQuantity: integer;
sType : String;
begin
//3.2.1
sorder:=edtOrderNum.Text;
iQuantity:=sedQuantity.Value;
sType:=uppercase(rgpChoice.Items[rgpChoice.ItemIndex]);
objBottle :=tBottle.create(sorder,stype,iQuantity);
showmessage('Object created');
end;
procedure TForm1.btnShowClick(Sender: TObject);
begin
//3.2.2
redQ3_2.Lines.Add(objBottle.ToString);
end;
procedure TForm1.btnAdjustClick(Sender: TObject);
var nQuant, diff :integer;
begin
//3.2.3
nQuant:= strToint(edtNewQuantity.Text);
diff := nQuant-objBottle.getQuantity;
objBottle.AdjustQuantity(diff);
redQ3_2.lines.Add('CORRECTED INVOICE');
redQ3_2.Lines.Add(objBottle.ToString);
end;
procedure TForm1.btnSubmitClick(Sender: TObject);
var lFile: textFile;
begin
//3.2.4
AssignFile(lFile,'Invoice.txt');
Rewrite(lFile);
Writeln(lFile,objBottle.ToString);
closefile(lfile);
PnlMessage.Caption:='Invoice submitted';
end;
end.
unit Mall_U;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Math;
type
TForm1 = class(TForm)
RedQ4Display: TRichEdit;
Q4_2_btnDisplayRoster: TButton;
Q4_3_btnReverse: TButton;
Q4_1_btnLoadGuards: TButton;
Q4_4_btnLeave: TButton;
procedure Q4_1_btnLoadGuardsClick(Sender: TObject);
procedure Q4_2_btnDisplayRosterClick(Sender: TObject);
// procedure Q4_3_btnShowGuardsClick(Sender: TObject);
procedure Q4_3_btnReverseClick(Sender: TObject);
procedure Q4_4_btnLeaveClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
arrNames: array [1 .. 12] of string = (
'Simon',
'Lungi',
'Chris',
'Gary',
'Tony',
'Carol',
'Moses',
'Mbali',
'Wilson',
'Nick',
'Berry',
'Blade'
);
arrEntrances: array [1 .. 3, 1 .. 4] of String;
implementation
{$R *.dfm}
procedure TForm1.Q4_1_btnLoadGuardsClick(Sender: TObject);
var
r, c, count: integer;
begin
count := 0;
for r := 1 to 3 do
begin
for c := 1 to 4 do
begin
inc(count);
arrEntrances[r, c] := arrNames[count];
end;
end;
Showmessage('Roster populated');
end;
procedure TForm1.Q4_2_btnDisplayRosterClick(Sender: TObject);
var
r, c: integer;
sLine: string;
begin
RedQ4Display.Lines.Add(#9 + 'Ent 1' + #9 + 'Ent 2' + #9 + 'Ent 3' + #9 +
'Ent 4');
for r := 1 to 3 do
begin
sLine := 'Level ' + inttostr(r - 1) + #9;
for c := 1 to 4 do
begin
sLine := sLine + arrEntrances[r, c] + #9;
end;
RedQ4Display.Lines.Add(sLine);
end;
RedQ4Display.Lines.Add('');
end;
procedure TForm1.Q4_3_btnReverseClick(Sender: TObject);
var
r, c, m: integer;
temparr : array[1..4] of String;
begin
for r := 1 to 3 do
begin
for c := 1 to 4 do
begin
temparr[c]:=arrEntrances[r,5-c];
end;
for m := 1 to 4 do
begin
arrEntrances[r,m]:=temparr[m];
end;
end;
end;
procedure TForm1.Q4_4_btnLeaveClick(Sender: TObject);
var r,c,x : integer;
sLine: string;
begin
for r := 1 to 3 do
begin
x := random(4) + 1;
arrEntrances[r, x] := 'X';
RedQ4Display.Lines.Add('level ' + inttostr(r - 1) + ' Entrance ' + inttostr
(x) + ' is closed');
end;
end;
end.