![]() | ![]() |
|
|
RELAZIONE DI INFORMATICA
Intestazione
Testo del programma:
"calcolare il risultato di un'espressione in forma RPN digitata dall'utente"
Data d'inizio:
Data di fine:
Analisi del programma:
Obiettivi:
calcolare il risultato in forma RPN
Interfaccia:
Principali proprietā dei componenti utilizzati nella progettazione dell'interfaccia utente:
Elenco eventi gestiti:
Elementi di progettazione
Elenco variabili:
catasta:array[1..max] of integer;
cima:0..max;
stringa:array[0..25] of string;
ris,oper1,oper2,x:integer;
Elenco procedure e relativi parametri formali:
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure vuota;
procedure pop(var dato:integer);
procedure calcola;
procedure push(dato:integer);
Listato del programma:
unit Unit1;
// programma Rpn, Olivi & Mosconi, 5ASt, 16/11/2001 //
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
const max=20;
type
TForm1 = class(TForm)
Edit2: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
sg1: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure vuota;
procedure pop(var dato:integer);
procedure calcola;
procedure push(dato:integer);
private
public
end;
var
Form1: TForm1;
catasta:array[1..max] of integer;
cima:0..max;
stringa:array[0..25] of string;
ris,oper1,oper2,x:integer;
implementation
procedure TForm1.Button1Click(Sender: TObject);
var cella:string;
celle:integer
begin
x:=0;
repeat
cella:=sg1.cells[x,0];
stringa[x]:=cella;
celle:=celle+1;
x:=x+1;
until cella='';
x:=0;
repeat
if (stringa[x]<>'+') and (stringa[x]<>'-')
and (stringa[x]<>'*') and (stringa[x]<>'/')
then push(strtoint(stringa[x]))
else
calcola;
x:=x+1;
until stringa[x]='';
end;
procedure tform1.vuota;
begin
cima:=0;
end;
procedure tform1.push(dato:integer);
begin
cima:=cima+1;
catasta[cima]:=dato;
end;
procedure tform1.pop(var dato:integer);
begin
dato:=catasta[cima];
cima:=cima-1;
end;
procedure tform1.calcola;
begin
pop(oper1);
pop(oper2);
begin
if stringa[x]='+' then ris:=oper1+oper2;
if stringa[x]='-' then ris:=oper2-oper1;
if stringa[x]='*' then ris:=oper1*oper2;
if stringa[x]='/' then ris:=oper2 div oper1;
push(ris);
end;
edit2.text:=inttostr(catasta[cima]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
vuota
end;
end.
Piano di test (quali casi sono stati provati?)
1° dato |
2° dato |
1° operando |
3°dato |
2° operando |
|
|
|
|
|
Il risultato č 10
Privacy |
Articolo informazione
Commentare questo articolo:Non sei registratoDevi essere registrato per commentare ISCRIVITI |
Copiare il codice nella pagina web del tuo sito. |
Copyright InfTub.com 2025