klasscho

Untitled

Nov 15th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. Program Project9;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7. Function SizeOfMatrix(var MyFile: TextFile) : Integer;
  8. var
  9. Numb, n, NumbEx, Temp:Integer;
  10. IsCorrect, FirstIt: Boolean;
  11. begin
  12. n := 0;
  13. FirstIt := True;
  14. IsCorrect := True;
  15. while (not Eof(MyFile)) and IsCorrect do
  16. begin
  17. NumbEx := Numb;
  18. Numb := 0;
  19. while not Eoln(MyFile) do
  20. begin
  21. Inc(Numb);
  22. Read (MyFile, Temp);
  23. end;
  24. if NumbEx <> Numb then
  25. IsCorrect := False;
  26. if FirstIt then
  27. begin
  28. IsCorrect := True;
  29. FirstIt := False;
  30. end;
  31. Inc(n);
  32. Readln(MyFile);
  33. end;
  34. if (Numb = n) and IsCorrect then
  35. SizeOfMatrix := n
  36. else
  37. SizeOfMatrix := 0;
  38. end;
  39.  
  40. procedure ReadFileName (var MyFile: TextFile);
  41. var
  42. FName: string;
  43. IsValidInput: boolean;
  44. begin
  45. IsValidInput := False;
  46. repeat
  47. Writeln ('Enter a file name for data entry in the format Name.txt');
  48. Readln(FName);
  49. if FileExists (FName) then
  50. begin
  51. AssignFile(MyFile, FName);
  52. Reset(MyFile);
  53. if EoF(MyFile) then
  54. Writeln('File is empty.')
  55. else
  56. IsValidInput := True;
  57. end
  58. else
  59. Writeln('Input Error. This file is empty.');
  60. until IsValidInput;
  61. end;
  62.  
  63. function IsTheMatrixCorrect(FName: string): boolean;
  64. var
  65. MyFile: TextFile;
  66. Number: Integer;
  67. TrueMatrix: Boolean;
  68. begin
  69. TrueMatrix := True;
  70. AssignFile(MyFile, FName);
  71. reset(MyFile);
  72. while (not EOF(MyFile)) do
  73. begin
  74. try
  75. read(MyFile, Number)
  76. except
  77. TrueMatrix := false
  78. end;
  79. end;
  80. CloseFile(MyFile);
  81. IsTheMatrixCorrect := TrueMatrix;
  82. end;
  83.  
  84. end.
Advertisement
Add Comment
Please, Sign In to add comment