COMPUTING 9691/2: PRACTICAL PROGRAMMING PROJECT

This section requires candidates to demonstrate their skills in a programming language by selecting a problem to solve. The solution to the problem should encompass as many of the criteria listed in Section 2 of the syllabus as the candidate is capable of using. Candidates and Centres should be aware that demonstration of the skills will be necessary, within the context of the problem solution, in order to earn marks in the assessment. It is envisaged that this project will be a long term piece of work to be completed during year one of the course.

SUBMISSION DEADLINE: Early October 2006. Delayed will not be penalized and assessed!

NOTE: -

            - Arrays and/or reccords;

            - Different data types (Real, Integer, Booolean, Character);

            - Selection (If-Then-Else loop and CASE sstatement) & Iteration - Repeating loops such as REPEAT-UNTIL, DO-WHILE LOOP, FOR-TO-DO;

            - Procedures and Functions;

            - Searching techniques (Linear search, biinary search, check digit); Note: If you choose the sorting techniques still okay but after sorting you must have a search function or procedure;

            - Files (Open, Write, Read, Re-Open the ffile);


{PROGRAM ONE}

{A program demonstrates both writing to disk, and reading from disk. Stock records are accepted at the terminal and written to disk, and then when all records are written, the file is closed and re-opened for input and the records are read and displayed on the screen.}

program s_create;

{Program to accept data from the keyboard and write to stock master file.}

uses crt;

const max = 20;

type

    string_max = array [1..max] of char;

    stock_rec_type = record;

        item_no : integer;

        description : string_max;

        selling_price : real;

        qty_in_stock : integer;

end;

stock_file_type = file of stock_rec_type;

var

    stock_file : stock_file_type;

    stock_item : stock_rec_type;

    filename : string[20];

{***************************************}

procedure read_text_string (no_of_chars: integer; var text_string:string_max);

const space = ' ';

var counter: integer;

begin

    for counter := 1 to no_of_chars do

        if eoln then text_string[counter] := space

        else read(text_string[counter]);

        {endif}

    {endfor}

    readln;

end; {procedure}

{*******************************}

procedure initialise;

begin

    clrscr;

    writeln('Please enter the name of the file, including pathname (e.g. a:\stockmas.dat);');

    readln(filename);

    assign(stock_file, filename);

    rewrite(stock_file);

    write('Enter item number; 999 to finish: ');

    readln(stock_item.item_no);

end; {procedure}

{*****************************************}

procedure write_recs;

begin

    with stock_item do

    begin

        while item_no <> 999 do

            begin

                write('Enter description: ');

                read_text_string(20, description);

                write('Selling price: ');

                readln(selling_price);

                write('Quantity in stock: ');

                readln(qty_in_stock);

                {**********write the record to the file***********}

                write(stock_file, stock_item);

                write('Enter item number; 999 to finish:');

                readln(item_no);

        end; {while}

    close(stock_file);

    end; {with}

end; {procedure}

{****************************************}

procedure read_recs;

begin

    reset(stock_file);

    with stock_item do

        begin

            while not eof (stock_file) do

                begin

                    read(stock_file, stock_item);

                    writeln(item_no:7, description:22, selling_price:8:2, qty_in_stock:5);

                end; {while}

        end; {with}

        close(stock_file);

end;{procedure}

{****************MAIN PROGRAM***************}

begin

    initialise;

    write_recs;

    read_recs;

end.


{PROGRAM TWO}

{Program sets up 20 blank records which will be used to hold details of which students have been allocated each of 20 lockers numbered 1 to 20}

program CreateRandom; {stored as U16Rnd1}

{Locker File Creation Program}

uses crt;

type LockerType = record

    LockerNumber : integer;

    Name   : string;

    Year : integer;

    Status : char;

end;

var

    LockerFile : file of lockertype;

    LockerRec : LockerType;

{*******************************************}

procedure A1_Init;

begin

    clrscr;

    writeln ('Locker File Creation');

    writeln;

    assign(LockerFile, 'a:\lockerf.dat');

    rewrite(LockerFile); {open a new file or overwrite an existing one}

