Arkathor
Hält's aus hier
Beiträge: 5
|
Verfasst: Mo 31.01.11 10:58
Hallo
Ich muss, als Hausaufgabe, einen Programm entwickeln der wie ein Fahrkartenautomat funktioniert. Am Anfang soll der Kunde Fahrziel wählen, dann Anzahl der Personen angeben.Aus diesen Daten rechne ich den Preis aus und gehe zum zweitem Formular. Dort klickt der Kunde auf Münzen oder Scheinen (Image komponente) und so "bezahlt" er für den ticket. Am Ende wenn der Preis negativ ist (zu viel eingezahlt) soll der Automat Rückgeld ausgeben (in Form von Münzen und Scheinen, also nicht z.B. 20.10 € Rückgeld sondern 1x20€ schein und 1x10Cent Münze), dass wollte ich mit div und Mod lösen, leider kriege ich Meldung "Operand ist auf diesen Operandentyp nicht anwendbar". Ich habe aber gelesen dass div und mod auch mit real Werten funktionieren. Ich wäre sehr dankbar für Hinweise und Hilfe beim Lösen dieses Problems. Anschließend noch quelltext.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71:
| unit FahrAutomat;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,JPEG;
type TForm1 = class(TForm) ZielCBx: TComboBox; ZielLb: TLabel; AnzahlLb: TLabel; AnzahlEd: TEdit; titelnameIMG: TImage; Ok1BT: TButton; procedure FormCreate(Sender: TObject); procedure ZielCBxChange(Sender: TObject); procedure Ok1BTClick(Sender: TObject); private public end;
var Form1: TForm1; Fz: Array[1..10] of String =('Berlin','New York','Pekin','Warschau','Athen','Rom','Paris','Tokyo','Mexiko city','Mond'); Fp:Array[1..10] of real=(3.50,5.50,4.70,8.70,14.20,8.90,24.90,55.60,7.50,25000.00); Bild:TImage; Anzahl:byte; Preis:real; index:byte;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject); var i:byte; Stadt:string; begin titelnameIMG.Picture.LoadfromFile ('titelname.BMP'); ZielCBx.clear; ZielCBx.text:='Fahrziel'; For i:=1 to 10 do begin Stadt:=FZ[i]; ZielCBx.Items.Add(Stadt); end;
end;
procedure TForm1.ZielCBxChange(Sender: TObject);
begin index:=ZielCBx.ItemIndex+1; AnzahlLb.visible:=true; AnzahlEd.visible:=true; end;
procedure TForm1.Ok1BTClick(Sender: TObject); begin Anzahl:=strtoint (AnzahlEd.text); Preis:=(Anzahl) * (Fp[index]); Form2.Show; end;
end. |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238:
| unit Unit2;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls,FahrAutomat, StdCtrls;
type TForm2 = class(TForm) BezahlungIMG: TImage; PreisLb: TLabel; zehncent: TImage; zwanzigcent: TImage; zehncentLb: TLabel; zwanzigcentLb: TLabel; Label1: TLabel; Label2: TLabel; funfzigcent: TImage; eineuro: TImage; zweieuro: TImage; funfeuro: TImage; zehneuro: TImage; zwanzigeuro: TImage; funfzigeuro: TImage; Label3: TLabel; hundereuro: TImage; zweihunderteuro: TImage; funfhunderteuro: TImage; funfzigcentLb: TLabel; eineuroLb: TLabel; zweieuroLb: TLabel; funfeuroLb: TLabel; zehneuroLb: TLabel; zwanzigeuroLb: TLabel; funfzigeuroLb: TLabel; hunderteuroLb: TLabel; zweihundertLb: TLabel; funfhundertLb: TLabel; procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); procedure zehncentClick(Sender: TObject); procedure zwanzigcentClick(Sender: TObject); procedure funfzigcentClick(Sender: TObject); procedure eineuroClick(Sender: TObject); procedure zweieuroClick(Sender: TObject); procedure funfeuroClick(Sender: TObject); procedure zehneuroClick(Sender: TObject); procedure zwanzigeuroClick(Sender: TObject); procedure funfzigeuroClick(Sender: TObject); procedure hundereuroClick(Sender: TObject); procedure zweihunderteuroClick(Sender: TObject); procedure funfhunderteuroClick(Sender: TObject); private public end;
var Form2: TForm2; Ausg:array [1..12] of byte; GeldArray:array [1..11] of real = (500,200,100,50,10,5,2,1,0.50,0.20,0.10);
implementation
{$R *.DFM}
procedure TForm2.FormCreate(Sender: TObject); begin BezahlungIMG.Picture.LoadfromFile ('titelname.BMP');
end;
procedure TForm2.FormShow(Sender: TObject); begin PreisLb.caption:=(floattostr(preis)); end;
Procedure geldrechne; var i:byte; begin i:=11; Ausg[i]:=Preis div Geldarray[i]; Preis:=Preis mod Geldarray[i]; i:=i-1; While i<> 0 do geldrechne; end;
procedure TForm2.zehncentClick(Sender:TObject); begin Preis:=Preis - 0.10; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
procedure TForm2.zwanzigcentClick(Sender: TObject); begin Preis:=Preis - 0.20; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
procedure TForm2.funfzigcentClick(Sender: TObject); begin Preis:=Preis - 0.50; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
procedure TForm2.eineuroClick(Sender: TObject); begin Preis:=Preis - 1; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
procedure TForm2.zweieuroClick(Sender: TObject); begin Preis:=Preis - 2; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
procedure TForm2.funfeuroClick(Sender: TObject); begin Preis:=Preis - 5; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
procedure TForm2.zehneuroClick(Sender: TObject); begin Preis:=Preis - 10; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
procedure TForm2.zwanzigeuroClick(Sender: TObject); begin Preis:=Preis - 20; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
procedure TForm2.funfzigeuroClick(Sender: TObject); begin Preis:=Preis - 50; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
procedure TForm2.hundereuroClick(Sender: TObject); begin Preis:=Preis - 100; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
procedure TForm2.zweihunderteuroClick(Sender: TObject); begin Preis:=Preis - 200; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
procedure TForm2.funfhunderteuroClick(Sender: TObject); begin Preis:=Preis - 500; PreisLb.caption:= floattostr (Preis); If Preis < 0 then begin preis:=preis * (-1); PreisLB.visible:=false; geldrechne; end; end;
end. |
|