0% found this document useful (0 votes)
9 views5 pages

IT Grade 11 Term 2 TextFile2 MEMO

This document serves as a teacher guide for remote learning exercises and worksheets in IT for Grade 11, focusing on solution development with text files. It includes several programming procedures for handling text files, such as reading, writing, and processing data, along with error handling and output formatting. The guide provides detailed examples and memoranda for different programs related to file operations.

Uploaded by

maluleke2006
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
9 views5 pages

IT Grade 11 Term 2 TextFile2 MEMO

This document serves as a teacher guide for remote learning exercises and worksheets in IT for Grade 11, focusing on solution development with text files. It includes several programming procedures for handling text files, such as reading, writing, and processing data, along with error handling and output formatting. The guide provides detailed examples and memoranda for different programs related to file operations.

Uploaded by

maluleke2006
Copyright
© © All Rights Reserved
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/ 5

___________________________________________________________________________

REMOTE LEARNING EXERCISES/WORKSHEETS

EXERCISES AND MEMORANDA

Teacher Guide

SUBJECT: _____IT________________

GRADE:__________11_________

TOPIC/S: Solution Development – Text Files

Week/s:_____4__________
Memorandum - TextFiles
procedure TfrmPassword.btnExecuteClick(Sender: TObject);
var outputfile : textfile;
sUsername, sPassword: string;
begin
//input
sUsername := edtUsername.Text;
sPassword := edtPassword.Text;
//process
assignfile(outputfile,'store.txt');
rewrite(outputfile);
//output
writeln(outputfile, sUsername + ','
+ spassword+','
+ datetostr(now()));
closefile(outputfile);
end;

program 1 - memorandum.zip
MEMORANDUM DATA FILES
(8)

2 procedure TfrmProgram2.btnDisplayClick(Sender: TObject);


var
inputfile: textfile;
icount: integer;
sLine: string;
sName, sSurname: string;
rAve: real;
rSales: real;
// highest and lowest
// averge
rhigh, rlow, rsum: real;
sHigh, sLow: string;
begin
// validation
if not(FileExists('sales.txt')) then
begin
MessageDlg('Error in opening file', mtError, [mbok], 0);
exit;
end;
// input
assignfile(inputfile, 'sales.txt');
reset(inputfile);
icount := 0;
rsum := 0;
// process
while not eof(inputfile) do
begin
readln(inputfile, sLine);
inc(icount);
sName := copy(sLine, 1, pos('#', sLine) - 1);
delete(sLine, 1, pos('#', sLine));
sSurname := copy(sLine, 1, pos('#', sLine) - 1);
delete(sLine, 1, pos('#', sLine));
rSales := strtofloat(sLine);
// output of data to the output
redOut.Lines.Add(#9 + sName + #9 + sSurname + #9 +
floattostr(rSales));
// determine the highest and lowest
if icount = 1 then
begin
rhigh := rSales;
rlow := rSales;
sHigh := sName + #9 + sSurname;
sLow := sName + #9 + sSurname;
end
else
begin
if rSales > rhigh then
begin
rhigh := rSales;
sHigh := sName + #9 + sSurname;
end
else if rSales < rlow then
begin
rlow := rSales;
sLow := sName + #9 + sSurname;
end
end;
// determines the average
rsum := rsum + rSales;
end;

closefile(inputfile);
// output of the highest and lowest
redOut.Lines.Add(#9 + 'Highest sales is :' + sHigh + ' with an amount of
'+
floattostrf(rhigh, ffcurrency, 10, 2));
redOut.Lines.Add(#9 + 'Lowest sales is :' + sLow + ' with an amount of '
+
floattostrf(rlow, ffcurrency, 10, 2));
// output of the average sales
redOut.Lines.Add('Average sales are: ' + floattostrf(rsum / icount,
ffcurrency, 10, 2));
end; (35)

program 2 - memorandum.zip
MEMORANDUM DATA FILES
3 procedure TfrmProgram3.btnDisplayClick(Sender: TObject);
var
sLine: string;
inputfile: textfile;
rAve, rsum: real;
icount: integer;
sName, sSurname: string;
begin
if not(FileExists('sales.txt')) then
begin
MessageDlg('Error in opening file', mtError, [mbok], 0);
exit;
end;
assignfile(inputfile, 'sales.txt');
reset(inputfile);
while not(eof(inputfile)) do
begin
readln(inputfile, sLine);
sName := copy(sLine, 1, pos(',', sLine) - 1);
delete(sLine, 1, pos(',', sLine));
sSurname := copy(sLine, 1, pos(',', sLine) - 1);
delete(sLine, 1, pos(',', sLine));
rsum := 0;
icount := 0;
while pos(',', sLine) <> 0 do
begin
rsum := rsum + strtofloat(copy(sLine, 1, pos(',', sLine) - 1));
delete(sLine, 1, pos(',', sLine));
inc(icount);
end;
rsum := rsum + strtofloat(sLine);
inc(icount);
// output
redOut.Lines.Add(#9 + sName + #9 + sSurname + #9 + 'Total: ' +
floattostrf(rsum, ffcurrency, 10, 2));
redOut.Lines.Add('Average sales are: ' + floattostrf(rsum / icount,
ffcurrency, 10, 2));
end;
closefile(inputfile);
end;

program 3 - memorandum.zip
MEMORANDUM DATA FILES (25)
4 procedure TForm2.btnProcessClick(Sender: TObject);
var
sLine, sGender: string;
inputfile: textfile;

sDetails, sAddress: string;

iloop: integer;
begin*)
if not(FileExists('data.txt')) then
begin
MessageDlg('Error in opening file', mtError, [mbok], 0);
exit;
end;
assignfile(inputfile, 'data.txt');
reset(inputfile);
while not(eof(inputfile)) do
begin
readln(inputfile, sLine);
if copy(sLine, 1, 2) = '00' then
begin
sDetails := sLine;
redOut.Lines.Add(sDetails);
end;

if copy(sLine, 1, 2) <> '00' then


begin
sAddress := #9 + sLine;
for iloop := 1 to 2 do
begin
readln(inputfile, sLine);
sAddress := sAddress + #9 + sLine;
end;
redOut.Lines.Add(sAddress);
end;
end;
closefile(inputfile);
end;

program 4 - memorandum.zip
MEMORANDUM DATA FILES (20)
Total [88]

You might also like