end;

{********************************************}

procedure A2_FillRecord;

begin

    LockerRec.Name := 'Empty';

    LockerRec.Year := 0;

    LockerRec.Status := 'E'; {Indicates an empty locker}

end;

{*************************************}

procedure A3_Output;

var Sub : integer;

begin

    for Sub := 1 to 20 do

    begin

        LockerRec.LockerNumber := sub;

        seek (LockerFile, sub);

        write(LockerFile, LockerRec);

        writeln('Record',sub, 'written');

    end; {for}

end;

{*************MAIN PROGRAM************************}

Begin

    A1_Init;

    A2_FillRecord;

    A3_Output;

    close (LockerFile);

    readln;

end.


{PROGRAM THREE}

{program to look up, add, delete, edit and list locker records}

program LockerMaint; {stored as U16Maint}

uses crt;

type LockerType = record

   LockerNumber : integer;

    Name : string;

    Year : integer;

    Status : char;

end;

{***********************}

var

   LockerFile : file of lockertype;

    LockerRec : LockerType;

    LockerInUse : boolean;

    LockerNum : Integer;

{*****************************}

procedure OpenFile;

begin

    assign(LockerFile, 'a:\lockerf.dat');

    reset(LockerFile);

end;

{******************************}

procedure GetLocker(var InUse : Boolean);

begin

    clrscr;

    writeln('Please enter the locker number');

    readln(LockerNum);

    seek(LockerFile, LockerNum);

    read(LockerFile, LockerRec);

    if (LockerRec.Status = 'E') then LockerInUse := False

    else LockerInUse := True;

end; {GetLocker}

{*******************************}

procedure FindRec;

begin

    GetLocker(LockerInUse);

    if LockerInUse then

        writeln('Locker', LockerNum, ' ', LockerRec.Name, ' ' , LockerRec.Year)

    else writeln('Locker ' , LockerNum, ' empty');

    readln;

end; {FindRec}

{****************************}

procedure AddRec;

begin

    GetLocker(LockerInUse);

    If LockerInUse then

        begin

            writeln('This locker is already in use'); readln;

        end

    else

    write('Enter student name: ');

    readln(LockerRec.Name);

    write('Enter student's year: ');

    readln(LockerRec.Year);

    LockerRec.Status := 'F';

    seek(LockerFile, LockerNum);

    write(LockerFile, LockerRec);

    end; {if}

end; {AddRec}

{*******************************}

procedure DeleteRec;

begin

end; {DeleteRec}

procedure EditRec;

begin

end; {EditRec}

procedure ListRec;

var sub : integer;

begin

    for sub := 1 to 20 do

    begin

        seek(LockerFile, sub);

        read(LockerFile, LockerRec);

        writeln('Record' , sub, ' :' , LockerRec.LockerNumber, LockerRec.Name, ' ' , LockerRec.Year);

    end; {for}

    readln;

end; {ListRec}

{*******************************}

procedure DisplayMenu;

var choice : char;

begin

    repeat

        clrscr;

        gotoxy (26,4); write('LOCKER FILE MAINTENANCE');

        gotoxy (26,6); write('1: Look up locker details');

        gotoxy (26,8); write('2: Add student name to file');

        gotoxy (26,10); write('3: Delete student name');

        gotoxy (26,12); write('4: Edit locker details');

        gotoxy (26,14); write('5: List occupied lockers');

        gotoxy (26,16); write('6: Quit');

        gotoxy (26,18); write('Please enter choice: ');

        readln(choice);

        case choice of

        '1' : FindRec;

        '2' : AddRec;

        '3' : DeleteRec;

        '4' : EditRec;

        '5' : ListRec;

        '6' : exit;

        end; {case}

    until choice = '6';

end; {DisplayMenu}

{************MAIN PROGRAM***********}

begin

    Openfile;

    DisplayMenu;

    close (LockerFile)

end.


Hosted by www.Geocities.ws

1