Advertisement
Guest User

Delphi Epta

a guest
Jun 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 7.15 KB | None | 0 0
  1. unit Model;
  2.  
  3. interface
  4.   uses
  5.     SysUtils;
  6.  
  7.   type
  8.     TStudent = record
  9.                  Surname : String[30];
  10.                  Firstname : String[30];
  11.                  Patronymic : String[30];
  12.                  Faculty : String[10];
  13.                  Specialty : String[10];
  14.                  Group : String[10];
  15.                  FormOfStudy : String[10];
  16.                  Ratings : String[30];
  17.                  AverageScore : String[5];
  18.                end;
  19.  
  20.     TStudentsList = record
  21.                       Len : Word;
  22.                       Data : array[1..1000] of TStudent;
  23.                     end;
  24.  
  25.   function GetDataFromFile(const PathToFile: String): TStudentsList;
  26.  
  27.   procedure WriteDataToFile(var StudList: TStudentsList;
  28.     const PathToFile: String);
  29.  
  30.   procedure AddStudent(var StudList: TStudentsList;
  31.     const lSurname, lFirstname, lPatronymic: String;
  32.     const lFaculty, lSpecialty, lGroup: String;
  33.     const lFormOfStudy, lRatings: String);
  34.  
  35.   procedure DeleteStudent(var StudList: TStudentsList;
  36.     const Index: Word);
  37.  
  38.   procedure ChangeStudent(var StudList: TStudentsList;
  39.     const Index: Word; const lSurname, lFirstname,
  40.     lPatronymic: String; const lFaculty, lSpecialty,
  41.     lGroup: String; const lFormOfStudy, lRatings: String);
  42.  
  43.   function CalcAverScore(const Str: String): Real;
  44.  
  45.   function FindStudent(const StudList: TStudentsList;
  46.     const lSurname, lFirstname, lPatronymic,
  47.     lGroup: String): Integer;
  48.  
  49.   function GetBestStudents(const StudList: TStudentsList;
  50.     IsPay: Boolean): TStudentsList;
  51.  
  52.   function SortRatings(const StudList: TStudentsList;
  53.     const Pay: Boolean): TStudentsList;
  54.  
  55.   function SortSurname(const StudList: TStudentsList;
  56.     const Group: String): TStudentsList;
  57.  
  58. implementation
  59.  
  60.   function GetDataFromFile;
  61.   var
  62.     DataFile : File of TStudent;
  63.     I : Word;
  64.   begin
  65.     AssignFile(DataFile, PathToFile);
  66.     Reset(DataFile);
  67.  
  68.     I := 1;
  69.     while not Eof(DataFile) do
  70.     begin
  71.       Read(DataFile, Result.Data[I]);
  72.       Inc(I);
  73.     end;
  74.  
  75.     Result.Len := I - 1;
  76.   end;
  77.  
  78.   procedure WriteDataToFile;
  79.   var
  80.     DataFile : File of TStudent;
  81.     I : Word;
  82.   begin
  83.     AssignFile(DataFile, PathToFile);
  84.     Rewrite(DataFile);
  85.  
  86.     for I := 1 to StudList.Len do
  87.       Write(DataFile, StudList.Data[I]);
  88.   end;
  89.  
  90.   procedure AddStudent;
  91.   begin
  92.     StudList.Len := StudList.Len + 1;
  93.  
  94.     with StudList.Data[StudList.Len] do
  95.     begin
  96.       Surname := lSurname;
  97.       Firstname := lFirstname;
  98.       Patronymic := lPatronymic;
  99.       Faculty := lFaculty;
  100.       Specialty := lSpecialty;
  101.       Group := lGroup;
  102.       FormOfStudy := lFormOfStudy;
  103.       Ratings := lRatings;
  104.       AverageScore := FloatToStr(CalcAverScore(lRatings));
  105.     end;
  106.  
  107.   end;
  108.  
  109.   procedure DeleteStudent;
  110.   var
  111.     I : Word;
  112.   begin
  113.     if Index+1 <> StudList.Len then
  114.       for I := Index + 1 to StudList.Len - 1 do
  115.         StudList.Data[I] := StudList.Data[I+1];
  116.     StudList.Data[StudList.Len].Surname := '';
  117.     StudList.Data[StudList.Len].Firstname := '';
  118.     StudList.Data[StudList.Len].Patronymic := '';
  119.     StudList.Data[StudList.Len].Faculty := '';
  120.     StudList.Data[StudList.Len].Specialty := '';
  121.     StudList.Data[StudList.Len].Group := '';
  122.     StudList.Data[StudList.Len].FormOfStudy := '';
  123.     StudList.Data[StudList.Len].Ratings := '';
  124.     StudList.Data[StudList.Len].AverageScore := '';
  125.     Dec(StudList.Len);
  126.   end;
  127.  
  128.   procedure ChangeStudent;
  129.   begin
  130.     with StudList.Data[Index+1] do
  131.     begin
  132.       Surname := lSurname;
  133.       Firstname := lFirstname;
  134.       Patronymic := lPatronymic;
  135.       Faculty := lFaculty;
  136.       Specialty := lSpecialty;
  137.       Group := lGroup;
  138.       FormOfStudy := lFormOfStudy;
  139.       Ratings := lRatings;
  140.       AverageScore := FloatToStr(CalcAverScore(lRatings));
  141.     end;
  142.   end;
  143.  
  144.   function CalcAverScore;
  145.   var
  146.     I, J : Byte;
  147.   begin
  148.     Result := 0;
  149.     J := 0;
  150.     I := 1;
  151.  
  152.     while I <= Length(Str) do
  153.     begin
  154.       if (Str[I] <> ',') and (Str[I+1] <> ',')  then
  155.       begin
  156.         Result := Result + StrToFloat(Str[I] + Str[I+1]);
  157.         Inc(J);
  158.         Inc(I);
  159.       end
  160.       else if (Str[I] <> ',') then
  161.       begin
  162.         Result := Result + StrToFloat(Str[I]);
  163.         Inc(J);
  164.       end;
  165.       Inc(I);
  166.     end;
  167.     Result := Result / J;
  168.   end;
  169.  
  170.   function FindStudent;
  171.   var
  172.     I : Word;
  173.     IsStudFind : Boolean;
  174.   begin
  175.     I := 1;
  176.     IsStudFind := False;
  177.     Result := -1;
  178.  
  179.     while (I <= StudList.Len) and (not IsStudFind) do
  180.     begin
  181.       if (StudList.Data[I].Surname = lSurname)
  182.         and (StudList.Data[I].Firstname = lFirstname)
  183.         and (StudList.Data[I].Patronymic = lPatronymic)
  184.         and (StudList.Data[I].Group = lGroup) then
  185.       begin
  186.         Result := I;
  187.         IsStudFind := True;
  188.       end;
  189.       Inc(I);
  190.     end;
  191.   end;
  192.  
  193.   function GetBestStudents;
  194.   var
  195.     I : Word;
  196.   begin
  197.     Result.Len := 0;
  198.  
  199.     for I := 1 to StudList.Len do
  200.     begin
  201.       if IsPay = True then
  202.       begin
  203.         if (StrToFloat(StudList.Data[I].AverageScore) >= 9)
  204.           and (StudList.Data[I].FormOfStudy = 'Платная') then
  205.         begin
  206.           Inc(Result.Len);
  207.           Result.Data[Result.Len] := StudList.Data[I];
  208.         end
  209.       end
  210.       else
  211.         if (StrToFloat(StudList.Data[I].AverageScore) >= 9)
  212.           and (StudList.Data[I].FormOfStudy = 'Бюджетная') then
  213.         begin
  214.           Inc(Result.Len);
  215.           Result.Data[Result.Len] := StudList.Data[I];
  216.         end;
  217.     end;
  218.   end;
  219.  
  220.   function SortRatings;
  221.   var
  222.     I, J : Word;
  223.     X : Real;
  224.     Tmp : TStudent;
  225.   begin
  226.     Result.Len := 0;
  227.  
  228.     if Pay = True then
  229.     begin
  230.       for I := 1 to StudList.Len do
  231.       begin
  232.         if StudList.Data[I].FormOfStudy = 'Платная' then
  233.         begin
  234.           Inc(Result.Len);
  235.           Result.Data[Result.Len] := StudList.Data[I];
  236.         end;
  237.       end;
  238.     end
  239.     else
  240.       for I := 1 to StudList.Len do
  241.       begin
  242.         if StudList.Data[I].FormOfStudy = 'Бюджетная' then
  243.         begin
  244.           Inc(Result.Len);
  245.           Result.Data[Result.Len] := StudList.Data[I];
  246.         end;
  247.       end;
  248.  
  249.     for I := 2 to Result.Len do
  250.     begin
  251.       Tmp := Result.Data[I];
  252.       X := StrToFloat(Result.Data[I].AverageScore);
  253.       J := I - 1;
  254.       while (J >= 1) and
  255.         (StrToFloat(Result.Data[J].AverageScore) < X) do
  256.       begin
  257.         Result.Data[J+1] := Result.Data[J];
  258.         Dec(J);
  259.       end;
  260.       Result.Data[J+1] := Tmp;
  261.     end;
  262.   end;
  263.  
  264.   function SortSurname;
  265.   var
  266.     I, J : Word;
  267.     Tmp : TStudent;
  268.     X : String;
  269.   begin
  270.     Result.Len := 0;
  271.  
  272.     for I := 1 to StudList.Len do
  273.       if StudList.Data[I].Group = Group then
  274.       begin
  275.         Inc(Result.Len);
  276.         Result.Data[Result.Len] := StudList.Data[I];
  277.       end;
  278.  
  279.     for I := 2 to Result.Len do
  280.     begin
  281.       Tmp := Result.Data[I];
  282.       X := Result.Data[I].Surname;
  283.       J := I - 1;
  284.       while (J >= 1) and
  285.         (Result.Data[J].AverageScore < X) do
  286.       begin
  287.         Result.Data[J+1] := Result.Data[J];
  288.         Dec(J);
  289.       end;
  290.       Result.Data[J+1] := Tmp;
  291.     end;
  292.   end;
  293.  
  294. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement