Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*Windows Free Pascal is developed by dr J.Szymanda under the GPL License*)
- (*************************************************************************)
- ////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////VARIABLES AND STUFF///////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- // TO DO //
- // ----- //
- // total seats in the hall
- // not allow people to overwrite seats
- // delete seats and tickets
- PROGRAM Major_Project;
- USES
- CRT,Classes;
- CONST
- maxArray = 30;
- maxVert = 11;
- maxHoriz = 11;
- TYPE
- Customer = RECORD
- Name: STRING[100];
- Phone: STRING[15];
- UID:Integer;
- END;
- Grid=Array[1..maxVert,1..maxHoriz] OF STRING[3];
- VAR
- Data: File Of Customer;
- Chr: Char;
- EmployeeRecord: Customer;
- Str: String;
- Result, SizeofFile: Integer;
- Exit:Boolean;
- Index, NoOfItems: Integer;
- Name: String[10];
- FileName: String[30];
- Seat: Text;
- Pack: Grid; {A WAY TO DESCRIBE THE ARRAY}
- Stage:Char;
- BookingID:String;
- //////////////////////////////////PROCEDURES////////////////////////////////////
- PROCEDURE GetFileName; //Connects To Customer Database
- BEGIN
- Filename:= 'customers.dat';
- Assign(Data,FileName);
- END;
- PROCEDURE ImportData; //Connects To Seats Database
- BEGIN
- Filename:= stage + '.txt';
- Assign(Seat,Filename);
- Reset(Seat);
- END;
- PROCEDURE ReadOrNew; //Read File OR Create New
- BEGIN
- {$I-} //Enables Input/Output checking
- Reset(Data);
- {$I+} //Disables I/O checking
- Result:= IOResult; //Returns the value of 0 if the file exists
- IF Result <> 0 THEN
- BEGIN
- {$I-}
- Rewrite(Data);
- {$I+}
- Result:= IOResult;
- IF Result <> 0 THEN
- BEGIN
- WriteLn('Error creating file!');
- Halt;
- END;
- END;
- SizeOfFile:= Filesize(Data);
- END;
- PROCEDURE BookSeats;
- VAR
- Across,Down:Integer;
- Replacement:String;
- xPos,yPos,noOfSeats,Index:Integer;
- BEGIN
- xPos := 1;
- yPos := 1;
- Index := 0;
- Replacement:=BookingID;
- WriteLn('How many seats would you like to book?');
- ReadLn(noOfSeats);
- REPEAT
- Write('Collumn (Down): ');
- ReadLn(Down);
- Write('Row (Across): ');
- ReadLn(Across);
- // I want to read the position from the text file that the person has entered and then check if its
- // NOT a 0 - if its a 0 then it has been booked and they need to enter the seats again.
- {IF (Down <> 0) THEN
- BEGIN
- WriteLn('Sorry this seat has been booked.');
- ReadLn(Down);
- END
- IF (Across <> 0) THEN
- BEGIN
- WriteLn('Sorry this seat has been booked.');
- ReadLn(Across);
- END}
- Pack[Down,across]:=Replacement;
- Inc(Index);
- UNTIL (Index = noOfSeats);
- ReWrite(Seat);
- END;
- PROCEDURE PrintArray;
- VAR
- Across,Down : Integer;
- BEGIN
- Clrscr;
- Across := 1;
- Down := 1;
- Writeln('+==============================+');
- While Down < maxVert DO
- BEGIN
- Write('|');
- WHILE Across < maxHoriz DO
- BEGIN
- Write(Pack[Down,Across]:3);
- //writeln(across);
- Inc(Across);
- END;
- Across := 1;
- //writeln(down);
- Inc(Down);
- Write('|');
- Writeln;
- END;
- Writeln('+==============================+');
- END;
- PROCEDURE FillAray;
- VAR
- Across,Down : Integer;
- BEGIN
- Across := 1;
- Down := 1;
- WHILE Down < maxVert DO
- BEGIN
- WHILE Across < maxHoriz DO
- BEGIN
- ReadLn(Seat,FileName);
- Pack[Down,Across]:=FileName;
- Write(Pack[Down,Across]);
- Inc(Across);
- END;
- Across := 1;
- WriteLn;
- //WriteLn(down);
- Inc(Down);
- END;
- //Close(Data);
- readkey;
- END;
- PROCEDURE IJustCreatedAnAccount;
- BEGIN
- WriteLn('Please enter your UID - Make sure its correct or you will book tickets for someone else!');
- Read(BookingID);
- BookSeats;
- END;
- PROCEDURE NewCustomer; //Add Customers
- VAR
- NewIdentifier : Integer;
- BEGIN
- WriteLn('You are now creating a new account. We need the following information:');
- ReadOrNew;
- IF (SizeOfFile = 0) THEN
- BEGIN
- NewIdentifier:=1;
- ClrScr;
- Write('Name: ');
- ReadLn(EmployeeRecord.Name);
- Write('Phone: ');
- ReadLn(EmployeeRecord.Phone);
- EmployeeRecord.UID := NewIdentifier;
- WriteLn('Your USER ID is: ',EmployeeRecord.UID);
- Write(Data, EmployeeRecord);
- Close(Data);
- WriteLn('User Added Successfully.');
- ReadKey;
- IJustCreatedAnAccount;
- END
- ELSE
- BEGIN
- Seek(Data, SizeOfFile-1);
- Read(Data,EmployeeRecord);
- NewIdentifier := (EmployeeRecord.UID + 1);
- ClrScr;
- Write('Name: ');
- ReadLn(EmployeeRecord.Name);
- Write('Phone: ');
- ReadLn(EmployeeRecord.Phone);
- EmployeeRecord.UID := NewIdentifier;
- WriteLn('Your USER ID is: ',EmployeeRecord.UID);
- Write(Data, EmployeeRecord);
- Close(Data);
- WriteLn('User Added Successfully.');
- ReadKey;
- IJustCreatedAnAccount;
- END;
- END;
- PROCEDURE getCustomerInformation;
- VAR
- bookedBefore:Char;
- BEGIN
- WriteLn('Welcome to the booking system.');
- WriteLn('Have you booked with us before?');
- WriteLn('Y/N');
- ReadLn(bookedBefore);
- IF (bookedBefore = 'Y') THEN
- BEGIN
- WriteLn('Please enter your UID - Make sure its correct or you will book tickets for someone else!');
- Read(BookingID);
- BookSeats;
- END
- ELSE
- NewCustomer;
- END;
- PROCEDURE WriteRecord; //Used In Print Record
- BEGIN;
- Read(Data, EmployeeRecord);
- WriteLn('=============================');
- WriteLn('Name: ', EmployeeRecord.Name);
- WriteLn('Phone: ', EmployeeRecord.Phone);
- WriteLn('UID: ', EmployeeRecord.UID);
- WriteLn('=============================');
- END;
- PROCEDURE PrintRecords; //Allows you to print all of the record to screen
- VAR
- Index: Integer;
- BEGIN
- ClrScr;
- Index:= 0;
- ReadOrNew;
- WHILE Index < SizeOfFile DO
- BEGIN
- WriteLn('Customer Array Position: ',Index);
- Seek(Data,Index);
- WriteRecord;
- Inc(Index);
- WriteLn('Press {ENTER} for the next record.');
- Readkey;
- ClrScr;
- END;
- END;
- PROCEDURE MenuOfNames; //Allows you to write a menu of all the names to screen
- VAR
- Index: Integer;
- BEGIN
- Index:= 0;
- ReadOrNew;
- WHILE Index < SizeOfFile DO
- BEGIN
- Seek(Data,Index);
- Read(Data, EmployeeRecord);
- WriteLn('Customer ', Index + 1, ' - ', EmployeeRecord.Name);
- Inc(Index);
- END;
- END;
- PROCEDURE DeleteRecordFromFile; //Allows you to delete a record from the file
- VAR
- Index, Choice: Integer;
- BEGIN
- MenuOfNAmes;
- WriteLn;
- WriteLn('Which customer do you want to delete? ');
- Readln(Choice);
- Index:= Choice - 1;
- WHILE Index < SizeOfFile - 1 DO
- BEGIN
- Seek(Data, Index + 1);
- Read(Data, EmployeeRecord);
- Seek(Data, Index);
- Write(Data, EmployeeRecord);
- Inc(Index);
- END;
- Seek(Data, SizeofFile - 1);
- Truncate(Data);
- Close(Data);
- // do an if statement - IF its UID has tickets booked in (will need to do a scan through all the stages?) then it needs to overwrite them with 0
- // create a subprogram to overwrite with 0 in the certain positions that the UID has been deleted from ...
- END;
- PROCEDURE ModifyRecord; //Allows you to modify an existing record
- VAR
- Index, Choice: Integer;
- BEGIN
- ClrScr;
- MenuOfNames;
- WriteLn;
- WriteLn('Which customer do you want to modify?');
- Write('Enter number: ');
- Readln(Choice);
- Index:= Choice - 1;
- Seek(Data, Index);
- ClrScr;
- WriteRecord;
- WriteLn;
- WriteLn('1. Name');
- WriteLn('2. Phone');
- WriteLn;
- WriteLn('What part of the customer do you want to modify?');
- Write('Enter number: ');
- Readln(Choice);
- Seek(Data, Index);
- WriteLn;
- CASE Choice OF
- 1: BEGIN
- Write('Enter the new name:');
- Readln(EmployeeRecord.Name);
- END;
- 2: BEGIN
- Write('Enter the new phone number:');
- Readln(EmployeeRecord.Phone);
- END;
- END;
- Seek(Data, Index);
- Write(Data, EmployeeRecord);
- Close(Data);
- END;
- PROCEDURE CloseProgram;
- BEGIN
- Exit:=True;
- END;
- PROCEDURE BookingLogo;
- VAR
- SL: TStringList;
- BEGIN
- TextColor(LightGreen);
- SL := TStringList.Create;
- SL.LoadFromFile('bookingart.txt'); // use real name (full path!) here.
- Writeln(SL.Text);
- SL.Free;
- TextColor(White);
- END;
- PROCEDURE Stages;
- BEGIN
- ClrScr;
- WriteLn('+===========+');
- WriteLn('| STAGES |');
- WriteLn('+===========+');
- WriteLn('| A | B |');
- WriteLn('+===========+');
- WriteLn('| C | D |');
- WriteLn('+===========+');
- WriteLn('| E | F |');
- WriteLn('+===========+');
- WriteLn('| E | H |');
- WriteLn('+===========+');
- WriteLn('| I | J |');
- WriteLn('+===========+');
- WriteLn;
- WriteLn('What stage would you like to book into:');
- ReadLn(Stage);
- END;
- PROCEDURE SeatsAvaliable;
- VAR
- Across,Down,Avaliable : Integer;
- BEGIN
- Across := 1;
- Down := 1;
- Avaliable := 0;
- While Down < maxVert DO
- BEGIN
- WHILE Across < maxHoriz DO
- BEGIN
- IF (Pack[Down,Across] = '0') THEN
- Inc(Avaliable);
- Inc(Across);
- END;
- Across := 1;
- Inc(Down);
- END;
- WriteLn('Seats Avaliable: ',Avaliable);
- END;
- PROCEDURE WriteArrayToFile;
- VAR
- Across,Down,MaxVert1,MaxHoriz1 : Integer;
- BEGIN
- Across := 1;
- Down := 1;
- MaxVert1 := 11;
- MaxHoriz1 := 11;
- WHILE Down < maxVert1 DO
- BEGIN
- WHILE Across < maxHoriz1 DO
- BEGIN
- WriteLn(Seat,Pack[Down,Across]);
- //WriteLn(Pack[Down,Across]);
- Inc(Across);
- END;
- //WriteLn;
- Across := 1;
- Inc(Down);
- END;
- END;
- PROCEDURE DeleteTickets;
- VAR
- Across,Down,Avaliable : Integer;
- UID:String;
- BEGIN
- Across := 1;
- Down := 1;
- Avaliable := 0;
- WriteLn('What is your UID - Please note if you continue you will loose your seats.');
- ReadLn(UID);
- WHILE Down < maxVert DO
- BEGIN
- WHILE Across < maxHoriz DO
- BEGIN
- IF (Pack[Down,Across] = UID) THEN
- BEGIN
- WriteLn('Im here');
- Pack[Down,Across] := '0';
- END;
- Inc(Across);
- END;
- Across := 1;
- Inc(Down);
- END;
- END;
- PROCEDURE createFile;
- BEGIN
- Assign(Seat,Filename);
- Rewrite(Seat);
- END;
- PROCEDURE MainMenu;
- VAR
- Choice: Integer;
- BEGIN
- ClrScr;
- BookingLogo;
- WriteLn('1. Add Customer');
- WriteLn('2. List Customer');
- WriteLn('3. Delete Customer');
- WriteLn('4. Modify Customer');
- WriteLn('5. Seats Avaliable');
- WriteLn('6. Book Tickets');
- WriteLn('7. Get Customer Information');
- WriteLn('8. Delete Tickets');
- WriteLn('9. Close Program');
- WriteLn;
- WriteLn('What do you want to do?');
- Readln(Choice);
- CASE Choice OF
- 1: NewCustomer;
- 2: PrintRecords;
- 3: DeleteRecordFromFile;
- 4: ModifyRecord;
- 5:
- BEGIN
- Stages;
- ImportData;
- FillAray;
- PrintArray;
- SeatsAvaliable;
- ReadKey;
- END;
- 6:
- BEGIN
- Stages;
- ImportData;
- FillAray;
- PrintArray;
- SeatsAvaliable;
- getCustomerInformation;
- PrintArray;
- WriteArrayToFile;
- ReadKey;
- END;
- 7: getCustomerInformation;
- 8:
- BEGIN
- Stages;
- ImportData;
- FillAray;
- PrintArray;
- DeleteTickets;
- PrintArray;
- //lmao it prints to the array but wont go back into a text fileeee
- //WriteArrayToFile;
- ReadKey;
- END;
- 9: CloseProgram;
- END;
- END;
- //Main Program
- BEGIN
- GetFileName;
- REPEAT
- MainMenu;
- UNTIL Exit = True;
- WriteLn('Closing...');
- ReadKey;
- END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement