Materie: | Appunti |
Categoria: | Informatica |
Voto: | 1.5 (2) |
Download: | 51 |
Data: | 23.01.2002 |
Numero di pagine: | 3 |
Formato di file: | .doc (Microsoft Word) |
Download
Anteprima
numerazione-rpn_1.zip (Dimensione: 12.45 Kb)
readme.txt 59 Bytes
trucheck.it_la-numerazione-rpn.doc 38.5 Kb
Testo
RELAZIONE DI INFORMATICA
1.
Intestazione
Testo del programma:
“calcolare il risultato di un’espressione in forma RPN digitata dall’utente”
Data d’inizio:
16.11.2001
Data di fine:
23.11.2001
2.
Analisi del programma:
Obiettivi:
calcolare il risultato in forma RPN
Interfaccia:
3.
Principali proprietà dei componenti utilizzati nella progettazione dell’interfaccia utente:
Elenco eventi gestiti:
Edit2: Tedit = width(233) heigth (21)
Button1: Tbutton = width(249) heigth(33)
Label1: Tlabel = width(251) heigth(23)
Label2: Tlabel = width(212) heigth(23)
sg1: TstringGrid = width(481) heigth(49) editabile se selezionata la casella
4.
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);
5.
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
{ Private declarations }
public
{ Public declarations }
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
{$R *.DFM}
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.
6.
Piano di test (quali casi sono stati provati?)
1° dato
2° dato
1° operando
3°dato
2° operando
12
23
+
25
-
Il risultato è 10