Está en la página 1de 42

TALLER DE PROGRAMACION I

ARREGLOS PARALELOS

IMNTEGRANTES MIGUEL ACOSTA ROBERTO RUIZ DIEGO NORIEGA

TUTOR Ing. PIERRE PEA

INGENIERIA DE SISTEMAS UNIVERSIDAD DE CORDOBA SAHAGUN CORDOBA

2011

EJERCICIO No 1 unit vector; {$mode objfpc}{$H+} interface uses Classes, SysUtils; type { Tvector } Tvector=class private vec1 : array [1..5] of integer; vec2 : array [1..5] of integer; vec3 : array [1..10] of integer; pos1 : integer; pos2 : integer; public constructor create; procedure set_vector1(valor1:integer;posicion1:integer); function get_vector1(posicion1:integer):integer; procedure set_vector2(valor2:integer;posicion2:integer); function get_vector2(posicion2:integer):integer; procedure set_vector3(valor3:integer;posicion3:integer); function get_vector3(posicion3:integer):integer; procedure set_pos1(dato1:integer); function get_pos1():integer; procedure set_pos2(dato2:integer); function get_pos2():integer; end; implementation { Tvector } constructor Tvector.create; begin pos1:=0; pos2:=0; end; procedure Tvector.set_vector1(valor1: integer; posicion1: integer); begin vec1[posicion1]:=valor1; end;

function Tvector.get_vector1(posicion1: integer): integer; begin result:=vec1[posicion1]; end; procedure Tvector.set_vector2(valor2: integer; posicion2: integer); begin vec2[posicion2]:=valor2; end; function Tvector.get_vector2(posicion2: integer): integer; begin result:=vec2[posicion2]; end; procedure Tvector.set_vector3(valor3: integer; posicion3: integer); begin vec3[posicion3]:=valor3; end; function Tvector.get_vector3(posicion3: integer): integer; begin result:=vec3[posicion3]; end; procedure Tvector.set_pos1(dato1: integer); begin pos1:=dato1; end; function Tvector.get_pos1(): integer; begin result:=pos1; end; procedure Tvector.set_pos2(dato2: integer); begin pos2:=dato2; end; function Tvector.get_pos2(): integer; begin result:=pos2; end; end.

unit elementos; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, vector; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Button5: TButton; Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; ListBox1: TListBox; ListBox2: TListBox; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; obj:Tvector; implementation { TForm1 }

procedure TForm1.FormCreate(Sender: TObject); begin obj := Tvector.create ; end; procedure TForm1.Button1Click(Sender: TObject); begin if obj.get_pos1 ()<= 5 then begin obj.set_pos1 (obj.get_pos1 ()+1); obj.set_vector1 (strtoint(Edit1.Text),obj.get_pos1 ()); ShowMessage('Insertado correctamente el elemento'); Edit1.Clear; Edit1.SetFocus ; label1.Caption :='DIGITE EL ELEMENTO VEC 1:'+ inttostr(obj.get_pos1 ()); end else showMessage('elemento fuera de rango'); end;

procedure TForm1.Button2Click(Sender: TObject); var i:integer; begin listBox1.Clear ; for i:=1 to Obj.get_pos1() do begin ListBox1.Items .Add (inttostr(obj.get_vector1 (i))); end; end; procedure TForm1.Button3Click(Sender: TObject); var i:integer; begin for i:=1 to 10 do begin label2.Caption := label2.Caption + inttostr (obj.get_vector1 (i)) + ' '; end; end; procedure TForm1.Button4Click(Sender: TObject); begin

if obj.get_pos2 ()< 5 then begin obj.set_pos2 (obj.get_pos2 ()+1); obj.set_vector2 (strtoint(Edit2.Text),obj.get_pos2 ()); ShowMessage('Insertado correctamente el elemento'); edit2.Clear ; edit2.SetFocus ; label3.Caption :='DIGITE EL ELEMENTO VEC 2:'+ inttostr(obj.get_pos2 ()); end else showMessage('elemento fuera de rango'); end; procedure TForm1.Button5Click(Sender: TObject); var i:integer; begin listBox2.Clear ; for i:=1 to Obj.get_pos2() do begin ListBox2.Items .Add (inttostr(obj.get_vector2 (i))); end; end; initialization {$I elementos.lrs} end.

EJERCICIO No 2 unit formulario; {$mode objfpc}{$H+} interface uses Classes, SysUtils; const MAX = 100; type { vector } vector = class private vecn: array [1..MAX] of string; veca: array [1..MAX] of integer; vecb: array [1..MAX] of integer; vecc: array [1..MAX] of integer; vect: array [1..MAX] of integer; pos: integer; public constructor create; procedure set_vector1(valor:string; posicion: integer); function get_vector1(posicion: integer): string; procedure set_vector2(valor:integer; posicion: integer); function get_vector2(posicion:integer): integer; procedure set_vector3(valor: integer; posicion: integer); function get_vector3(posicion:integer): integer; procedure set_vector4(valor: integer; posicion: integer); function get_vector4(posicion:integer): integer; procedure set_vector5(valor: integer; posicion: integer); function get_vector5(posicion:integer): integer; procedure set_pos(dato:integer); function get_pos():integer; end; implementation { vector }

constructor vector.create; begin pos:=0; end; procedure vector.set_vector1(valor: string; posicion: integer); begin vecn[posicion]:= valor; end; function vector.get_vector1(posicion: integer): string; begin Result:= vecn[posicion]; end; procedure vector.set_vector2(valor: integer; posicion: integer); begin veca[posicion]:= valor; end; function vector.get_vector2(posicion: integer): integer; begin Result:= veca[posicion]; end; procedure vector.set_vector3(valor: integer; posicion: integer); begin vecb[posicion]:= valor; end; function vector.get_vector3(posicion: integer): integer; begin Result := vecb[posicion]; end; procedure vector.set_vector4(valor: integer; posicion: integer); begin vecc[posicion] := valor; end; function vector.get_vector4(posicion: integer): integer; begin Result := vecc[posicion] end; procedure vector.set_vector5(valor: integer; posicion: integer); begin

vect[posicion]:= valor; end; function vector.get_vector5(posicion: integer): integer; begin Result:= vect[posicion]; end; procedure vector.set_pos(dato: integer); begin pos := dato; end; function vector.get_pos(): integer; begin Result := pos; end; end. FORMULARIO unit formulario; {$mode objfpc}{$H+} interface uses Classes, SysUtils; const MAX = 100; type { vector } vector = class private vecn: array [1..MAX] of string; veca: array [1..MAX] of integer; vecb: array [1..MAX] of integer; vecc: array [1..MAX] of integer; vect: array [1..MAX] of integer; pos: integer; public constructor create; procedure set_vector1(valor:string; posicion: integer);

function get_vector1(posicion: integer): string; procedure set_vector2(valor:integer; posicion: integer); function get_vector2(posicion:integer): integer; procedure set_vector3(valor: integer; posicion: integer); function get_vector3(posicion:integer): integer; procedure set_vector4(valor: integer; posicion: integer); function get_vector4(posicion:integer): integer; procedure set_vector5(valor: integer; posicion: integer); function get_vector5(posicion:integer): integer; procedure set_pos(dato:integer); function get_pos():integer; end; implementation { vector } constructor vector.create; begin pos:=0; end; procedure vector.set_vector1(valor: string; posicion: integer); begin vecn[posicion]:= valor; end; function vector.get_vector1(posicion: integer): string; begin Result:= vecn[posicion]; end; procedure vector.set_vector2(valor: integer; posicion: integer); begin veca[posicion]:= valor; end; function vector.get_vector2(posicion: integer): integer; begin Result:= veca[posicion]; end; procedure vector.set_vector3(valor: integer; posicion: integer); begin vecb[posicion]:= valor; end;

