IT Nov 2015 Paper 1 MEMO
IT Nov 2015 Paper 1 MEMO
IT Nov 2015 Paper 1 MEMO
SENIOR CERTIFICATE
GRADE12
INFORMATION TECHNOLOGY P1
NOVEMBER 2015
MEMORANDUM
MARKS: 150
GENERAL INFORMATION:
• These marking guidelines are to be used as the basis for the marking session.
They were prepared for use by markers. All markers are required to attend a
standardisation meeting to ensure that the guidelines are consistently interpreted
and applied in the marking of candidates' work.
• Note that candidates who provide an alternate correct solution to that given as
example of a solution in the marking guidelines will be given full credit for the
relevant answer/solution, unless the specific instructions in the paper was not
followed or the requirements of the question was not met.
• Annexures A, B and C (pages 3–9) include the marking grid for each question
for using either one of the two programming languages.
• Annexures D, E and F (pages 10–19) contain examples of solutions for Java for
Questions 1 to 3 in programming code.
ANNEXURE A
SECTION A
Extract the start weight and height from the text box and
convert both to real/double number
Calculate BMI using the correct formula
Display BMI in the output area formatted to 5 decimals 8
If statements with correct ranges making provision for all
three categories
(<18.5) ( >=18.5 to <=25) and (>25)
Correct messages displayed
TOTAL: 50
ANNEXURE B
SECTION B
2.1.2 Constructor:
Definition with three correct parameters and data types
Assign parameter values to the name and registration
code attributes 5
Use the determineExpDate method with argument to set
the expiry date attribute
Set the sessionsCompleted attribute to 0
2.1.3 setSessionsCompleted
Method definition with parameter
Assign the parameter value to the sessionsCompleted 2
method
NOTE:
There are 2 ways to determine the sessions completed
value for 2 marks.
Method 1: Local variable used to count needs 3 steps: -
• set variable to 0
• increment the variable inside the loop
• call setSessionsCompleted method to set the value.
ANNEXURE C
SECTION C
QUESTION 3: MARKING GRID–PROBLEM-SOLVING PROGRAMMING
NOTE:
Any other method that generates the correct output
without using a loop.
NOTE:
Can also be done using nested loops.
NOTE:
If a flag is used:
• Flagging the correct row 10
• Provide code in the display to accommodate the flag
• Provide code in the water bottle count to
accommodate flag
NOTE:
If original display is called, it must accommodate the
changed array/flagging.
TOTAL: 43
========================================================================
Supplied code
========================================================================
public class Question1_Memo extends javax.swing.JFrame {
public Question1_Memo() {
initComponents();
this.setLocationRelativeTo(this);
fillMemberCodes();
}=======================================================================
// Question 1.1
=======================================================================
private void btnQues1_1ActionPerformed(java.awt.event.ActionEvent evt)
{
double startWeight = Double.parseDouble(txfWeight.getText());
double height = Double.parseDouble(txfHeight.getText());
double bmi = startWeight / (height * height);
String sBmi = String.format("%8.5f",bmi);
txaOutput_1_1.setText("BMI = " + sBmi + "\n");
if (bmi < 18.5) {
txaOutput_1_1.append("Underweight");
} else if (bmi <= 25) {
txaOutput_1_1.append("Normal weight");
} else {
txaOutput_1_1.append("Overweight");
}
}
=====================================================================
// Question 1.2
=====================================================================
private void btnQues1_2ActionPerformed(java.awt.event.ActionEvent evt)
{
int numDays = 0;
double startWeight = Double.parseDouble(txfWeight.getText());
double goalWeight = Double.parseDouble(txfGoalWeight.getText());
if (startWeight > goalWeight) {
txaOutput_1_2.setText("Day\tWeight\n");
while (goalWeight < startWeight) {
numDays++;
startWeight -= 0.375;
txaOutput_1_2.append(numDays + "\t" +
String.format("%6.3f",startWeight) + "\n");
}
} else {
txaOutput_1_2.setText("Invalid value entered");
}
}
======================================================================
// Question 1.3
======================================================================
private void btnQues1_3ActionPerformed(java.awt.event.ActionEvent evt)
{
String name = txfName.getText().toUpperCase();
//OR membershipCode = membershipCode.replaceAll("[AEIOU ]", "");
if (rbnFemale.isSelected()) {
membershipCode += "-F-";
}
if (rbnMale.isSelected()) {
membershipCode += "-M-";
}
if (chbAllergy.isSelected()) {
membershipCode += '*';
}
txfMembershipNumber.setText(membershipCode);
}
======================================================================
// Question 1.4
======================================================================
private void btnQues1_4ActionPerformed(java.awt.event.ActionEvent evt)
{
int randomNumber1 = (int) (Math.random() * 20);
String gender = "-M-";
if (arrMemberCodes[randomNumber1].contains("-F-")) {
gender = "-F-";
}
int randomNumber2;
do {
randomNumber2 = (int) (Math.random() * 20);
} while (arrMemberCodes[randomNumber2].contains(gender));
txaOutput_1_4.setText("Premium members\n");
txaOutput_1_4.append("\n" + arrMemberCodes[randomNumber1]);
txaOutput_1_4.append("\n" + arrMemberCodes[randomNumber2]);
}
=====================================================================
// Question 1.5
=====================================================================
private void btnQues1_5ActionPerformed(java.awt.event.ActionEvent evt)
{
if ((arrMemberCodes[i]).compareTo(arrMemberCodes[j]) > 0) {
String temp = arrMemberCodes[i];
arrMemberCodes[i] = arrMemberCodes[j];
arrMemberCodes[j] = temp;
}
}
}
for (int i = 0; i < 20; i++) {
if (arrMemberCodes[i].contains("*")) {
txaOutput_1_5.append(arrMemberCodes[i] + "\n");
}
}
for (int i = 0; i < 20; i++) {
if (!arrMemberCodes[i].contains("*")) {
txaOutput_1_5.append(arrMemberCodes[i] + "\n");
}
}
}
======================================================================
Supplied code
======================================================================
=======================================================================
// Question 2.1.1
=======================================================================
private String determineExpDate(String regDate) {
int year = Integer.parseInt(regDate.substring(0, 4));
year = year + 2;
========================================================================
// Question 2.1.4
========================================================================
public void increaseSessionsCompleted() {
sessionsCompleted++;
}
=======================================================================
// Question 2.1.5
=======================================================================
public String evaluateProgress(int total) {
double percent = (sessionsCompleted / (double) total) * 100;
if (percent > 75) {
return (name + " qualifies as an instructor");
} else {
return ("Percentage completed: " + String.format("%-2.2f",
percent) + "%");
}
}
=======================================================================
// Question 2.1.6
=======================================================================
public String toString() {
return (name + " [" + regCode + "]\n" + "Expiry Date: " + expiryDate
+ "\nCompleted sessions: " + sessionsCompleted);
}
// Supplied code
=====================================================================
Supplied code
======================================================================
Student objStudent;
=======================================================================
// Question 2.2.1
=======================================================================
private void btnQuestion_2_2_1ActionPerformed(java.awt.event.ActionEventevt)
{
objStudent = new Student(txfStudent.getText(), txfRegCode.getText(),
txfRegDate.getText());
txaOutput.setText(objStudent.toString());
}
======================================================================
// Question 2.2.2
======================================================================
private void btnQuestion_2_2_2ActionPerformed(java.awt.event.ActionEventevt) {
try {
txaOutput.setText("Name of student: " + objStudent.getName() +
"\n");
txaOutput.append(("Dates of completed sessions:"));
========================================================================
// Question 2.2.3
========================================================================
private void btnQuestion_2_2_3ActionPerformed(java.awt.event.ActionEventevt)
{
String completed;
if (chbCompleted.isSelected()) {
completed = "Completed";
objStudent.increaseSessionsCompleted();
} else {
completed = "Not completed";
}
String currentDate = txfTrainingDate.getText();
String line = objStudent.getCode() + " trained on " + currentDate + "#"
+ completed;
try {
PrintWriter outFile = new PrintWriter(new FileWriter("DataQ2.txt",
true));
outFile.println(line);
outFile.close();
JOptionPane.showMessageDialog(null, "Information written to text
file");
} catch (Exception e) {
}
txaOutput.append("\n\n" + objStudent.toString());
}
========================================================================
// Question 2.2.4
========================================================================
private void
btnQuestion2_2_4ActionPerformed(java.awt.event.ActionEventevt) {
int totalSessions = Integer.parseInt(txfTotalSessions.getText());
lblProgress.setText(objStudent.evaluateProgress(totalSessions));
}
=======================================================================
// Declaration of global variable
=======================================================================
int numWorkshops = 6;
=======================================================================
// Display array with headings - call method to display
=======================================================================
private void btnDisplayActionPerformed(java.awt.event.ActionEventevt) {
display();
}
========================================================================
// Make a booking
========================================================================
private void btnBookingActionPerformed(java.awt.event.ActionEvent evt) {
String workshop = cmbWorkshops.getSelectedItem().toString();
int day = lstDays.getSelectedIndex() + 1;
String message = "";
for (int r = 0; r < numWorkshops; r++) {
if (workshop.equals(arrWorkshops[r])) {
for (int c = 0; c < 4; c++) {
if (day == (c + 1)) {
if (arrBookings[r][c] < 20) {
arrBookings[r][c] = arrBookings[r][c] + 1;
display();
JOptionPane.showMessageDialog(null, workshop + " on
Day " + day + " is successfully booked");
}
else {
JOptionPane.showMessageDialog(null, workshop + " on
Day " + day + " is fully booked");
}
}
}
}
}
}
========================================================================
// Calculate cases of bottled water
========================================================================
private void btnWaterActionPerformed(java.awt.event.ActionEvent evt) {
int bottles[] = new int[4];
int totalBottles = 0;
int cases = 0;
for (int c = 0; c < 4; c++) {
for (int r = 0; r < numWorkshops; r++) {
bottles[c] = bottles[c] + arrBookings[r][c];
}
totalBottles = totalBottles + bottles[c];
}
txaOutput.setText("\nBottles of water needed:\n");
for (int r = 0; r < 4; r++) {
txaOutput.append(String.format("Day %-25s%-10s\n", (r + 1),
bottles[r]));
}
double ans = totalBottles % 24;
if (ans == 0) {
cases = totalBottles / 24;
} else {
cases = (totalBottles / 24) + 1;
}
txaOutput.append(String.format("\n%-28s%-10s", "Total: ",
totalBottles));
========================================================================
// Method to display 2-d array with headings
========================================================================
public void display() {
txaOutput.setText(String.format("%-25s", "Workshop"));
for (int i = 1; i <= 4; i++) {
txaOutput.append(String.format("%-10s", "Day " + i));
}
txaOutput.append("\n\n");
for (int r = 0; r < numWorkshops; r++) {
txaOutput.append(String.format("%-25s", arrWorkshops[r]));
for (int c = 0; c < 4; c++) {
txaOutput.append(String.format("%-10s",
arrBookings[r][c]));
}
txaOutput.append("\n");
}
txaOutput.append("\n");
}
unit Question1U_Memo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,Dialogs, StdCtrls, Buttons, ComCtrls, ExtCtrls;
type
TfrmQuestionONE = class(TForm)
bmbClose: TBitBtn;
lblFormHeading: TLabel;
grbQuest11: TGroupBox;
grbQuest12: TGroupBox;
grbQuest13: TGroupBox;
grbQuest14: TGroupBox;
lblHWeight: TLabel;
lblHeight: TLabel;
btnQuestion1_1: TButton;
redQ11: TRichEdit;
edtWeight: TEdit;
edtHeight: TEdit;
lblHWeight2: TLabel;
edtGoalWeight: TEdit;
btnQuestion1_2: TButton;
redQ12: TRichEdit;
lblHName: TLabel;
edtName: TEdit;
rgpGender: TRadioGroup;
grbAllergy: TGroupBox;
chkAllergy: TCheckBox;
lblHCode: TLabel;
btnQuestion1_3: TButton;
edtMembershipCode: TEdit;
btnQuestion1_4: TButton;
redQ14: TRichEdit;
grbQuest15: TGroupBox;
btnQuestion1_5: TButton;
redQ15: TRichEdit;
procedure FormCreate(Sender: TObject);
procedure btnQuestion1_1Click(Sender: TObject);
procedure btnQuestion1_2Click(Sender: TObject);
procedure btnQuestion1_3Click(Sender: TObject);
procedure btnQuestion1_4Click(Sender: TObject);
procedure btnQuestion1_5Click(Sender: TObject);
procedure bmbCloseClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmQuestionONE: TfrmQuestionONE;
implementation
{$R *.dfm}
{$R+}
var
arrMemberCodes: array [1 .. 20] of String;
// ==================================================================
// Question 1.1
// ==================================================================
procedureTfrmQuestionONE.bmbCloseClick(Sender: TObject);
begin
Application.Terminate;
end;
// ==================================================================
// Question 1.2
// ==================================================================
procedure TfrmQuestionONE.btnQuestion1_2Click(Sender: TObject);
var
rWeight, rGoalWeight: Real;
iNumdays: Integer;
begin
redQ12.Clear;
rWeight := StrToFloat(edtWeight.Text);
rGoalWeight := StrToFloat(edtGoalWeight.Text);
iNumdays := 0;
if (rWeight > rGoalWeight) then
begin
redQ12.Lines.Add('Day' + #9 + 'Weight');
while (rWeight > rGoalWeight) do
begin
inc(iNumdays, 1);
rWeight := rWeight - 0.375;
redQ12.Lines.Add(IntToStr(iNumdays) + #9 + FloatToStrF(rWeight,
ffFixed,8, 3));
end; // while
end // if
else
redQ12.Lines.Add('Invalid value entered');
end;
// ==================================================================
// Question 1.3
// ==================================================================
procedure TfrmQuestionONE.btnQuestion1_3Click(Sender: TObject);
var
sMembershipCode, sName: String;
A, iRandom, iNumLetters, iSum: Integer;
sCheckNum : String;
begin
sName := Uppercase(edtName.Text);
sMembershipCode := '';
For A := 1 to Length(sName) do
if NOT(sName[A] IN ['A', 'E', 'I', 'O', 'U', #32]) then
sMembershipCode := sMembershipCode + sName[A];
iNumLetters := length(sMembershipCode);
case rgpGender.ItemIndex of
0: sMembershipCode := sMembershipCode + '-F-';
1: sMembershipCode := sMembershipCode + '-M-';
end;
iRandom := Random(9) + 1;
iSum := iRandom + 10 + iNumLetters;
sCheckNum := IntToStr(iRandom) + IntToStr(iSum);
sMembershipCode := sMembershipCode + sCheckNum;
if chkAllergy.Checked then
sMembershipCode := sMembershipCode + '*';
edtMembershipCode.Text := sMembershipCode;
end;
// ==================================================================
// Question 1.4
// ==================================================================
procedure TfrmQuestionONE.btnQuestion1_4Click(Sender: TObject);
var
iFirst, iSecond : Integer;
sSeekGender : String;
begin
iFirst := Random(20) + 1;
if pos('-M-', arrMemberCodes[iFirst]) = 0 then
sSeekGender := '-M-'
else
sSeekGender := '-F-';
repeat
iSecond := Random(20) + 1;
until (pos(sSeekGender, arrMemberCodes[iSecond]) > 0);
redQ14.Clear;
redQ14.Lines.Add('Premium members' + #13);
redQ14.Lines.Add(arrMemberCodes[iFirst]);
redQ14.Lines.Add(arrMemberCodes[iSecond]);
end;
// ==================================================================
// Question 1.5
// ==================================================================
procedure TfrmVraagEen.btnQuestion1_5Click(Sender: TObject);
var
i, j: Integer;
temp: String;
begin
for i := 1 to 19 do
for j := i + 1 to 20 do
begin
if arrMemberCodes[i] > arrMemberCodes[j] then
begin
temp := arrMemberCodes[i];
arrMemberCodes[i] := arrMemberCodes[j];
arrMemberCodes[j] := temp;
end;
end;
for i := 1 to 20 do
if pos('*', arrMemberCodes[i]) > 0
then redQ15.Lines.Add(arrMemberCodes[i]);
for i := 1 to 20 do
if pos('*', arrMemberCodes[i]) = 0
then redQ15.Lines.Add(arrMemberCodes[i]);
end;
// ==================================================================
procedureTfrmQuestionONE.FormCreate(Sender: TObject);
begin
arrMemberCodes[1] := 'PRTHNMM-M-421';
arrMemberCodes[2] := 'LYYHNBB-F-623*';
arrMemberCodes[3] := 'DFGQWJJK-M-220*';
arrMemberCodes[4] := 'NBVGTYY-F-926';
arrMemberCodes[5] := 'NBGTRFSSD-F-322*';
arrMemberCodes[6] := 'NJKYTRRTG-M-928';
arrMemberCodes[7] := 'JBHGTYGFTR-F-121';
arrMemberCodes[8] := 'HGTYRJJ-F-522*';
arrMemberCodes[9] := 'KJHYTGFDDRWQ-M-830';
arrMemberCodes[10] := 'NHYTRFDDD-M-221*';
arrMemberCodes[11] := 'NBVGTYYGHG-M-424';
arrMemberCodes[12] := 'CVBGFRXXS-M-726';
arrMemberCodes[13] := 'PLIUYHGTRF-M-323';
arrMemberCodes[14] := 'QWDFGENBG-M-423*';
arrMemberCodes[15] := 'RBRTHNDRKS-F-525';
arrMemberCodes[16] := 'MKJHTGFDD-M-625';
arrMemberCodes[17] := 'SDWRQWDDG-F-726';
arrMemberCodes[18] := 'HNGBBVFFDCCS-F-931';
arrMemberCodes[19] := 'NMBGHFDRLP-F-121';
arrMemberCodes[20] := 'BVCZZXGFDJK-M-122';
end;
end.
unit StudentU;
interface
type
TStudent = class(TObject)
private
fName : String;
fRegCode : String;
fExpiryDate : String;
fSessionsCompleted : Integer;
public
constructorCreate(Name, RegCode, RegDate: String);
procedure setSessionsCompleted(iSessions : Integer);
procedure increaseSessionsCompleted;
function evaluateProgress(iMax : Integer) : String;
function toString : String;
function GetName : String;
function GetCode : String;
function GetExpDate: String;
function GetSessionsCompleted: Integer;
end;
implementation
//==========================================================
//Question 2.1.4
//==========================================================
procedure TStudent.increaseSessionsCompleted;
begin
Inc(fSessionsCompleted, 1);
end;
//==========================================================
//Question 2.1.5
//==========================================================
function TStudent.evaluateProgress(iMax: Integer): String;
var
rProgress :Real;
begin
rProgress := (fSessionsCompleted / iMax) * 100;
ifrProgress >= 75 then
Result := fName + ' qualifies as an instructor'
else
Result := 'Percentage completed: ' +
FloatToStrf(rProgress,ffFixed,2,2) + '%';
end;
//==========================================================
//Question 2.1.6
//==========================================================
function TStudent.toString: String;
begin
Result := fName + ' [' + fRegCode + '] ' + #13 +
'Expiry date: ' + fExpiryDate + #13 +
'Completed sessions: ' + IntToStr(fSessionsCompleted);
end;
Result := fSessionsCompleted;
end;
//================================================================
end.
unit Question2U_Memo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, ExtCtrls, StudentU;
type
TfrmQuestionTWO = class(TForm)
bmbClose: TBitBtn;
lblFormHeading: TLabel;
redQ2: TRichEdit;
pnlButtons: TPanel;
btnQuestion222: TButton;
btnQuestion221: TButton;
pnlQ223: TPanel;
btnQuestion223: TButton;
Label1: TLabel;
edtTotalSessions: TEdit;
btnQuestion224: TButton;
pnlProgress: TPanel;
lblProgress: TLabel;
lblCompleted: TLabel;
chkCompleted: TCheckBox;
lblTrainingDate: TLabel;
edtTrainingDate: TEdit;
lblDate: TLabel;
lblRegCode: TLabel;
edtRegCode: TEdit;
edtDate: TEdit;
edtStudent: TEdit;
procedure FormCreate(Sender: TObject);
procedure btnQuestion221Click(Sender: TObject);
procedure btnQuestion222Click(Sender: TObject);
procedure btnQuestion223Click(Sender: TObject);
procedure btnQuestion224Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmQuestionTWO: TfrmQuestionTWO;
implementation
var
objStudent: TStudent;
{$R *.dfm}
{$R+}
//==========================================================
//Question 2.2.1
//==========================================================
procedure TfrmQuestionTWO.btnQuestion221Click(Sender: TObject);
begin
objStudent := TStudent.Create(edtStudent.text, edtRegCode.text,
edtDate.text);
redQ2.Lines.Clear;
redQ2.Lines.Add(objStudent.toString);
end;
//==========================================================
//Question 2.2.2
//==========================================================
procedure TfrmQuestionTWO.btnQuestion222Click(Sender: TObject);
var
TxtFile: Textfile;
sLine, sRegCode, sDate: String;
iCount: Integer;
begin
AssignFile(TxtFile, 'DataQ2.txt');
Reset(TxtFile);
iCount := 0;
redQ2.Clear;
redQ2.Lines.Add('Name of student: ' + objStudent.GetName);
redQ2.Lines.Add('Dates of completed sessions:');
while NOT EOF(TxtFile) do
begin
readln(TxtFile, sLine);
if pos(objStudent.GetCode, sLine) = 1 then
begin
Delete(sLine, 1, pos('on ', sLine) + 2);
sDate := copy(sLine, 1, pos('#', sLine) - 1);
Delete(sLine, 1, pos('#', sLine));
if sLine = 'Completed' then
begin
redQ2.Lines.Add(sDate);
inc(iCount, 1);
end;
end;
end; // while
objStudent.setSessionsCompleted(iCount);
CloseFile(TxtFile);
redQ2.Lines.Add(#10);
redQ2.Lines.Add(objStudent.toString);
btnQuestion223.Enabled := true;
btnQuestion224.Enabled := true;
end;
//==========================================================
//Question 2.2.3
//==========================================================
procedure TfrmQuestionTWO.btnQuestion223Click(Sender: TObject);
var
TxtFile: Textfile;
sLine, sCompleted, sSesDate: String;
begin
sSesDate := edtTrainingDate.text;
AssignFile(TxtFile, 'DataQ2.txt');
Append(TxtFile);
writeln(TxtFile, sLine);
CloseFile(TxtFile);
redQ2.Lines.Clear;
redQ2.Lines.Add(objStudent.toString);
end;
//==========================================================
//Question 2.2.4
//==========================================================
procedure TfrmQuestionTWO.btnQuestion224Click(Sender: TObject);
var
iSessions: Integer;
sProgress: String;
begin
iSessions := StrToInt(edtTotalSessions.text);
sProgress := objStudent.evaluateProgress(iSessions);
lblProgress.Caption := sProgress;
end;
// ==================================================================
// Supplied code
// ==================================================================
procedure TfrmQuestionTWO.FormCreate(Sender: TObject);
begin
btnQuestion223.Enabled := false;
btnQuestion224.Enabled := false;
end;
end.
unit Question3U;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls;
type
TfrmQuestion3 = class(TForm)
pnlClose: TPanel;
bmbClose: TBitBtn;
pnlInput: TPanel;
grpInput: TGroupBox;
lblWorkshopQuestion: TLabel;
lblTopic: TLabel;
lblDay: TLabel;
cboTopic: TComboBox;
lblOutput: TLabel;
lbluserComponents: TLabel;
redDisplay: TRichEdit;
btnDisplay: TButton;
btnBook: TButton;
btnCancelWorkshop: TButton;
btnWater: TButton;
lstDay: TListBox;
Label1: TLabel;
procedure btnDisplayClick(Sender: TObject);
procedure btnBookClick(Sender: TObject);
procedure display;
procedure btnCancelWorkshopClick(Sender: TObject);
procedure btnWaterClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmQuestion3: TfrmQuestion3;
implementation
{$R *.dfm}
{$R+}
CONST
MaxRow: Integer = 6;
MaxCol: Integer = 4;
var
arrWorkshops: Array [1 .. 6] of String = (
'Aerobics',
'Bodybuilding',
'Cardio',
'Dancing',
'Energy Supplements',
'First Aid'
);
Copyright reserved Please turn over
Information Technology/P1 31 DBE/November 2015
NSC – Memorandum
numWorkshops: Integer = 6;
begin
iRemoveLine := 0;
sWorkshop := cboTopic.Text;
for i := 1 to numWorkshops do
if sWorkshop = arrWorkshops[i] then
begin
iRemoveLine := i;
for iWShop := iRemoveLine to numWorkshops - 1 do
arrWorkshops[iWShop] := arrWorkshops[iWShop + 1];
for iDay := 1 to 4 do
for iWShop := iRemoveLine to numWorkshops - 1 do
arrBookings[iWShop, iDay] := arrBookings[iWShop + 1, iDay];
Dec(numWorkshops);
end;
display;
end;
//==========================================================
// Determinethe number of cases of bottled water needed
//==========================================================
procedure TfrmQuestion3.btnWaterClick(Sender: TObject);
var
iWShop, iDay, iTotal, iDayTot: Integer;
sLine: String;
begin
redDisplay.Paragraph.TabCount := 4;
redDisplay.Paragraph.Tab[0] := 156;
redDisplay.Paragraph.Tab[1] := 200;
redDisplay.Paragraph.Tab[2] := 250;
redDisplay.Paragraph.Tab[3] := 300;
redDisplay.Lines.Add('Bottles of water needed:');
iTotal := 0;
for iDay := 1 to 4 do
begin
iDayTot := 0;
for iWShop := 1 to numWorkshops do
iDayTot := iDayTot + arrBookings[iWShop, iDay];
redDisplay.Lines.Add('Day ' + IntToStr(iDay) + #9 + IntToStr(iDayTot));
iTotal := iTotal + iDayTot;
end;
redDisplay.Lines.Add(#10 + 'Total: ' + #9 + IntToStr(iTotal));
redDisplay.Lines.Add('Cases of bottled water needed: ' +
FloatToStr(Round((iTotal/24) + 0.5)));
end;
//==========================================================
// Display
//==========================================================
procedure TfrmQuestion3.display;
var
iWShop, iDay: Integer;
sLine: String;
begin
redDisplay.Clear;
redDisplay.Paragraph.TabCount := 4;
redDisplay.Paragraph.Tab[0] := 150;
redDisplay.Paragraph.Tab[1] := 200;
redDisplay.Paragraph.Tab[2] := 250;
redDisplay.Paragraph.Tab[3] := 300;
redDisplay.Lines.Add
('Workshop' + #9 + 'Day 1' + #9 + 'Day 2' + #9 + 'Day 3' + #9 + 'Day 4' +
#10);
for iWShop := 1 to numWorkshops do
begin
sLine := arrWorkshops[iWShop];
for iDay := 1 to 4 do
sLine := sLine + #9 + IntToStr(arrBookings[iWShop, iDay]);
redDisplay.Lines.Add(sLine);
end;
end;
end.
Copyright reserved