Advertisement
Freight

Untitled

May 21st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.12 KB | None | 0 0
  1. (*Windows Free Pascal is developed by dr J.Szymanda under the GPL License*)
  2. (*************************************************************************)
  3. ////////////////////////////////////////////////////////////////////////////////
  4. //////////////////////////////VARIABLES AND STUFF///////////////////////////////
  5. ////////////////////////////////////////////////////////////////////////////////
  6.  
  7.  
  8. // TO DO //
  9. // ----- //
  10. // total seats in the hall
  11. // not allow people to overwrite seats
  12. // delete seats and tickets
  13.  
  14. PROGRAM Major_Project;
  15. USES
  16. CRT,Classes;
  17. CONST
  18. maxArray = 30;
  19. maxVert = 11;
  20. maxHoriz = 11;
  21. TYPE
  22. Customer = RECORD
  23. Name: STRING[100];
  24. Phone: STRING[15];
  25. UID:Integer;
  26. END;
  27. Grid=Array[1..maxVert,1..maxHoriz] OF STRING[3];
  28. VAR
  29. Data: File Of Customer;
  30. Chr: Char;
  31. EmployeeRecord: Customer;
  32. Str: String;
  33. Result, SizeofFile: Integer;
  34. Exit:Boolean;
  35. Index, NoOfItems: Integer;
  36. Name: String[10];
  37. FileName: String[30];
  38. Seat: Text;
  39. Pack: Grid; {A WAY TO DESCRIBE THE ARRAY}
  40. Stage:Char;
  41. BookingID:String;
  42.  
  43. //////////////////////////////////PROCEDURES////////////////////////////////////
  44.  
  45. PROCEDURE GetFileName; //Connects To Customer Database
  46. BEGIN
  47. Filename:= 'customers.dat';
  48. Assign(Data,FileName);
  49. END;
  50.  
  51. PROCEDURE ImportData; //Connects To Seats Database
  52. BEGIN
  53. Filename:= stage + '.txt';
  54. Assign(Seat,Filename);
  55. Reset(Seat);
  56. END;
  57.  
  58. PROCEDURE ReadOrNew; //Read File OR Create New
  59. BEGIN
  60. {$I-} //Enables Input/Output checking
  61. Reset(Data);
  62. {$I+} //Disables I/O checking
  63. Result:= IOResult; //Returns the value of 0 if the file exists
  64. IF Result <> 0 THEN
  65. BEGIN
  66. {$I-}
  67. Rewrite(Data);
  68. {$I+}
  69. Result:= IOResult;
  70. IF Result <> 0 THEN
  71. BEGIN
  72. WriteLn('Error creating file!');
  73. Halt;
  74. END;
  75. END;
  76. SizeOfFile:= Filesize(Data);
  77. END;
  78.  
  79. PROCEDURE BookSeats;
  80. VAR
  81. Across,Down:Integer;
  82. Replacement:String;
  83. xPos,yPos,noOfSeats,Index:Integer;
  84. BEGIN
  85. xPos := 1;
  86. yPos := 1;
  87. Index := 0;
  88. Replacement:=BookingID;
  89. WriteLn('How many seats would you like to book?');
  90. ReadLn(noOfSeats);
  91. REPEAT
  92. Write('Collumn (Down): ');
  93. ReadLn(Down);
  94. Write('Row (Across): ');
  95. ReadLn(Across);
  96. // I want to read the position from the text file that the person has entered and then check if its
  97. // NOT a 0 - if its a 0 then it has been booked and they need to enter the seats again.
  98. {IF (Down <> 0) THEN
  99. BEGIN
  100. WriteLn('Sorry this seat has been booked.');
  101. ReadLn(Down);
  102. END
  103. IF (Across <> 0) THEN
  104. BEGIN
  105. WriteLn('Sorry this seat has been booked.');
  106. ReadLn(Across);
  107. END}
  108. Pack[Down,across]:=Replacement;
  109. Inc(Index);
  110. UNTIL (Index = noOfSeats);
  111. ReWrite(Seat);
  112. END;
  113.  
  114. PROCEDURE PrintArray;
  115. VAR
  116. Across,Down : Integer;
  117. BEGIN
  118. Clrscr;
  119. Across := 1;
  120. Down := 1;
  121. Writeln('+==============================+');
  122. While Down < maxVert DO
  123. BEGIN
  124. Write('|');
  125. WHILE Across < maxHoriz DO
  126. BEGIN
  127. Write(Pack[Down,Across]:3);
  128. //writeln(across);
  129. Inc(Across);
  130. END;
  131. Across := 1;
  132. //writeln(down);
  133. Inc(Down);
  134.  
  135. Write('|');
  136. Writeln;
  137. END;
  138. Writeln('+==============================+');
  139. END;
  140.  
  141. PROCEDURE FillAray;
  142. VAR
  143. Across,Down : Integer;
  144. BEGIN
  145. Across := 1;
  146. Down := 1;
  147. WHILE Down < maxVert DO
  148. BEGIN
  149. WHILE Across < maxHoriz DO
  150. BEGIN
  151. ReadLn(Seat,FileName);
  152. Pack[Down,Across]:=FileName;
  153. Write(Pack[Down,Across]);
  154. Inc(Across);
  155.  
  156. END;
  157. Across := 1;
  158. WriteLn;
  159. //WriteLn(down);
  160. Inc(Down);
  161. END;
  162. //Close(Data);
  163. readkey;
  164. END;
  165.  
  166. PROCEDURE IJustCreatedAnAccount;
  167. BEGIN
  168. WriteLn('Please enter your UID - Make sure its correct or you will book tickets for someone else!');
  169. Read(BookingID);
  170. BookSeats;
  171. END;
  172.  
  173. PROCEDURE NewCustomer; //Add Customers
  174. VAR
  175. NewIdentifier : Integer;
  176. BEGIN
  177. WriteLn('You are now creating a new account. We need the following information:');
  178. ReadOrNew;
  179.  
  180. IF (SizeOfFile = 0) THEN
  181. BEGIN
  182. NewIdentifier:=1;
  183. ClrScr;
  184. Write('Name: ');
  185. ReadLn(EmployeeRecord.Name);
  186. Write('Phone: ');
  187. ReadLn(EmployeeRecord.Phone);
  188. EmployeeRecord.UID := NewIdentifier;
  189. WriteLn('Your USER ID is: ',EmployeeRecord.UID);
  190. Write(Data, EmployeeRecord);
  191. Close(Data);
  192. WriteLn('User Added Successfully.');
  193. ReadKey;
  194. IJustCreatedAnAccount;
  195. END
  196. ELSE
  197. BEGIN
  198. Seek(Data, SizeOfFile-1);
  199. Read(Data,EmployeeRecord);
  200. NewIdentifier := (EmployeeRecord.UID + 1);
  201. ClrScr;
  202. Write('Name: ');
  203. ReadLn(EmployeeRecord.Name);
  204. Write('Phone: ');
  205. ReadLn(EmployeeRecord.Phone);
  206. EmployeeRecord.UID := NewIdentifier;
  207. WriteLn('Your USER ID is: ',EmployeeRecord.UID);
  208. Write(Data, EmployeeRecord);
  209. Close(Data);
  210. WriteLn('User Added Successfully.');
  211. ReadKey;
  212. IJustCreatedAnAccount;
  213. END;
  214. END;
  215.  
  216. PROCEDURE getCustomerInformation;
  217. VAR
  218. bookedBefore:Char;
  219. BEGIN
  220. WriteLn('Welcome to the booking system.');
  221. WriteLn('Have you booked with us before?');
  222. WriteLn('Y/N');
  223. ReadLn(bookedBefore);
  224. IF (bookedBefore = 'Y') THEN
  225. BEGIN
  226. WriteLn('Please enter your UID - Make sure its correct or you will book tickets for someone else!');
  227. Read(BookingID);
  228. BookSeats;
  229. END
  230. ELSE
  231. NewCustomer;
  232. END;
  233.  
  234. PROCEDURE WriteRecord; //Used In Print Record
  235. BEGIN;
  236. Read(Data, EmployeeRecord);
  237. WriteLn('=============================');
  238. WriteLn('Name: ', EmployeeRecord.Name);
  239. WriteLn('Phone: ', EmployeeRecord.Phone);
  240. WriteLn('UID: ', EmployeeRecord.UID);
  241. WriteLn('=============================');
  242. END;
  243.  
  244. PROCEDURE PrintRecords; //Allows you to print all of the record to screen
  245. VAR
  246. Index: Integer;
  247. BEGIN
  248. ClrScr;
  249. Index:= 0;
  250. ReadOrNew;
  251. WHILE Index < SizeOfFile DO
  252. BEGIN
  253. WriteLn('Customer Array Position: ',Index);
  254. Seek(Data,Index);
  255. WriteRecord;
  256. Inc(Index);
  257. WriteLn('Press {ENTER} for the next record.');
  258. Readkey;
  259. ClrScr;
  260. END;
  261. END;
  262.  
  263. PROCEDURE MenuOfNames; //Allows you to write a menu of all the names to screen
  264. VAR
  265. Index: Integer;
  266. BEGIN
  267. Index:= 0;
  268. ReadOrNew;
  269. WHILE Index < SizeOfFile DO
  270. BEGIN
  271. Seek(Data,Index);
  272. Read(Data, EmployeeRecord);
  273. WriteLn('Customer ', Index + 1, ' - ', EmployeeRecord.Name);
  274. Inc(Index);
  275. END;
  276. END;
  277.  
  278. PROCEDURE DeleteRecordFromFile; //Allows you to delete a record from the file
  279. VAR
  280. Index, Choice: Integer;
  281. BEGIN
  282. MenuOfNAmes;
  283. WriteLn;
  284. WriteLn('Which customer do you want to delete? ');
  285. Readln(Choice);
  286. Index:= Choice - 1;
  287. WHILE Index < SizeOfFile - 1 DO
  288. BEGIN
  289. Seek(Data, Index + 1);
  290. Read(Data, EmployeeRecord);
  291. Seek(Data, Index);
  292. Write(Data, EmployeeRecord);
  293. Inc(Index);
  294. END;
  295. Seek(Data, SizeofFile - 1);
  296. Truncate(Data);
  297. Close(Data);
  298. // 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
  299. // create a subprogram to overwrite with 0 in the certain positions that the UID has been deleted from ...
  300. END;
  301.  
  302. PROCEDURE ModifyRecord; //Allows you to modify an existing record
  303. VAR
  304. Index, Choice: Integer;
  305. BEGIN
  306. ClrScr;
  307. MenuOfNames;
  308. WriteLn;
  309. WriteLn('Which customer do you want to modify?');
  310. Write('Enter number: ');
  311. Readln(Choice);
  312. Index:= Choice - 1;
  313. Seek(Data, Index);
  314. ClrScr;
  315. WriteRecord;
  316. WriteLn;
  317. WriteLn('1. Name');
  318. WriteLn('2. Phone');
  319. WriteLn;
  320. WriteLn('What part of the customer do you want to modify?');
  321. Write('Enter number: ');
  322. Readln(Choice);
  323. Seek(Data, Index);
  324. WriteLn;
  325. CASE Choice OF
  326. 1: BEGIN
  327. Write('Enter the new name:');
  328. Readln(EmployeeRecord.Name);
  329. END;
  330. 2: BEGIN
  331. Write('Enter the new phone number:');
  332. Readln(EmployeeRecord.Phone);
  333. END;
  334. END;
  335. Seek(Data, Index);
  336. Write(Data, EmployeeRecord);
  337. Close(Data);
  338. END;
  339.  
  340. PROCEDURE CloseProgram;
  341. BEGIN
  342. Exit:=True;
  343. END;
  344.  
  345. PROCEDURE BookingLogo;
  346. VAR
  347. SL: TStringList;
  348. BEGIN
  349. TextColor(LightGreen);
  350. SL := TStringList.Create;
  351. SL.LoadFromFile('bookingart.txt'); // use real name (full path!) here.
  352. Writeln(SL.Text);
  353. SL.Free;
  354. TextColor(White);
  355. END;
  356.  
  357. PROCEDURE Stages;
  358. BEGIN
  359. ClrScr;
  360. WriteLn('+===========+');
  361. WriteLn('| STAGES |');
  362. WriteLn('+===========+');
  363. WriteLn('| A | B |');
  364. WriteLn('+===========+');
  365. WriteLn('| C | D |');
  366. WriteLn('+===========+');
  367. WriteLn('| E | F |');
  368. WriteLn('+===========+');
  369. WriteLn('| E | H |');
  370. WriteLn('+===========+');
  371. WriteLn('| I | J |');
  372. WriteLn('+===========+');
  373. WriteLn;
  374. WriteLn('What stage would you like to book into:');
  375. ReadLn(Stage);
  376. END;
  377.  
  378. PROCEDURE SeatsAvaliable;
  379. VAR
  380. Across,Down,Avaliable : Integer;
  381. BEGIN
  382. Across := 1;
  383. Down := 1;
  384. Avaliable := 0;
  385. While Down < maxVert DO
  386. BEGIN
  387. WHILE Across < maxHoriz DO
  388. BEGIN
  389. IF (Pack[Down,Across] = '0') THEN
  390. Inc(Avaliable);
  391. Inc(Across);
  392. END;
  393. Across := 1;
  394. Inc(Down);
  395. END;
  396. WriteLn('Seats Avaliable: ',Avaliable);
  397. END;
  398.  
  399. PROCEDURE WriteArrayToFile;
  400. VAR
  401. Across,Down,MaxVert1,MaxHoriz1 : Integer;
  402. BEGIN
  403. Across := 1;
  404. Down := 1;
  405. MaxVert1 := 11;
  406. MaxHoriz1 := 11;
  407. WHILE Down < maxVert1 DO
  408. BEGIN
  409. WHILE Across < maxHoriz1 DO
  410. BEGIN
  411. WriteLn(Seat,Pack[Down,Across]);
  412. //WriteLn(Pack[Down,Across]);
  413. Inc(Across);
  414. END;
  415. //WriteLn;
  416. Across := 1;
  417. Inc(Down);
  418. END;
  419. END;
  420.  
  421. PROCEDURE DeleteTickets;
  422. VAR
  423. Across,Down,Avaliable : Integer;
  424. UID:String;
  425. BEGIN
  426. Across := 1;
  427. Down := 1;
  428. Avaliable := 0;
  429. WriteLn('What is your UID - Please note if you continue you will loose your seats.');
  430. ReadLn(UID);
  431. WHILE Down < maxVert DO
  432. BEGIN
  433. WHILE Across < maxHoriz DO
  434. BEGIN
  435. IF (Pack[Down,Across] = UID) THEN
  436. BEGIN
  437. WriteLn('Im here');
  438. Pack[Down,Across] := '0';
  439. END;
  440. Inc(Across);
  441. END;
  442. Across := 1;
  443. Inc(Down);
  444. END;
  445. END;
  446.  
  447. PROCEDURE createFile;
  448. BEGIN
  449. Assign(Seat,Filename);
  450. Rewrite(Seat);
  451. END;
  452.  
  453. PROCEDURE MainMenu;
  454. VAR
  455. Choice: Integer;
  456. BEGIN
  457. ClrScr;
  458. BookingLogo;
  459. WriteLn('1. Add Customer');
  460. WriteLn('2. List Customer');
  461. WriteLn('3. Delete Customer');
  462. WriteLn('4. Modify Customer');
  463. WriteLn('5. Seats Avaliable');
  464. WriteLn('6. Book Tickets');
  465. WriteLn('7. Get Customer Information');
  466. WriteLn('8. Delete Tickets');
  467. WriteLn('9. Close Program');
  468. WriteLn;
  469. WriteLn('What do you want to do?');
  470. Readln(Choice);
  471. CASE Choice OF
  472. 1: NewCustomer;
  473. 2: PrintRecords;
  474. 3: DeleteRecordFromFile;
  475. 4: ModifyRecord;
  476. 5:
  477. BEGIN
  478. Stages;
  479. ImportData;
  480. FillAray;
  481. PrintArray;
  482. SeatsAvaliable;
  483. ReadKey;
  484. END;
  485. 6:
  486. BEGIN
  487. Stages;
  488. ImportData;
  489. FillAray;
  490. PrintArray;
  491. SeatsAvaliable;
  492. getCustomerInformation;
  493. PrintArray;
  494. WriteArrayToFile;
  495.  
  496. ReadKey;
  497. END;
  498. 7: getCustomerInformation;
  499. 8:
  500. BEGIN
  501. Stages;
  502. ImportData;
  503. FillAray;
  504. PrintArray;
  505. DeleteTickets;
  506. PrintArray;
  507. //lmao it prints to the array but wont go back into a text fileeee
  508. //WriteArrayToFile;
  509. ReadKey;
  510. END;
  511. 9: CloseProgram;
  512. END;
  513. END;
  514. //Main Program
  515. BEGIN
  516. GetFileName;
  517. REPEAT
  518. MainMenu;
  519. UNTIL Exit = True;
  520. WriteLn('Closing...');
  521. ReadKey;
  522. END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement