Modellierung und Simulation - Objektorientierte Programmierung
| Autor: | Prof. Dr.-Ing. Schneider |
| Termin: | 23.05.2025 |
Aufgabe 9.1
Erweitern Sie den struct person durch weitere Komponenten, z. B.:
- Strasse,
- Hausnummer,
- Postleitzahl,
- Ort,
- Geburtsdatum [Array aus 3 Zahlen].
| Musterlösung 9.1 |
%
% >> p = Person( 'Hannah', '0815', 'Weg', 5, 22222, 'HH' )
% >> whos p
%
classdef Person
properties
name = '';
telnr = 0;
strasse = '';
hausnr = 1;
plz = 1;
ort = '';
end % properties
methods
function o = Person( name, telnr, str, hnr, plz, ort )
o.name = name;
o.telnr = telnr;
o.strasse = str;
o.hausnr = hnr;
o.plz = plz;
o.ort = ort;
end
function print( o )
fprintf( 'Name: %s, Tel.Nr.: %g,\n', ...
o.name, o.telnr );
fprintf( 'wohnt: %s %g, %g %s.\n', ...
o.strasse, o.hausnr, o.plz, o.ort );
end
function info( o )
fprintf( 'Telefonnummer %g gehört zu %s.\n', ...
o.telnr, o.name );
end
end % methods
end % classdef
|
→ zurück zum Hauptartikel: BSE Modellierung und Simulation - SoSe25