Fórum Projeto Testador de logica! #213573

12/02/2004

0

Um usuario digita uma logica qualquer ´x and y´ dá os valores logicos iniciais para x e y
O programa deve retornar se o resultado é falso ou verdadeiro como fazer isso?


Transistorbr

Transistorbr

Responder

Posts

12/02/2004

Beppe

procedure TForm1.Button1Click(Sender: TObject);

  function NextString(var P: PChar): String;
  var
    S: PChar;
  begin
    while P^ in [1..32] do Inc(P);
    S := P;
    while not (P^ in [0..32]) do Inc(P);
    SetString(Result, S, P - S);
  end;

  function GetValue(const S: String): Integer;
  begin
    if SameText(S, ´x´) then
      Result := StrToInt(LabeledEdit1.Text)
    else if SameText(S, ´y´) then
      Result := StrToInt(LabeledEdit2.Text)
    else
      Result := StrToInt(S);
  end;

var
  P: PChar;
  A, B: Integer;
  Op: String;
begin
  P := PChar(Edit1.Text);
  A := GetValue(NextString(P));
  Op := NextString(P);
  B := GetValue(NextString(P));
  if SameText(Op, ´and´) then
    Label1.Caption := IntToStr(A and B)
  else if SameText(Op, ´or´) then
    Label1.Caption := IntToStr(A or B)
  else if SameText(Op, ´xor´) then
    Label1.Caption := IntToStr(A xor B)
end;


Eu fiz pra zeros e uns, mas fazer com verdadeiro e falso é fácil, vai!


Responder

Gostei + 0

14/02/2004

Transistorbr

:D
Beleza amigo vou testar!!!


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar