Jump to content
youjnhuhn2

Ajutor Delphi7

Recommended Posts

Posted (edited)

Am un proiect de facut in Delphi7 care imi cere urmatorul lucru:

sa afisez elementul maxim/minim al unui vector ce-l citesc dintr-un fisier .txt

problema e ca nu stiu cum sa urc vectorul din fisier intr-o variabila si sa-l parcurg sa gasesc maxim si minim.

vectorul e de genul:

[VECTOR]

1

10

1.2

-22

31

99.1

4.12

-6.72

-6.44

4.13

http://postimg.org/image/cmmqgstkl/

Edited by youjnhuhn2
Posted

pana acum am facut asta si aici sunt mort n-am niciun dumnezeu

	

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
Fisier1: TMenuItem;
Deschidere1: TMenuItem;
Parasireaplicatie1: TMenuItem;
Vizualizare1: TMenuItem;
Vizualizarevector1: TMenuItem;
Calcul1: TMenuItem;
Calculeaza1: TMenuItem;

procedure Deschidere1Click(Sender: TObject);
procedure Parasireaplicatie1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Deschidere1Click(Sender: TObject);
var
openDialog : TOpenDialog;
begin

openDialog := TOpenDialog.Create(self);

openDialog.InitialDir := GetCurrentDir;

openDialog.Options := [ofFileMustExist];

openDialog.Filter :=
'Text Files|*.txt|' ;

openDialog.FilterIndex := 2;

if openDialog.Execute
then ShowMessage('File : '+openDialog.FileName)
else ShowMessage('Deschiderea fisierului e fost anulata');


openDialog.Free;
end;



procedure TForm1.Parasireaplicatie1Click(Sender: TObject);

var
buttonSelected : Integer;
begin

buttonSelected := MessageDlg('Sigur doriti sa parasiti aplicatia?',mtCustom,
[mbYes,mbNo], 0);


if buttonSelected = mrYes then Application.Terminate;


end;

end.

Posted

in pascal:


assign(f,'numere.txt');reset(f);
readln(f); //treci peste stringul '[vector]'
readln(f,max); //min=max=
min:=max; // = primul nr din fisier
a[1]:=min; //il pui in vector[1]
i:=2; //restul valorilor le vei pune in vector incepand cu poz. 2
while (not eof(f)) do begin
readln(f,n);
if max<n then max:=n
else if min>n then min:=n;
a[i]:=n;
inc(i);
end;
writeln(min,' ',max);
end.

Posted

The good old delphi... :)

Link proiect: http://rapidshare.com/share/A6C3EA1ED588D085902E300DF8AA1ADA


unit fVectorUnit;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Menus;

type
TfVector = class(TForm)
mm: TMainMenu;
Fiseire1: TMenuItem;
Deschidere1: TMenuItem;
ParasireAplicatie1: TMenuItem;
Vizualizare1: TMenuItem;
Calcul1: TMenuItem;
Calculeaza1: TMenuItem;
Vizualizarevector1: TMenuItem;
reVector: TRichEdit;
OD: TOpenDialog;
procedure Deschidere1Click(Sender: TObject);
procedure ParasireAplicatie1Click(Sender: TObject);
procedure Vizualizarevector1Click(Sender: TObject);
procedure Calculeaza1Click(Sender: TObject);
private
{ Private declarations }
public
Vector: array of real;
{ Public declarations }
end;

var
fVector: TfVector;

implementation
uses fMinMaxUnit;
{$R *.dfm}

procedure TfVector.Deschidere1Click(Sender: TObject);
var
List: TStringList;
I: Integer;
begin
OD.InitialDir := ExtractFilePath(Application.ExeName);
if OD.Execute then
begin
List := TStringList.Create;
try
List.LoadFromFile(OD.FileName);
SetLength(Vector, List.Count);
for I := 0 to High(Vector) do
begin
try
Vector[I] := StrToFloat(List.Strings[I])
except
MessageDlg('Date invalide!', mtError, [mbOk], 0);
Vector := nil;
Break;
end;
end;
finally
List.Free;
end;
end;
end;

procedure TfVector.ParasireAplicatie1Click(Sender: TObject);
begin
if MessageDlg('Sigur doriti sa parasiti aplicatia?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
Application.Terminate;
end;

procedure TfVector.Vizualizarevector1Click(Sender: TObject);
var
I: Integer;
begin
if Length(Vector) = 0 then
begin
MessageDlg('Baza de date nu a fost incarcata!', mtInformation, [mbOk], 0);
Exit;
end;
for I := 0 to High(Vector) do
reVector.Lines.Add('v[' + IntToStr(I) + ']='+ FloatToStrF(Vector[I], ffFixed, 3, 3))
end;

procedure TfVector.Calculeaza1Click(Sender: TObject);
begin
if Length(Vector) = 0 then
begin
MessageDlg('Baza de date nu a fost incarcata!', mtInformation, [mbOk], 0);
Exit;
end;
fMinMax.ShowModal;
end;

end.


unit fMinMaxUnit;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TfMinMax = class(TForm)
rbMin: TRadioButton;
rbMax: TRadioButton;
bCalc: TButton;
bClose: TButton;
procedure bCloseClick(Sender: TObject);
procedure bCalcClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
fMinMax: TfMinMax;

implementation
uses fVectorUnit;
{$R *.dfm}

function MaxVector: real;
var
I: Integer;
M: real;
begin
M := fVector.Vector[Low(fVector.Vector)];
for I := 1 to High(fVector.Vector) do
if fVector.Vector[I] > M then
M := fVector.Vector[I];
Result := M;
end;

function MinVector: real;
var
I: Integer;
M: real;
begin
M := fVector.Vector[Low(fVector.Vector)];
for I := 1 to High(fVector.Vector) do
if fVector.Vector[I] < M then
M := fVector.Vector[I];
Result := M;
end;

procedure TfMinMax.bCalcClick(Sender: TObject);
var
MinMax: real;
I: Integer;
begin
if rbMin.Checked then
MessageDlg('Elementul minim: ' + FloatToStrF(MinVector, ffFixed, 3, 3), mtInformation, [mbOk], 0)
else
MessageDlg('Elementul maxim: ' + FloatToStrF(MaxVector, ffFixed, 3, 3), mtInformation, [mbOk], 0)
end;

procedure TfMinMax.bCloseClick(Sender: TObject);
begin
Close;
end;

end.

  • Downvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...