Program determine possible of triangle. Inputs are in file.

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Category: Homework in Pascal

Author: Juraj Pupák
Program: Subor_tr.pas
File exe: Subor_tr.exe
need: Num_tria.txt

Program read from file Num_Tria.txt length of triangle. Determine possible of triangle and result write to file Num_1.txt.
{ SUBOR_TR.PAS                                                      }
{ Program vycita zo suboru Num_Tria.txt dlzky stran trojuholnikov.  }
{ Zisti ci sa daju zostrojit a vysledok zapise do suboru Num_1.txt. }
{                                                                   }
{ Author: Juraj Pupak                                               }
{ Date  : 27.10.2006                           http://www.trsek.com }
 
program Subor_Triangle;
uses crt;
 
Procedure ZapisSubor(subor : string; vytvor : Boolean; moj_text : string);
var
  Tsubor : Text;
begin
  Assign(Tsubor,subor);
  IF vytvor = True THEN
  begin
  Rewrite(Tsubor);
    end else
    begin
      Append(Tsubor);
      end;
  writeln(Tsubor,moj_text);
  close(Tsubor);
end;
 
Function DaSaZostrojit(Pole : array of integer) : Boolean;
var
  Is_Triangle : Boolean;
begin
  If Pole[1] + Pole[2] > Pole[3] THEN
     begin
       If Pole[3] + Pole[2] > Pole[1] THEN
          begin
            IF Pole[3] + Pole[1] > Pole[2] THEN
               begin
                 Is_Triangle := True;
               end else
               begin
                 Is_Triangle := False;
               end;
         end else
         begin
           Is_Triangle := False;
         end;
     end else
     begin
       Is_Triangle := False;
     end;
 
  DaSaZostrojit := Is_Triangle;
end;
 
var
  Tsubor : Text;
  dlzka_retazca : integer;
  index,number_1,Code : integer;
  Cstr_Num,number : string;
  Pole : array [0..3] of integer;
  Is_Triangle,Vytvor : Boolean;
 
begin
  clrscr;
  writeln('Program vycita zo suboru Num_Tria.txt dlzky stran trojuholnikov.');
  writeln('Zisti ci sa daju zostrojit a vysledok zapise do suboru Num_1.txt.');
 
  Assign(Tsubor,'Num_Tria.txt');
  Reset(Tsubor);
  Vytvor := True;
 
  while not Eof(Tsubor) Do
  begin
    Readln(Tsubor,Cstr_Num);
    dlzka_retazca := length(Cstr_Num);
    For index := 1 To dlzka_retazca Do
    begin
      number := copy(Cstr_Num,index,1);
      Val(number,number_1,Code);
      Pole[index] := number_1;
    end;
 
    Is_Triangle := DaSaZostrojit(Pole);
    IF Is_Triangle = True THEN
      begin
        ZapisSubor('Num_1.txt',Vytvor,Cstr_Num);
        Vytvor := False;
      end;
  end;
 
  writeln('hotovo');
  readln;
end.