Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Model;
- interface
- uses
- SysUtils;
- type
- TStudent = record
- Surname : String[30];
- Firstname : String[30];
- Patronymic : String[30];
- Faculty : String[10];
- Specialty : String[10];
- Group : String[10];
- FormOfStudy : String[10];
- Ratings : String[30];
- AverageScore : String[5];
- end;
- TStudentsList = record
- Len : Word;
- Data : array[1..1000] of TStudent;
- end;
- function GetDataFromFile(const PathToFile: String): TStudentsList;
- procedure WriteDataToFile(var StudList: TStudentsList;
- const PathToFile: String);
- procedure AddStudent(var StudList: TStudentsList;
- const lSurname, lFirstname, lPatronymic: String;
- const lFaculty, lSpecialty, lGroup: String;
- const lFormOfStudy, lRatings: String);
- procedure DeleteStudent(var StudList: TStudentsList;
- const Index: Word);
- procedure ChangeStudent(var StudList: TStudentsList;
- const Index: Word; const lSurname, lFirstname,
- lPatronymic: String; const lFaculty, lSpecialty,
- lGroup: String; const lFormOfStudy, lRatings: String);
- function CalcAverScore(const Str: String): Real;
- function FindStudent(const StudList: TStudentsList;
- const lSurname, lFirstname, lPatronymic,
- lGroup: String): Integer;
- function GetBestStudents(const StudList: TStudentsList;
- IsPay: Boolean): TStudentsList;
- function SortRatings(const StudList: TStudentsList;
- const Pay: Boolean): TStudentsList;
- function SortSurname(const StudList: TStudentsList;
- const Group: String): TStudentsList;
- implementation
- function GetDataFromFile;
- var
- DataFile : File of TStudent;
- I : Word;
- begin
- AssignFile(DataFile, PathToFile);
- Reset(DataFile);
- I := 1;
- while not Eof(DataFile) do
- begin
- Read(DataFile, Result.Data[I]);
- Inc(I);
- end;
- Result.Len := I - 1;
- end;
- procedure WriteDataToFile;
- var
- DataFile : File of TStudent;
- I : Word;
- begin
- AssignFile(DataFile, PathToFile);
- Rewrite(DataFile);
- for I := 1 to StudList.Len do
- Write(DataFile, StudList.Data[I]);
- end;
- procedure AddStudent;
- begin
- StudList.Len := StudList.Len + 1;
- with StudList.Data[StudList.Len] do
- begin
- Surname := lSurname;
- Firstname := lFirstname;
- Patronymic := lPatronymic;
- Faculty := lFaculty;
- Specialty := lSpecialty;
- Group := lGroup;
- FormOfStudy := lFormOfStudy;
- Ratings := lRatings;
- AverageScore := FloatToStr(CalcAverScore(lRatings));
- end;
- end;
- procedure DeleteStudent;
- var
- I : Word;
- begin
- if Index+1 <> StudList.Len then
- for I := Index + 1 to StudList.Len - 1 do
- StudList.Data[I] := StudList.Data[I+1];
- StudList.Data[StudList.Len].Surname := '';
- StudList.Data[StudList.Len].Firstname := '';
- StudList.Data[StudList.Len].Patronymic := '';
- StudList.Data[StudList.Len].Faculty := '';
- StudList.Data[StudList.Len].Specialty := '';
- StudList.Data[StudList.Len].Group := '';
- StudList.Data[StudList.Len].FormOfStudy := '';
- StudList.Data[StudList.Len].Ratings := '';
- StudList.Data[StudList.Len].AverageScore := '';
- Dec(StudList.Len);
- end;
- procedure ChangeStudent;
- begin
- with StudList.Data[Index+1] do
- begin
- Surname := lSurname;
- Firstname := lFirstname;
- Patronymic := lPatronymic;
- Faculty := lFaculty;
- Specialty := lSpecialty;
- Group := lGroup;
- FormOfStudy := lFormOfStudy;
- Ratings := lRatings;
- AverageScore := FloatToStr(CalcAverScore(lRatings));
- end;
- end;
- function CalcAverScore;
- var
- I, J : Byte;
- begin
- Result := 0;
- J := 0;
- I := 1;
- while I <= Length(Str) do
- begin
- if (Str[I] <> ',') and (Str[I+1] <> ',') then
- begin
- Result := Result + StrToFloat(Str[I] + Str[I+1]);
- Inc(J);
- Inc(I);
- end
- else if (Str[I] <> ',') then
- begin
- Result := Result + StrToFloat(Str[I]);
- Inc(J);
- end;
- Inc(I);
- end;
- Result := Result / J;
- end;
- function FindStudent;
- var
- I : Word;
- IsStudFind : Boolean;
- begin
- I := 1;
- IsStudFind := False;
- Result := -1;
- while (I <= StudList.Len) and (not IsStudFind) do
- begin
- if (StudList.Data[I].Surname = lSurname)
- and (StudList.Data[I].Firstname = lFirstname)
- and (StudList.Data[I].Patronymic = lPatronymic)
- and (StudList.Data[I].Group = lGroup) then
- begin
- Result := I;
- IsStudFind := True;
- end;
- Inc(I);
- end;
- end;
- function GetBestStudents;
- var
- I : Word;
- begin
- Result.Len := 0;
- for I := 1 to StudList.Len do
- begin
- if IsPay = True then
- begin
- if (StrToFloat(StudList.Data[I].AverageScore) >= 9)
- and (StudList.Data[I].FormOfStudy = 'Платная') then
- begin
- Inc(Result.Len);
- Result.Data[Result.Len] := StudList.Data[I];
- end
- end
- else
- if (StrToFloat(StudList.Data[I].AverageScore) >= 9)
- and (StudList.Data[I].FormOfStudy = 'Бюджетная') then
- begin
- Inc(Result.Len);
- Result.Data[Result.Len] := StudList.Data[I];
- end;
- end;
- end;
- function SortRatings;
- var
- I, J : Word;
- X : Real;
- Tmp : TStudent;
- begin
- Result.Len := 0;
- if Pay = True then
- begin
- for I := 1 to StudList.Len do
- begin
- if StudList.Data[I].FormOfStudy = 'Платная' then
- begin
- Inc(Result.Len);
- Result.Data[Result.Len] := StudList.Data[I];
- end;
- end;
- end
- else
- for I := 1 to StudList.Len do
- begin
- if StudList.Data[I].FormOfStudy = 'Бюджетная' then
- begin
- Inc(Result.Len);
- Result.Data[Result.Len] := StudList.Data[I];
- end;
- end;
- for I := 2 to Result.Len do
- begin
- Tmp := Result.Data[I];
- X := StrToFloat(Result.Data[I].AverageScore);
- J := I - 1;
- while (J >= 1) and
- (StrToFloat(Result.Data[J].AverageScore) < X) do
- begin
- Result.Data[J+1] := Result.Data[J];
- Dec(J);
- end;
- Result.Data[J+1] := Tmp;
- end;
- end;
- function SortSurname;
- var
- I, J : Word;
- Tmp : TStudent;
- X : String;
- begin
- Result.Len := 0;
- for I := 1 to StudList.Len do
- if StudList.Data[I].Group = Group then
- begin
- Inc(Result.Len);
- Result.Data[Result.Len] := StudList.Data[I];
- end;
- for I := 2 to Result.Len do
- begin
- Tmp := Result.Data[I];
- X := Result.Data[I].Surname;
- J := I - 1;
- while (J >= 1) and
- (Result.Data[J].AverageScore < X) do
- begin
- Result.Data[J+1] := Result.Data[J];
- Dec(J);
- end;
- Result.Data[J+1] := Tmp;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement