Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. program Project3;
  2.  
  3. {$APPTYPE CONSOLE}
  4. {$R *.res}
  5. uses
  6. System.SysUtils;
  7. type
  8. stringMatrix = array [0..29, 0..10] of String;
  9.  
  10. const
  11. InputMessage =
  12. 'Пожалуйста, введите имя файла, из которого будут считываться данные.';
  13. OutputMessage =
  14. 'Пожалуйста, введите имя файла, в который желаете записать результат.';
  15. MistakeFoundMessage =
  16. 'Ошибка! Файл с таким именем не найден. Повторите попытку.';
  17. MistakeOpenMessage =
  18. 'Ошибка! Невозможно открыть данный файл. Пожалуйста, проверьте файл и повторите попытку.';
  19.  
  20. {function RandomNum(var i, j: integer);
  21. var
  22. InFile: TextFile;
  23. FileName: String;
  24. begin
  25. for I := 1 to 30 do
  26. begin
  27. FileName := '';
  28. FileName := IntToStr(random(10) + 1);
  29. for J := 1 to 9 do
  30. FileName := Str + ', ' + IntToStr(random(10) + 1);
  31. WriteLn(InFile, FileName);
  32. end;
  33. end}
  34.  
  35. function CountNegativeMarks(var Marks : array of String) : String;
  36. var
  37. c, I, J, Answer: integer;
  38. begin
  39. Answer := 0;
  40. for I := 0 to 9 do
  41. if (Marks[I] = '1') or (Marks[I] = '2') or (Marks[I] = '3') then
  42. inc(Answer);
  43. Result := IntToStr(Answer);
  44. end;
  45.  
  46.  
  47.  
  48. procedure LoadMatrixFromFile (var Students: stringMatrix);
  49. var
  50. InputIsNotCorrect: Boolean;
  51. InFile: TextFile;
  52. Reader: String;
  53. J, I: integer;
  54. begin
  55. repeat
  56. InputIsNotCorrect := True;
  57. WriteLn(InputMessage + #13#10 + 'Например, "C:\Users\Ольга\Desktop\LabWork\Unit 2\Lab 3\input.txt"');
  58. ReadLn(Reader);
  59. if FileExists(Reader) then
  60. begin
  61. try
  62. AssignFile(InFile, Reader);
  63. Reset(InFile);
  64. except
  65. WriteLn(MistakeOpenMessage);
  66. InputIsNotCorrect := False;
  67. end;
  68. if InputIsNotCorrect then
  69. try
  70. for I := 0 to 29 do
  71. begin
  72. ReadLn(InFile, Reader);
  73. for J := 0 to 9 do
  74. begin
  75. Students[I][J] := Copy(Reader, 1, pos(', ', Reader) - 1);
  76. delete(Reader, 1, pos(', ', Reader) + 1);
  77. end;
  78. Students[I][9] := Reader;
  79. end;
  80. except
  81. WriteLn('Ошибка! Файл содержит неверные данные. Пожалуйста, проверьте файл и повторите попытку.');
  82. InputIsNotCorrect := False;
  83. end;
  84. CloseFile(InFile);
  85. end
  86. else
  87. begin
  88. WriteLn(MistakeFoundMessage);
  89. InputIsNotCorrect := False;
  90. end;
  91. until InputIsNotCorrect;
  92. end;
  93.  
  94. procedure SaveMatrixToFile (Students: stringMatrix);
  95. var
  96. OutputIsNotCorrect: Boolean;
  97. OutFile: TextFile;
  98. Reader: String;
  99. I, J : integer;
  100. begin
  101. repeat
  102. OutputIsNotCorrect := True;
  103. WriteLn(OutputMessage + #13#10 + 'Например, "C:\Users\Ольга\Desktop\LabWork\Unit 2\Lab 3\output.txt"');
  104. ReadLn(Reader);
  105. if FileExists(Reader) then
  106. begin
  107. try
  108. AssignFile(OutFile, Reader);
  109. Rewrite(OutFile);
  110. except
  111. WriteLn(MistakeOpenMessage);
  112. OutputIsNotCorrect := False;
  113. end;
  114. if OutputIsNotCorrect then
  115. begin
  116. for I := 0 to 29 do
  117. Students[I][10] := CountNegativeMarks(Students[I]);
  118. for I := 0 to 29 do
  119. begin
  120. Write(OutFile,'Студент №', i + 1,': ');
  121. Write('Студент №', i + 1,': ');
  122. for J := 0 to 8 do
  123. begin
  124. Write(OutFile, Students[I][J], ', ');
  125. Write(Students[I][J], ', ');
  126. end;
  127. WriteLn(OutFile, Students[I][9], ' : негативных оценок = ', Students[I][10]);
  128. WriteLn(Students[I][9], ' : негативных оценок = ', Students[I][10]);
  129. end;
  130. CloseFile(OutFile);
  131. end;
  132. end
  133. else
  134. begin
  135. OutputIsNotCorrect := False;
  136. WriteLn(MistakeFoundMessage);
  137. end;
  138. until OutputIsNotCorrect;
  139. end;
  140.  
  141. procedure Main();
  142. var
  143. P, Answer: integer;
  144. Students : stringMatrix;
  145. begin
  146. LoadMatrixFromFile(Students);
  147. SaveMatrixToFile(Students);
  148. ReadLn;
  149. end;
  150. begin
  151. Main()
  152. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement