Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program project;
- Type ArrReal = array[1..150] of Real;
- const PRECISION = 0.001;
- function calcularTir(mo:Real;nd:Integer;var flujos : ArrReal):Real;
- var i,j:Integer;
- xo,fx,m,tir,aux:Real;
- begin
- xo := random();
- xo := xo*1000;
- //xo := xo-1000;
- fx := -mo;
- for i:=1 to nd do fx := fx + flujos[i]*exp(i*ln(xo));
- while fx>PRECISION do begin
- m:=0;
- for i:=1 to nd do begin
- aux := 1;
- for j:=1 to (i-1) do aux := aux*xo;
- m:= m + flujos[i]*i*aux;
- end;
- xo := xo - (fx/m);
- fx := -mo;
- for i:=1 to nd do begin
- aux := 1;
- for j:=1 to i do aux := aux*xo;
- fx := fx + flujos[i]*aux;
- end;
- end;
- calcularTir := (1/xo)-1;
- end;
- procedure emitirReporte(var archIn,archOut:Text);
- var tasa,mo,tir:Real;
- proy:String;
- nd:Integer;
- flujos:ArrReal;
- estado:String;
- begin
- readln(archIn,tasa);
- writeln('Tasa de corte: ',tasa:2:2,'%');
- writeln('PROYECTO TIR COMENTARIOS');
- randomize;
- while not eof(archIn) do begin
- readln(archIn,proy);
- readln(archIn,mo);
- nd := 0;
- while not eoln(archIn)do begin
- inc(nd);
- read(archIn,flujos[nd]);
- end;
- tir := calcularTir(mo,nd,flujos);
- tir := tir*100;
- if(tir>tasa) then begin
- estado := 'APROBADO';
- end
- else estado := 'RECHAZADO';
- writeln(proy:10,' ',tir:4:2,'% ',estado);
- readln(archIn);
- end;
- end;
- var archIn,archOut:Text;
- begin
- assign(archIn,'datos.txt');
- reset(archIn);
- assign(archOut,'reporte.txt');
- rewrite(archOut);
- emitirReporte(archIn,archOut);
- close(archIn);
- close(archOut);
- readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement