Delphi-PRAXiS
Seite 1 von 3  1 23      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Punkt vor Strich? (https://www.delphipraxis.net/8015-punkt-vor-strich.html)

Die Muhkuh 27. Aug 2003 07:58


Punkt vor Strich?
 
Ich hab nen Rechner programmiert der mit 2 bis 5 Zahlen rechnet allerding so wie man es ihm sagt also 5+4*2-5=13 eigentlich müsste ja 8 rauskommen.

Im Klarext wie kann ich dem Rechner "beibringen" das er Punkt vor Strich rechnet?

greetz

Spider

Illuminator-23-5 27. Aug 2003 08:03

Re: Punkt vor Strich?
 
du könntest von vorne bis hinten alles durchgehen und alle multiplikationen/divisionen erledigen und erst in einem 2. Schritt addition/subtraktion
5+4*2-5=
5+8-5=
8

Die Muhkuh 27. Aug 2003 18:22

Re: Punkt vor Strich?
 
Ähm ja schön, nur wie geht das??? Hast du nen Beispiel Code?

Illuminator-23-5 27. Aug 2003 18:31

Re: Punkt vor Strich?
 
wie speicherst du die rechnung? ich könnt dann im fall schnell was schreiben

Die Muhkuh 27. Aug 2003 18:52

Re: Punkt vor Strich?
 
Also hier ist der !!!gesamte!!! Code:
Delphi-Quellcode:
var
  Rechnen: TRechnen;
  a, b, c, d, e, f, g, z1, z2, z3, er : Extended;

implementation

uses Unit1, Unit2, Unit4, Unit5, Unit6, Unit7, shellapi;

{$R *.DFM}

procedure TRechnen.Button5Click(Sender: TObject);
begin
 
  if Combobox5.itemindex = 0 then
    begin
      a := strtofloat (Edit1.text);
      b := strtofloat (Edit2.text);

        case Combobox1.itemindex of
          0: er := a + b;
          1: er := a - b;
          2: er := a * b;
          3: er := a / b;
        end;
      Panel1.caption := floattostr (er);
    end;

  if Combobox5.itemindex = 1 then
    begin
      a := strtofloat (Edit1.text);
      b := strtofloat (edit2.text);
      c := strtofloat (Edit3.text);

        case Combobox1.ItemIndex of
          0: z1 := a + b;
          1: z1 := a - b;
          2: z1 := a * b;
          3: z1 := a / b;
        end;

        case combobox2.itemindex of
          0: er := z1 + c;
          1: er := z1 - c;
          2: er := z1 * c;
          3: er := z1 / c;
        end;
      Panel1.caption := floattostr (er);
     end;

    if Combobox5.itemindex = 2 then
      begin
        a := strtofloat (Edit1.text);
        b := strtofloat (Edit2.text);
        c := strtofloat (Edit3.text);
        d := strtofloat (Edit4.text);

          case Combobox1.itemindex of
            0: z1 := a + b;
            1: z1 := a - b;
            2: z1 := a * b;
            3: z1 := a / b;
          end;

          case combobox2.itemindex of
            0: z2 := z1 + c;
            1: z2 := z1 - c;
            2: z2 := z1 * c;
            3: z2 := z1 / c;
          end;

          case Combobox3.ItemIndex of
            0 : er := z2 + d;
            1 : er := z2 - d;
            2 : er := z2 * d;
            3 : er := z2 / d;
          end;
        Panel1.caption := floattostr (er);
      end;

    if Combobox5.itemindex = 3 then
      begin
         a := strtofloat (Edit1.text);
         b := strtofloat (Edit2.text);
         c := strtofloat (Edit3.text);
         d := strtofloat (Edit4.text);
         e := strtofloat (Edit5.text);

           case Combobox1.itemindex of
             0: z1 := a + b;
             1: z1 := a - b;
             2: z1 := a * b;
             3: z1 := a / b;
           end;

           case combobox2.itemindex of
             0: z2 := z1 + c;
             1: z2 := z1 - c;
             2: z2 := z1 * c;
             3: z2 := z1 / c;
           end;

           case Combobox3.ItemIndex of
             0 : z3 := z2 + d;
             1 : z3 := z2 - d;
             2 : z3 := z2 * d;
             3 : z3 := z2 / d;
           end;

           case Combobox3.ItemIndex of
             0 : er := z3 + d;
             1 : er := z3 - d;
             2 : er := z3 * d;
             3 : er := z3 / d;
           end;
         Panel1.caption := floattostr (er);
      end;

    if Combobox5.itemindex = 4 then
      begin
        f := strtofloat (Edit1.text);

        er := Sqr(f);
        Panel1.caption := floattostr (er);
      end;
    if Combobox5.ItemIndex = 5 then
      begin
        g := strtofloat (Edit1.text);

        er:= Sqrt(g) ;
        Panel1.caption := floattostr (er);
      end;
end;

procedure TRechnen.ComboBox5Change(Sender: TObject);
begin
  if Combobox5.ItemIndex = 0 then
    begin
      Edit1.visible := true;
      Edit2.visible := true;
      Edit3.visible := false;
      Edit4.visible := false;
      Edit5.visible := false;
      Edit1.text := '';
      Edit2.text := '';
      Edit3.text := '';
      Edit4.text := '';
      Edit5.text := '';

      Combobox1.visible := true;
      Combobox2.visible := false;
      combobox3.visible := false;
      Combobox4.visible := false;
      Combobox1.Text := '';
      Combobox2.Text := '';
      Combobox3.Text := '';
      Combobox4.Text := '';
      Combobox5.Text := '';

      Panel1.Caption := '';
     end;

  if Combobox5.itemindex = 1 then
    begin
      Edit1.visible := true;
      Edit2.visible := true;
      Edit3.visible := true;
      Edit4.visible := false;
      Edit5.visible := false;
      Edit1.text := '';
      Edit2.text := '';
      Edit3.text := '';
      Edit4.text := '';
      Edit5.text := '';

      Combobox1.visible := true;
      Combobox2.visible := true;
      combobox3.visible := false;
      Combobox4.visible := false;
      Combobox1.Text := '';
      Combobox2.Text := '';
      Combobox3.Text := '';
      Combobox4.Text := '';
      Combobox5.Text := '';

      Panel1.Caption := '';
    end;

  if Combobox5.itemindex = 2 then
    begin
      Edit1.visible := true;
      Edit2.visible := true;
      Edit3.visible := true;
      Edit4.visible := true;
      Edit5.visible := false;
      Edit1.text := '';
      Edit2.text := '';
      Edit3.text := '';
      Edit4.text := '';
      Edit5.text := '';

      Combobox1.visible := true;
      Combobox2.visible := true;
      combobox3.visible := true;
      Combobox4.visible := false;
      Combobox1.Text := '';
      Combobox2.Text := '';
      Combobox3.Text := '';
      Combobox4.Text := '';
      Combobox5.Text := '';

      Panel1.Caption := '';
    end;

   if Combobox5.itemindex = 3 then
     begin
       Edit1.visible := true;
       Edit2.visible := true;
       Edit3.visible := true;
       Edit4.visible := true;
       Edit5.visible := true;
       Edit1.text := '';
       Edit2.text := '';
       Edit3.text := '';
       Edit4.text := '';
       Edit5.text := '';

       Combobox1.visible := true;
       Combobox2.visible := true;
       combobox3.visible := true;
       Combobox4.visible := true;
       Combobox1.Text := '';
       Combobox2.Text := '';
       Combobox3.Text := '';
       Combobox4.Text := '';
       Combobox5.Text := '';

       Panel1.Caption := '';
     end;

   if Combobox5.itemindex = 4 then
     begin
       Edit1.visible := true;
       Edit2.visible := false;
       Edit3.visible := false;
       Edit4.visible := false;
       Edit5.visible := false;
       Edit1.text := '';
       Edit2.text := '';
       Edit3.text := '';
       Edit4.text := '';
       Edit5.text := '';

       Combobox1.visible := false;
       Combobox2.visible := false;
       combobox3.visible := false;
       Combobox4.visible := false;
       Combobox1.Text := '';
       Combobox2.Text := '';
       Combobox3.Text := '';
       Combobox4.Text := '';
       Combobox5.Text := '';

       Panel1.Caption := '';
     end;

   if Combobox5.itemindex = 5 then
     begin
       Edit1.visible := true;
       Edit2.visible := false;
       Edit3.visible := false;
       Edit4.visible := false;
       Edit5.visible := false;
       Edit1.text := '';
       Edit2.text := '';
       Edit3.text := '';
       Edit4.text := '';
       Edit5.text := '';

       Combobox1.visible := false;
       Combobox2.visible := false;
       combobox3.visible := false;
       Combobox4.visible := false;
       Combobox1.Text := '';
       Combobox2.Text := '';
       Combobox3.Text := '';
       Combobox4.Text := '';
       Combobox5.Text := '';

       Panel1.Caption := '';
     end;
end;
Das ist der doch nicht ganz gesamte Code(Der gesamte ist 850 Zeilen lang!) Wahrscheinlich hätte man einiges Verbessern können so weit bin ich nocht net!

alcaeus 27. Aug 2003 18:52

Re: Punkt vor Strich?
 
Hier einige Ansätze:
1. suche ein Punkt-Zeichen. Kopiere die Zahlen vom Zeichen davor bis zum Zeichen danach raus. Speicher aber Position und Länge des ursprünglichen Strings, es wird nützlich sein
2. Löse diese (einfache) Rechnung
3. Setze das Ergebnis anstatt des Ausdrucks wieder ein:
Delphi-Quellcode:
Delete(Rechnung, Start, Laenge);
Insert(Rechnung, Start,ZwErgebnis);
4. Wiederhole das ganze bis kein Punktzeichen mehr da ist
5. Rechne alle Strichrechnungen nach deinem Muster aus.

Das sollte helfen, wenn nicht, lass dir von Illu den code schreiben :wink:

Hansa 27. Aug 2003 18:54

Re: Punkt vor Strich?
 
Wie wäre es mit einer einfachen Klammerung :?:

Die Muhkuh 27. Aug 2003 18:54

Re: Punkt vor Strich?
 
Zitat:

Zitat von alcaeus
Hier einige Ansätze:
1. suche ein Punkt-Zeichen. Kopiere die Zahlen vom Zeichen davor bis zum Zeichen danach raus. Speicher aber Position und Länge des ursprünglichen Strings, es wird nützlich sein
2. Löse diese (einfache) Rechnung
3. Setze das Ergebnis anstatt des Ausdrucks wieder ein:
Delphi-Quellcode:
Delete(Rechnung, Start, Laenge);
Insert(Rechnung, Start,ZwErgebnis);
4. Wiederhole das ganze bis kein Punktzeichen mehr da ist
5. Rechne alle Strichrechnungen nach deinem Muster aus.

Das sollte helfen, wenn nicht, lass dir von Illu den code schreiben :wink:

Ich versteh nur Bahnhof!
Ich prgrammier erst seit nem Jahr mit viertel Jaht pause!

Die Muhkuh 27. Aug 2003 19:00

Re: Punkt vor Strich?
 
PS: Fallse jemand das Programm möchte dann kann er es sich unter www.mani007.de downloaden!

Hansa 27. Aug 2003 19:12

Re: Punkt vor Strich?
 
Mein Vorschlag ist doch etwas zu knapp: Ich meine den String um die Klammern zu erweitern und den dann auszuwerten. Das ganze läuft sowieso auf String-Manipulation hinaus. Das würde ich in Prozeduren aufteilen, dann sofern eine "(" kommt solange lesen bis ")" kommt. Den Ausdruck auswerten usw.


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:09 Uhr.
Seite 1 von 3  1 23      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz