0% found this document useful (0 votes)
5 views6 pages

Advanced Databases

The document defines three classes: TAgent, TProperty, and TPropertyTable for managing real estate properties and agents. TAgent holds the agent's name and the count of properties, TProperty associates a property with an agent, and TPropertyTable manages the collection of properties and agents. Additionally, it provides functionality to add properties and assign them to the agent with the least properties.

Uploaded by

mavislossie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Advanced Databases

The document defines three classes: TAgent, TProperty, and TPropertyTable for managing real estate properties and agents. TAgent holds the agent's name and the count of properties, TProperty associates a property with an agent, and TPropertyTable manages the collection of properties and agents. Additionally, it provides functionality to add properties and assign them to the agent with the least properties.

Uploaded by

mavislossie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

```delphi

unit PropertyManagement;
interface
uses
SysUtils, Classes;
type
TAgent = class
private
FName: string;
FProperties: Integer;
public
constructor Create(const AName:
string);
property Name: string read FName;
property Properties: Integer read
FProperties;
end;
TProperty = class
private
FAgent: TAgent;
public
constructor Create(const AAgent:
TAgent);
property Agent: TAgent read FAgent;
end;
TPropertyTable = class
private
FProperties: TList;
FAgents: TList;
public
constructor Create;
destructor Destroy; override;
procedure AddProperty(const AAgent:
TAgent);
function GetAgentWithLeastProperties:
TAgent;
end;
implementation
constructor TAgent.Create(const AName:
string);
begin
FName := AName;
FProperties := 0;
end;
constructor TProperty.Create(const
AAgent: TAgent);
begin
FAgent := AAgent;
AAgent.FProperties :=
AAgent.FProperties + 1;
end;
constructor TPropertyTable.Create;
begin
FProperties := TList.Create;
FAgents := TList.Create;
end;
destructor TPropertyTable.Destroy;
var
I: Integer;
begin
for I := 0 to FProperties.Count - 1 do
TObject(FProperties[I]).Free;
FProperties.Free;
FAgents.Free;
inherited Destroy;
end;
procedure
TPropertyTable.AddProperty(const
AAgent: TAgent);
var
NewProperty: TProperty;
begin
NewProperty :=
TProperty.Create(AAgent);
FProperties.Add(NewProperty);
end;
function
TPropertyTable.GetAgentWithLeastPropert
ies: TAgent;
var
I: Integer;
MinProperties: Integer;
MinAgent: TAgent;
begin
MinProperties := MaxInt;
MinAgent := nil;
for I := 0 to FAgents.Count - 1 do
begin
if TAgent(FAgents[I]).Properties <
MinProperties then
begin
MinProperties :=
TAgent(FAgents[I]).Properties;
MinAgent := TAgent(FAgents[I]);
end;
end;
Result := MinAgent;
end;
end.
```
In this code, we have three classes:
`TAgent`, `TProperty`, and
`TPropertyTable`. The `TAgent` class
represents an agent with a name and a
number of properties. The `TProperty`
class represents a property assigned to an
agent. The `TPropertyTable` class
manages the properties and agents.
To add a property to the property table and
automatically assign it to the agent with the
least number of properties, you can use the
following code:
```delphi
var
PropertyTable: TPropertyTable;
Agent: TAgent;
begin
PropertyTable := TPropertyTable.Create;
// Create agents
Agent := TAgent.Create('Agent A');
PropertyTable.AddProperty(Agent);
Agent := TAgent.Create('Agent B');
PropertyTable.AddProperty(Agent);
Agent := TAgent.Create('Agent C');
PropertyTable.AddProperty(Agent);
// Add property and assign it to the agent
with the least number of properties
Agent :=
PropertyTable.GetAgentWithLeastProperti
es;
PropertyTable.Add

You might also like