Pascal · lesson 17 of 30 · Data, functions and the command lineJoin fields into a record
A record keeps the slot, model and temperature of one disk together. := copies all of it.
17-records.pas Download 17-records.pas
program Records;
{$mode objfpc}{$H+}
type
TDisk = record
Slot: Integer;
Model: string;
Temp: Integer;
end;
procedure Show(const D: TDisk);
begin
WriteLn('slot ', D.Slot, ' ', D.Model, ' ', D.Temp, ' C');
end;
var
Disks: array[1..2] of TDisk;
I: Integer;
begin
Disks[1].Slot := 1;
Disks[1].Model := 'Example HDD A';
Disks[1].Temp := 38;
Disks[2] := Disks[1];
Disks[2].Slot := 2;
Disks[2].Temp := 41;
for I := 1 to 2 do
Show(Disks[I]);
end.
Terminal
$ ./17-records
slot 1 Example HDD A 38 C
slot 2 Example HDD A 41 CExercise
Add the size and print the sum of both disks.