pascalabcnet/TestSuite/CompilationSamples/Students.pas

39 lines
938 B
ObjectPascal
Raw Permalink Normal View History

2020-06-26 18:05:06 +03:00
//Перегрузка операторов
2015-05-14 22:35:07 +03:00
type
Student = class
Name: string;
Height: integer;
public
constructor(Name: string; Height: integer);
begin
Self.Name := Name;
Self.Height := Height;
end;
class function operator<(left,right: Student): boolean;
// Сравнение по росту
2015-05-14 22:35:07 +03:00
begin
Result := left.Height < right.Height;
end;
class function operator>(left,right: Student): boolean;
begin
Result := left.Height > right.Height;
end;
function ToString: string; override;
begin
Result := string.Format('{0} ({1})', Name, Height);
end;
end;
var
s1,s2: Student;
begin
s1 := new Student('Stepa Morkovkin',188);
s2 := new Student('Petya Pomidorov',180);
Writeln('s1: ',s1);
Writeln('s2: ',s2);
Writeln;
Writeln('s1<s2: ',s1<s2);
//
2020-06-26 18:05:06 +03:00
Writeln('Student.operator>(s1,s2): ',{Student.operator>(s1,s2)}s1>s2);
2015-05-14 22:35:07 +03:00
end.