function vector.get_vector3(posicion: integer): integer; begin Result := vecb[posicion]; end; procedure vector.set_vector4(valor: integer; posicion: integer); begin vecc[posicion] := valor; end; function vector.get_vector4(posicion: integer): integer; begin Result := vecc[posicion] end; procedure vector.set_vector5(valor: integer; posicion: integer); begin vect[posicion]:= valor; end; function vector.get_vector5(posicion: integer): integer; begin Result:= vect[posicion]; end; procedure vector.set_pos(dato: integer); begin pos := dato; end; function vector.get_pos(): integer; begin Result := pos; end; end.

EJERCICIO 3 unit suma; {$mode objfpc}{$H+} interface uses Classes, SysUtils; const MAX = 100; type { vector } vector = class private vecn: array [1..MAX] of integer; pos: integer; public constructor create; procedure set_vector1(valor:integer; posicion: integer); function get_vector1 (posicion: integer): integer; procedure set_pos (dato: integer); function get_pos (): integer; end; implementation { vector } constructor vector.create; begin pos:= 0; end; procedure vector.set_vector1(valor: integer; posicion: integer); begin vecn[posicion]:= valor; end;

function vector.get_vector1(posicion: integer): integer; begin Result:= vecn[posicion]; end; procedure vector.set_pos(dato: integer); begin pos := dato; end; function vector.get_pos(): integer; begin Result:= pos; end; end. FORMULARIO unit fsuma; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, LResources, suma, Forms, Controls, Graphics, Dialogs, StdCtrls; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; Label1: TLabel; Label2: TLabel; Label5: TLabel; Label6: TLabel; ListBox1: TListBox; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { private declarations } public

{ public declarations } end; var Form1: TForm1; obj: vector; implementation { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin obj:= vector.create; end; procedure TForm1.Button1Click(Sender: TObject); begin if obj.get_pos()<= 100 then begin obj.set_pos(obj.get_pos()+1); obj.set_vector1(strtoint(Edit1.Text), obj.get_pos()); ShowMessage ('Elemento Insertado'); Edit1.Clear; Edit1.SetFocus; end; end; procedure TForm1.Button2Click(Sender: TObject); var i, suma, Simpar : integer; begin suma:= 0; Simpar:= 0; ListBox1.Clear ; for i:= 1 to obj.get_pos () do begin ListBox1.Items.Add (inttostr(obj.get_vector1 (i))); end; for i:=1 to max do begin if (obj.get_vector1(i) mod 2)=0 then suma:=suma+obj.get_vector1 (i); end; label5.Caption := label5.Caption + inttostr(suma) + ' ';

for i:=1 to max do begin if ((obj.get_vector1 (i)) mod 2)=1 then Simpar:=Simpar+obj.get_vector1 (i); end; label6.Caption := label6.Caption + inttostr(Simpar) + ' '; end;

initialization {$I fsuma.lrs} end.

EJERCICIO 5 unit uprecios; {$mode objfpc}{$H+} interface uses Classes, SysUtils; const MAX = 100; type { vector } vector = class private vecdes: array [1..MAX] of string; vecpu: array [1..MAX] of integer; vecc: array [1..MAX] of integer; vectg: array [1..MAX] of integer; pos: integer; public constructor create; procedure set_vector1 (valor:string; posicion: integer); function get_vector1 (posicion: integer): string; procedure set_vector2 (valor: integer; posicion: integer); function get_vector2 (posicion: integer): integer; procedure set_vector3 (valor: integer; posicion: integer); function get_vector3 (posicion: integer): integer; procedure set_vector4 (valor: integer; posicion: integer); function get_vector4 (posicion: integer): integer; procedure set_pos(dato:integer); function get_pos():integer; end;

implementation { vector }

constructor vector.create; begin pos:= 0; end; procedure vector.set_vector1(valor: string; posicion: integer); begin vecdes[posicion]:= valor; end; function vector.get_vector1(posicion: integer): string; begin Result:= vecdes[posicion]; end; procedure vector.set_vector2(valor: integer; posicion: integer); begin vecpu[posicion]:= valor; end; function vector.get_vector2(posicion: integer): integer; begin Result:= vecpu[posicion]; end; procedure vector.set_vector3(valor: integer; posicion: integer); begin vecc[posicion]:= valor; end; function vector.get_vector3(posicion: integer): integer; begin Result:= vecc[posicion]; end; procedure vector.set_vector4(valor: integer; posicion: integer); begin vectg[posicion]:= valor; end; function vector.get_vector4(posicion: integer): integer; begin Result:= vectg[posicion]; end; procedure vector.set_pos(dato: integer); begin

pos:= dato; end; function vector.get_pos(): integer; begin Result:= pos; end; end. FORMULARIO unit fprecio; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, uprecios, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; ListBox1: TListBox; ListBox2: TListBox; ListBox3: TListBox; ListBox4: TListBox; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject);

procedure Button3Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; obj: vector; implementation { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin obj:= vector.create; end; procedure TForm1.Button1Click(Sender: TObject); begin if obj.get_pos() <= 100 then begin obj.set_pos (obj.get_pos()+1); obj.set_vector1(Edit1.Text, obj.get_pos()); obj.set_vector2(strtoint(edit2.Text), obj.get_pos()); obj.set_vector3(strtoint(edit3.Text), obj.get_pos()); //obj.set_vector4 (strtoint(edit4.Text), obj.get_pos ()); ShowMessage ('Elemento insertado'); edit1.Clear; edit2.Clear; edit3.Clear; edit1.SetFocus; end; end; procedure TForm1.Button2Click(Sender: TObject); var i: integer; begin ListBox1.Clear; ListBox2.Clear; ListBox3.Clear; //ListBox4.Clear; for i:= 1 to obj.get_pos() do

begin ListBox1.Items.Add (obj.get_vector1(i)); ListBox2.Items.Add (inttostr(obj.get_vector2(i))); ListBox3.Items.Add (inttostr(obj.get_vector3(i))); ListBox4.Items.Add (inttostr(obj.get_vector4(i)+(obj.get_vector2(i))*(obj.get_vector3(i)))); end; end; procedure TForm1.Button3Click(Sender: TObject); var i, suma: integer; begin suma:= 0; for i:= 1 to obj.get_pos() do begin suma:= suma + (obj.get_vector4(i)); label8.Caption:= label8.Caption + (inttostr(suma)); end; end;

initialization {$I fprecio.lrs} end.

EJERCICIO 6 unit vivienda; {$mode objfpc}{$H+} interface uses Classes, SysUtils; const max = 100; type { vector } vector = class private vecv: array [1..max] of string; vecar: array [1..max] of integer; vecpor: array [1..max] of integer; vecgan: array [1..max] of integer; vectg: array [1..max] of integer; pos: integer; public constructor create; procedure set_vector1(valor:string; posicion: integer); function get_vector1(posicion: integer): string; procedure set_vector2(valor:integer; posicion: integer); function get_vector2(posicion:integer): integer; procedure set_vector3(valor: integer; posicion: integer); function get_vector3(posicion:integer): integer; procedure set_vector4(valor: integer; posicion: integer); function get_vector4(posicion:integer): integer; procedure set_vector5(valor: integer; posicion: integer); function get_vector5(posicion:integer): integer; procedure set_pos(dato:integer); function get_pos():integer; end;

implementation

{ vector } constructor vector.create; begin pos:= 0 end; procedure vector.set_vector1(valor: string; posicion: integer); begin vecv[posicion]:= valor; end; function vector.get_vector1(posicion: integer): string; begin Result:= vecv[posicion]; end; procedure vector.set_vector2(valor: integer; posicion: integer); begin vecar[posicion]:= valor; end; function vector.get_vector2(posicion: integer): integer; begin Result:= vecar[posicion]; end; procedure vector.set_vector3(valor: integer; posicion: integer); begin vecpor[posicion]:= valor; end; function vector.get_vector3(posicion: integer): integer; begin Result:= vecpor[posicion]; end; procedure vector.set_vector4(valor: integer; posicion: integer); begin vecgan[posicion]:= valor; end; function vector.get_vector4(posicion: integer): integer; begin result:= vecgan[posicion]; end;

procedure vector.set_vector5(valor: integer; posicion: integer); begin vectg[posicion]:= valor; end; function vector.get_vector5(posicion: integer): integer; begin Result:= vectg[posicion]; end; procedure vector.set_pos(dato: integer); begin pos:= dato; end; function vector.get_pos(): integer; begin Result:= pos; end; end. FORMULARIO unit formulario; {$mode objfpc}{$H+} interface uses Classes, SysUtils, vivienda, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Label1: TLabel; Label2: TLabel;

Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; ListBox1: TListBox; ListBox2: TListBox; ListBox3: TListBox; ListBox4: TListBox; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; obj: vector; implementation { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin obj:= vector.create; end; procedure TForm1.Button1Click(Sender: TObject); begin if obj.get_pos() <= 100 then begin obj.set_pos (obj.get_pos()+1); obj.set_vector1(Edit1.Text, obj.get_pos()); obj.set_vector2(strtoint(edit2.Text), obj.get_pos()); obj.set_vector3(strtoint(edit3.Text), obj.get_pos()); //obj.set_vector4 (strtoint(edit4.Text), obj.get_pos ()); ShowMessage ('Elemento insertado'); edit1.Clear; edit2.Clear; edit3.Clear; edit1.SetFocus; end;

end; procedure TForm1.Button2Click(Sender: TObject); var i:integer; begin ListBox1.Clear ; ListBox2.Clear ; ListBox3.Clear ; ListBox4.Clear ; for i:= 1 to obj.get_pos () do begin ListBox1.Items.Add(obj.get_vector1 (i)); ListBox2.Items.Add (inttostr(obj.get_vector2 (i))); ListBox3.Items.Add (inttostr(obj.get_vector3(i))); ListBox4.Items.Add (inttostr(obj.get_vector4(i)+(obj.get_vector2(i))/100)); end; end;

initialization {$I formulario.lrs} end.

EJERCICIO 7 unit vector; {$mode objfpc}{$H+} interface uses Classes, SysUtils;

type { vector } { tvector } tvector = class private vecn: array [1..10] of integer; vecpar: array [1..10] of integer; vecimp: array [1..10] of integer; pos: integer; public constructor create; procedure set_vector1(valor:integer; posicion: integer); function get_vector1 (posicion: integer): integer; procedure set_vector2 (valor: integer; posicion: integer); function get_vector2 (posicion: integer): integer; procedure set_vector3 (valor: integer; posicion: integer); function get_vector3 (posicion: integer): integer; procedure set_pos (dato: integer); function get_pos (): integer; end; implementation { vector } constructor tvector.create; begin

pos:= 0 end; procedure tvector.set_vector1(valor: integer; posicion: integer); begin vecn[posicion]:= valor; end; function tvector.get_vector1(posicion: integer): integer; begin Result:= vecn[posicion]; end; procedure tvector.set_vector2(valor: integer; posicion: integer); begin vecpar[posicion]:= valor; end; function tvector.get_vector2(posicion: integer): integer; begin Result:= vecpar[posicion]; end; procedure tvector.set_vector3(valor: integer; posicion: integer); begin vecimp[posicion]:= valor; end; function tvector.get_vector3(posicion: integer): integer; begin Result:= vecimp[posicion]; end; procedure tvector.set_pos(dato: integer); begin pos:= dato; end; function tvector.get_pos(): integer; begin Result:= pos; end;

end. FORMULARIO

unit ejercicio7; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, vector, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Edit1: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; ListBox1: TListBox; ListBox2: TListBox; ListBox3: TListBox; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; obj: tvector; implementation { TForm1 }

procedure TForm1.FormCreate(Sender: TObject); begin obj:= tvector.create; end; procedure TForm1.Button1Click(Sender: TObject); begin if obj.get_pos() <= 10 then begin obj.set_pos(obj.get_pos()+1); obj.set_vector1(strtoint(edit1.Text), obj.get_pos()); ShowMessage('Elemento Insertado'); Edit1.Clear; Edit1.SetFocus; end; end; procedure TForm1.Button2Click(Sender: TObject); var i: integer; begin ListBox1.Clear; for i:= 1 to obj.get_pos() do begin ListBox1.Items.Add (inttostr(obj.get_vector1(i))); end; end; procedure TForm1.Button3Click(Sender: TObject); var i: integer; begin for i:= 1 to obj.get_pos() do begin if (obj.get_vector1(i)mod 2) = 0 then ListBox2.Items.Add (inttostr(obj.get_vector1(i))); end; end; procedure TForm1.Button4Click(Sender: TObject); var i: integer; begin for i:= 1 to obj.get_pos() do begin

if (obj.get_vector1(i)mod 2) = 1 then ListBox3.Items.Add (inttostr(obj.get_vector1(i))); end; end; initialization {$I ejercicio7.lrs} end.

EJERCICIO 8 unit UVentana; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, UVector; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { private declarations } objVector:TVector; cont:integer; public { public declarations } end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin if cont <= max then

begin objVector.set_numero(cont, StrToInt(Edit1.Text)); cont:=cont+1; end else begin ShowMessage('vector lleno'); end; end; procedure TForm1.Button2Click(Sender: TObject); begin ShowMessage('El numero mas grande en el vector es: ' IntToStr(objVector.numero_mayor) +' El numero mas pequenio en el vector es: ' IntToStr(objVector.numero_menor) +' El numero mas grande se repite ' IntToStr(objVector.numero_veces_repetido(objVector.numero_mayor)) + veces.' +' El numero mas pequenio se repite ' IntToStr(objVector.numero_veces_repetido(objVector.numero_menor)) + veces.' ); end; procedure TForm1.FormCreate(Sender: TObject); begin objVector:=TVector.Create; cont:=1; end;

+ + + ' + '

end. EJERCICIO 9 unit vector; {$mode objfpc}{$H+} interface uses Classes, SysUtils; type { tvector }

tvector=class private vec:array[1..10] of integer; num:integer; public constructor create; procedure set_vector(valor:integer;numero:integer); function get_vector(numero:integer):integer; procedure set_num(dato:integer); function get_num:integer; end; implementation { tvector } constructor tvector.create; begin num:=1; end; procedure tvector.set_vector(valor: integer; numero: integer); begin vec[numero]:=valor; end; function tvector.get_vector(numero: integer): integer; begin result:= vec[numero]; end; procedure tvector.set_num(dato: integer); begin num:=dato; end; function tvector.get_num: integer; begin result:=num; end; end. FORMULARIO unit formulario;

{$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, vector, StdCtrls; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Edit1: TEdit; Label1: TLabel; Label2: TLabel; ListBox1: TListBox; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; Obj:tvector; implementation { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin Obj:=tvector.create; end; procedure TForm1.Button1Click(Sender: TObject); begin if Obj.get_num() <= 10 then begin

Obj.set_vector(strtoint(edit1.Text), Obj.get_num()); Obj.set_num(Obj.get_num()+1); label1.Caption:='Digite los numeros del vector'+inttostr(Obj.get_num()); ShowMessage('Numero introducido correctamente'); edit1.Clear; edit1.SetFocus; end else ShowMessage('Elemento fuera del rango'); end; procedure TForm1.Button2Click(Sender: TObject); var i:integer; begin ListBox1.Clear; for i:=1 to Obj.get_num() do begin ListBox1.Items.Add(inttostr(Obj.get_vector(i))); end; end; procedure TForm1.Button3Click(Sender: TObject); var i, temp, n:integer; begin temp:=0; for i:=1 to 10 do begin if (Obj.get_vector(i)=i) then temp:= i; end; Label2.caption:=Label2.caption +inttostr(temp)+''; end; initialization {$I formulario.lrs} end.

EJERCICIO 11 unit pares; {$mode objfpc}{$H+} interface uses Classes, SysUtils; type { vector } vector = class private vecn: array [1..100] of integer; vecpos: array [1..100] of integer; vecneg: array [1..100] of integer; veczero: array [1..100] of integer; pos: integer; public constructor create; procedure set_vector1(valor:integer; posicion: integer); function get_vector1 (posicion: integer): integer; procedure set_vector2 (valor: integer; posicion: integer); function get_vector2 (posicion: integer): integer; procedure set_vector3 (valor: integer; posicion: integer); function get_vector3 (posicion: integer): integer; procedure set_vector4 (valor: integer; posicion: integer); function get_vector4 (posicion: integer): integer; procedure set_pos (dato: integer); function get_pos (): integer; end; implementation

{ vector } constructor vector.create; begin pos:= 0; end; procedure vector.set_vector1(valor: integer; posicion: integer); begin vecn[posicion]:= valor; end; function vector.get_vector1(posicion: integer): integer; begin Result:= vecn[posicion]; end; procedure vector.set_vector2(valor: integer; posicion: integer); begin vecpos[posicion]:= valor; end; function vector.get_vector2(posicion: integer): integer; begin Result:= vecpos[posicion]; end; procedure vector.set_vector3(valor: integer; posicion: integer); begin vecneg[posicion]:= valor; end; function vector.get_vector3(posicion: integer): integer; begin Result:= vecneg[posicion]; end; procedure vector.set_vector4(valor: integer; posicion: integer); begin veczero[posicion]:= valor; end; function vector.get_vector4(posicion: integer): integer; begin Result:= veczero[posicion]; end;

procedure vector.set_pos(dato: integer); begin pos:= dato; end; function vector.get_pos(): integer; begin Result:= pos; end; end. FORMULARIO unit formulario; {$mode objfpc}{$H+} interface uses Classes, SysUtils, pares, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; ListBox1: TListBox; ListBox2: TListBox; ListBox3: TListBox; ListBox4: TListBox; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { private declarations } public

{ public declarations } end; var Form1: TForm1; obj: vector; implementation { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin if obj.get_pos() <= 10 then begin obj.set_pos(obj.get_pos()+1); obj.set_vector1(strtoint(edit1.Text), obj.get_pos()); ShowMessage('Elemento Insertado'); Edit1.Clear; Edit1.SetFocus; end; end; procedure TForm1.Button2Click(Sender: TObject); var i: integer; begin ListBox1.Clear; for i:= 1 to obj.get_pos() do begin ListBox1.Items.Add (inttostr(obj.get_vector1(i))); end; for i:= 1 to obj.get_pos() do begin if (obj.get_vector1(i)) > 0 then ListBox2.Items.Add (inttostr(obj.get_vector1(i))); end; for i:= 1 to obj.get_pos() do begin if (obj.get_vector1(i)) < 0 then ListBox3.Items.Add (inttostr(obj.get_vector1(i))); end; for i:= 1 to obj.get_pos() do begin

if (obj.get_vector1(i)) = 0 then ListBox4.Items.Add (inttostr(obj.get_vector1(i))); end; end;

procedure TForm1.FormCreate(Sender: TObject); begin obj:= vector.create; end; initialization {$I formulario.lrs} end. EJERCICIO 12 unit UVentana; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, UVector; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; Edit2: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { private declarations } objVector:TVector; cont:integer; public { public declarations } end;

var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin objVector:=TVector.Create; cont:=1; end; procedure TForm1.Button2Click(Sender: TObject); var cant, pos, i, j, numero:integer; vectoAux:array of integer; cadena:string; begin j:=0; cadena:=''; numero:=StrToInt(Edit2.Text); cant:=objVector.numero_veces_repetido(numero); if cant > 0 then begin setLength(vectoAux, cant); for i:=1 to max do begin if objVector.get_numero(i) = numero then begin vectoAux[j]:=i; j:=j+1; cadena:= cadena + IntToStr(i) + ','; end; end; ShowMessage(cadena); end else begin ShowMessage('el numero no esta en el vector.'); end; end; procedure TForm1.Button1Click(Sender: TObject);

begin if cont <= max then begin objVector.set_numero(cont, StrToInt(Edit1.Text)); cont:=cont+1; end else begin ShowMessage('vector lleno'); end; end; end.