Delphi

Stian Søiland, IT 111, øvingsgruppe 15 (stud.ass. Kari Alvheim)

Delphi - Øving 5 - Oppgave 5

Oppgave 5

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    tinput: TEdit;
    toutput: TEdit;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button2Click(Sender: TObject);
begin
 tinput.clear;
 toutput.clear;
end;

procedure TForm1.Button1Click(Sender: TObject);

var tall,temptall1,temptall2:integer;
    input,output:string;

function ener(tall:integer):string;
 begin
  tall := tall mod 10;
  case tall of
   0: ener := '';
   1: ener := 'én';
   2: ener := 'to';
   3: ener := 'tre';
   4: ener := 'fire';
   5: ener := 'fem';
   6: ener := 'seks';
   7: ener := 'sju';
   8: ener := 'åtte';
   9: ener := 'ni';
  end;
 end;

function lave(tall:integer):string;
 var temp:string;
 begin
  case tall of
   10..19: case tall of
             10: lave := 'ti';
             11: lave := 'elleve';
             12: lave := 'tolv';
             13: lave := 'tretten';
             14: lave := 'fjorten';
             15: lave := 'femten';
             16: lave := 'seksten';
             17: lave := 'sytten';
             18: lave := 'atten';
             19: lave := 'nitten';
           end;
  else
         temp := ener(tall);
         if (tall > 19) and (temp <> '') then temp := '-' + temp;
         case tall of
          0..9:   lave := temp;
          20..29: lave := 'tjue' + temp;
          30..39: lave := 'tretti' + temp;
          40..49: lave := 'førti' + temp;
          50..59: lave := 'femti' + temp;
          60..69: lave := 'seksti' + temp;
          70..79: lave := 'søtti' + temp;
          80..89: lave := 'åtti' + temp;
          90..99: lave := 'nitti' + temp;
         end;
  end;
 end;


begin
 input := tinput.text;
 tall := StrToInt(input);
 if tall < 0
  then ShowMessage('Negative beløp er ikke tillatt')
  else
   if tall > 100000
    then ShowMessage('Beløp ikke disponibelt på konto')
    else
     begin
      temptall1 := tall MOD 100;
      output := lave(temptall1);
      if (tall > 99) then
       begin
        temptall1 := tall MOD 1000;
        temptall2 := temptall1 DIV 100;
        if (temptall1 >0) and (output <> '') then output := '-og-' + output;
        case temptall2 of
         1: output := 'ett-hundre' + output;
         2..9: output := ener(temptall2) + '-hundre' + output;
        end;
        if (tall > temptall1) and (temptall2 > 0) and (output <> '') then output := '-og-' + output;
        temptall2 := tall DIV 1000;
        case temptall2 of
         1: output := 'ett-tusen' + output;
         2..99: output := lave(temptall2) + '-tusen' + output;
         100: output := 'hundre-tusen' + output;
        end;
       end;
      toutput.text := output;
     end;
end;

end.
  

 


© Stian Søiland 1998

Valid HTML 4.0!