Advertisement
klasscho

Untitled

Nov 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 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. CorrectName: boolean;
  44. begin
  45. Writeln ('Enter a file name for data entry in the format Name.txt');
  46. AssignFile(MyFile, FName);
  47. Reset(MyFile);
  48. begin
  49. repeat
  50. Readln(FName);
  51. if FileExists(FName) then
  52. CorrectName := True
  53. else
  54. begin
  55. Writeln ('The file name was entered incorrectly. Try again. Example: Name.txt');
  56. CorrectName := False;
  57. end;
  58. until CorrectName ;
  59. end;
  60.  
  61. end;
  62.  
  63. function IsTheMatrixCorrect(FName: string): boolean;
  64. var
  65. MyFile: TextFile;
  66. Number: Integer;
  67. TrueMatrix, IsValidInput: 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. AssignFile(MyFile, FName);
  81. Reset(MyFile);
  82. if EoF(MyFile) then
  83. Writeln('File is empty.')
  84. else
  85. IsValidInput := True;
  86. CloseFile(MyFile);
  87. IsTheMatrixCorrect := TrueMatrix;
  88. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement