unit Form.Main;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
const
NotenSchlüssel:
array [1 .. 5]
of Single = ( 96.0, 80.0, 60.0, 40.0, 20.0 );
type
TForm1 =
class( TForm )
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Button1Click( Sender: TObject );
private
{Private-Deklarationen}
public
{Public-Deklarationen}
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetSchulnoteFromPercent( APercent: Single ): Integer;
begin
// Guard
if ( APercent < 0 )
or ( APercent > 100 )
then
raise EArgumentOutOfRangeException.Create( '
Der Wert muss zwischen 0% und 100% liegen!' );
Result := Low( NotenSchlüssel );
repeat
if APercent >= NotenSchlüssel[Result]
then
Exit;
Inc( Result );
until Result > High( NotenSchlüssel );
end;
function GetSchulnoteFromPunkte( AErreicht, AMax : Integer ) : Integer;
begin
// Guard
if AErreicht < 0
then
raise EArgumentOutOfRangeException.Create( '
Die erreichte Punktzahl darf nicht kleiner 0 sein!' );
if AMax <= 0
then
raise EArgumentOutOfRangeException.Create( '
Die maximale Punktzahl darf nicht kleiner oder gleich 0 sein!' );
if AErreicht > AMax
then
raise EArgumentOutOfRangeException.CreateFmt( '
Die erreichte Punktzahl (%d) kann nicht größer als die maximale Punktzahl (%d) sein!',
[AErreicht, AMax] );
Result := GetSchulnoteFromPercent( AErreicht / AMax * 100 );
end;
procedure TForm1.Button1Click( Sender: TObject );
var
LErreichtePunktZahl, LMaxPunktZahl: Integer;
begin
LErreichtePunktZahl := StrToInt( Edit1.Text );
LMaxPunktZahl := StrToInt( Edit2.Text );
Label1.Caption := IntToStr( GetSchulnoteFromPunkte( LErreichtePunktZahl, LMaxPunktZahl ) );
end;
end.