Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Find power

Program calculatepower;
var x, y, z :integer;
begin
  z:= 1;
  writeln('Input the value of X: ');
  readln(X);
  writeln('Input the value of Y: ');
  readln(Y);
  Z:= 1;
  while Y > 0 do 
    begin
        z := Z * X;
        Y := Y - 1;
    end;
  writeln('The value of Z is ', Z);
end.

FluentError

program FluentError;

{$IFDEF FPC}
 {$mode DELPHI} 
{$ELSE}
 {$APPTYPE CONSOLE}
{$ENDIF}

uses
  SysUtils;

type
  Int32 = integer ; //D7

  IFluent = interface
  ['{704F44B3-DC6D-47F0-A12E-3B803FA4BB29}']
      function  GetCol( out ACol : integer ) : IFluent ;
      function  GetRow( out ARow : integer ) : IFluent ;
      function  ShowIntParams(
            const A, B, C, D  : Int32
      ) : IFluent ;
      function  ShowArraysIntParams(
          X, y, z : array of int32
      ) : IFluent ;
      function  NextCol : IFluent  ;
      function  NextRow : IFluent  ;
      function  DebugMsg(const Msg: String)   : IFluent ;
  end ;

  TFluent = class(TInterfacedObject, IFluent )
    private
      FRow,
      FCol : integer ;
      function  DebugMsg(const Msg: String)   : IFluent ;
      function  GetCol( out ACol : integer )  : IFluent ;
      function  GetRow( out ARow : integer )  : IFluent ;
      function  ShowIntParams(
            const A, B, C, D  : Int32
      ) : IFluent ;
      function  ShowArraysIntParams(
           X, y, z : array of int32
      ) : IFluent ;
      function  NextCol  : IFluent ;
      function  NextRow  : IFluent ;
    public
    constructor Create ;
  end;

function TFluent.DebugMsg(const Msg: String) : IFluent ;
begin
    Result := self ;
    WriteLn( msg )
end;

{ TFluent }

function TFluent.GetRow(out ARow: integer): IFluent;
begin
   Result := self ;
   ARow := FRow ;
  DebugMsg( 'getRow( out ' + IntToStr( ARow ) + ')' ) ;
end;

function TFluent.ShowIntParams(
      const A, B, C, D  : Int32
): IFluent;
begin
  DebugMsg(
     'Int Params( '
        + intToStr ( A ) + ', '
        + intToStr ( B ) + ', '
        + intToStr ( C ) + ', '
        + intToStr ( D ) + ')' ) ;

  Result := self ;
end;

function TFluent.ShowArraysIntParams(
          x, y, z : array of int32
      ) : IFluent ;
begin
    
  Result := self ;
  DebugMsg(
    Format (
     'Arrays of Int ('
        + ' X[ %d, %d, %d, %d ]' 
        + ' Y[ %d, %d, %d, %d ]' 
        + ' Z[ %d, %d, %d, %d ]'
        + ' )' 
      , [ 
            x[0], x[1], x[2], x[3] 
          , y[0], y[1], y[2], y[3] 
          , z[0], z[1], z[2], z[3] 
         ] 
    )
  ) ;    
end;


function TFluent.GetCol(out ACol: integer): IFluent;
begin
  Result := self ;
  ACol := FCol ;
  DebugMsg( 'getCol( out ' + IntToStr ( ACol ) + ')' ) ;
end;

function  TFluent.NextCol : IFluent ;
begin
  Result := self ;
  Inc ( FCol ) ;
  DebugMsg( 'NextCol : ' + IntToStr(FCol - 1) +  ' -> ' + IntToStr(FCol)  ) ;
end;

function  TFluent.NextRow : IFluent ;
begin
  Result := self ;
  Inc ( FRow ) ;
  DebugMsg( 'NextRow : ' + IntToStr(FRow - 1) +  ' -> ' + IntToStr(FRow)  ) ;
end;

constructor TFluent.Create;
begin
  FRow := 0 ;
  FCol := 0 ;
end;

var
  LRow1, LCol1, LRow2, LCol2 : integer ;
  LFluent: IFluent ;
begin
  LFluent := TFluent.Create ;

  LRow1 := -1 ;
  LCol1 := -1 ;
  LRow2 := -1 ;
  LCol2 := -1 ;

  LFluent
    .DebugMsg ( 'InitValues' )
    .NextRow
    .GetRow ( LRow1 )
    .NextRow
    .GetRow ( LRow2 )
    .NextCol
    .GetCol ( LCol1 )
    .NextCol
    .GetCol ( LCol2 )
    .DebugMsg ( 'Show values (wrong values in delphi compilers)' )
    .ShowIntParams( LRow1, LCol1, LRow2, LCol2 )
    .ShowIntParams( LRow2, LCol2, LRow1, LCol1 )
    .ShowIntParams( LRow1, LCol2, LRow2, LCol1 )
    .ShowIntParams( LRow1, LCol2, LRow1 + 10, LCol2 + 10 )
    .ShowArraysIntParams( {X} [LRow1, LCol1, LRow2, LCol2],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .ShowArraysIntParams( {X} [LRow2, LCol2, LRow1, LCol1],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .ShowArraysIntParams( {X} [LRow1, LCol2, LRow2, LCol1],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .DebugMsg ( 'Press [enter]' )
  ;

  ReadLn ;

  LFluent
    .DebugMsg ( 'Show values (correct values in delphi compilers)' )
    .ShowIntParams( LRow1, LCol1, LRow2, LCol2 )
    .ShowIntParams( LRow2, LCol2, LRow1, LCol1 )
    .ShowIntParams( LRow1, LCol2, LRow2, LCol1 )
    .ShowIntParams( LRow1, LCol2, LRow1 + 10, LCol2 + 10 )
    .ShowArraysIntParams( {X} [LRow1, LCol1, LRow2, LCol2],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .ShowArraysIntParams( {X} [LRow2, LCol2, LRow1, LCol1],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .ShowArraysIntParams( {X} [LRow1, LCol2, LRow2, LCol1],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .DebugMsg ( 'Press [enter]' )
  ;

  ReadLn ;
end.

ElectionResults

Program ElectionResults;
uses sysutils;

{ The function maximumVote returns the winner }
function maximumVote(vote : array of integer; counts : integer): integer;
var  
    i, j, max : integer;  //variable declaration
begin

    max := 0;     //initializes max to 0
    for i := 0 to counts-1 do   
    begin

        if (vote[i]>= max) then   //comparision to determine the winner  
        begin
        
            max := vote[i];
            j := i;
            
        end;
        
    end;
    
    maximumVote := j ; //returns last name of winner
    
end;

{ displays required outputs including the winner of election}
procedure getInput();


var // local variable declaration 
   str, winner: string;
   num, sum, count : integer;
   names : array[1..30] of string; 
   votes : array[1..30] of integer;
   percentageOfVotes : array[1..30] of real;

begin 

    writeln(format('%-18s%-18s%-18s', ['Candidate', 'Votes Received', '% of Total Votes']));  //header display
    readln(count);   //reads each line and stores in count 
    sum := 0;
    for num := 1 to count do   
    begin
       
        readln(names[num]);  //stores in the given num of name arrays after reading each line
        readln(votes[num]);  //stores in the given num of votes arrays after reading each line
        sum := sum + votes[num];   //calculating the sum of votes
        
    end;
    
    for num := 1 to count do
    begin
    
        percentageOfVotes[num] := (votes[num]/sum * 100 ); //stores votes percent in array after its calculation
        
        str := format('%-13s%13d%18.2f', [names[num], (votes[num]), (percentageOfVotes[num])]);   //formatting strings for output
        writeln(str);  
        
    end;
    
    winner := names[maximumVote(votes, count) + 1];
    writeln(format('%-13s%13d', ['Total', sum]));  //displaying the total sum of number of votes
    writeln('The winner of the election is ' + winner + '.');   //displaying the winner of election
    
end;

{ main program }
begin 

  getInput();
  
end.

Speed Tracker

program SpeedTracker;

uses sysutils;

var
  time1, time2: string;
  distance: integer;

function getDifference (stringPos, maxValue: integer; var carry: integer; t1, t2: string): integer;
var
  tempDiff: integer;
begin
  tempDiff := strtoint(copy(t2, stringPos, 2)) - strtoint(copy(t1, stringPos, 2)) - carry;
  carry := 0;
  if tempDiff < 0 then
    begin
      carry := (abs(tempDiff) div maxValue) + 1;
      tempDiff := maxValue + tempDiff;
    end;
  getDifference := tempDiff;
end;

function getAverageSpeed (t1, t2: string; dist: integer): integer;
var
  carry: integer;
  timeDifference: real;
begin
  carry := 0;
  timeDifference := getDifference(7, 60, carry, t1, t2) / 3600 + getDifference(4, 60, carry, t1, t2) / 60 + getDifference(1, 24, carry, t1, t2);
  getAverageSpeed := round(dist / timeDifference);
end;

begin
  write('Enter camera 1 time (HH:MM:SS): ');
  readln(time1);
  write('Enter camera 2 time (HH:MM:SS): ');
  readln(time2);
  write('Enter distance between cameras (miles): ');
  readln(distance);
  writeln('Average Speed: ', inttostr(getAverageSpeed(time1, time2, distance)));
  readln;
end.

ElectionResults

{*
Name: Aswin Timalsina
CWID: 30098693

Program Description: The program reads the file STDIN and displays the name, votes received and percent of the votes. The program also calculates the total number of votes and finds the winner of the election. The program make good use of subprograms procedure and function, local variables and arrays.
*}


Program ElectionResults;      {name of the program}

  Uses sysutils;              {imports sysutils library}
  
procedure headline();         {procedure that displays the headline}
begin
    writeln('Candidate        Votes Received        % of Total Votes');
end;

function readFile() : string ;{function that displays the table and calculates the winner}
type                          {arrays declared}
names = array of string;  
votes = array of integer;
    
var                           {variables declared}
name1 : names;
vote1 : votes;
number, i, l: integer;
highest : integer = 0;
vote_sum : integer = 0;
candidate : string = '';



begin
    readln(number);           {stores the number of voters to 'number'}
    setlength(name1, number); {length of the array set}
    setlength(vote1, number);
    
    for i:= 1 to number do    {loop to store in array and storing the sum of vote}
    begin
        readln(name1[i]);
        readln(vote1[i]);
        vote_sum := vote_sum + vote1[i];
        
        if(vote1[i] > highest) then  {finds the winner}
        begin
            highest := vote1[i];
            candidate := name1[i];
        end;
        
    end;
    
    for l:=1 to number do
    begin
            writeln(Format('%0:-20s %-21d %5.2f',[name1[l], vote1[l], ((vote1[l]/vote_sum)*100)])); {prints the table of name, votes and percentage}
    
    end;
    writeln('Total               ', vote_sum);  {prints the total votes}
    
  readFile := candidate + '.';
  
end;

begin
  
  headline();                                                         {headline procedure called}
  
  writeln(Format('The winner of the election is %s', [readFile()]));  {prints readFile function and prints the winner of the election}
  
end.                  {end of program}

Simple Life Calculator

program SimpleLifeCalculator;

var
  mode, quitString: string;

procedure VAT ();
var
  money: real;
begin
  write('Enter amount of money (pounds): ');
  readln(money);
  writeln('VAT: ', (money * 0.2):0:2, ' pounds');
  writeln('Gross amount: ', (money * 1.2):0:2, ' pounds');
end;

procedure tax ();
var
  income: integer;
  taxMultiplier: real;
begin
  write('Enter annual income (pounds): ');
  readln(income);
  if income <= 11850 then
    taxMultiplier := 0
  else if income <= 46350 then
    taxMultiplier := 0.2
  else if income <= 150000 then
    taxMultiplier := 0.4
  else
    taxMultiplier := 0.45;
  writeln('Tax: ', round(income * taxMultiplier));
  writeln('Final income: ', round(income * (1 - taxMultiplier)));
end;

procedure timesTable ();
var
  number, terms, termCount: integer;
begin
  write('Enter a number: ');
  readln(number);
  writeln('How many terms? ');
  readln(terms);
  for termCount := 1 to terms do
    writeln(number * termCount);
end;

begin
  repeat
    write('VAT (1), Tax (2) or Times Table (3): ');
    readln(mode);
    if mode = '1' then
      VAT()
    else if mode = '2' then
      tax()
    else if mode = '3' then
      timesTable();
    write('Would you like to quit? (Y/N): ');
    readln(quitString);
  until upcase(quitString) = 'Y';
end.

truth or not

program truthOrNot;

uses
  sysutils;

var
  gateInput : string;
  A, B, C : integer;

begin

  writeln('Input Gate');
  readln(gateInput);
  UpperCase(gateInput);

  writeln('|    A    |    B    |    C    |');
  writeln('-------------------------------');

  for A := 0 to 1 do
  begin
    for B:= 0 to 1 do
    begin
        if gateInput = 'AND' then
        begin
          if (A = 1) AND (B = 1) then
          begin
            C := 1;
          end
          else
          begin
            C := 0;
          end;
        end
        else if gateInput = 'OR' then
        begin
          if ((A = 1) AND (B = 1)) OR (A = 1) OR (B = 1) then
          begin
            C := 1;
          end
          else
          begin
            C := 0;
          end;
        end
        else if gateInput = 'NOT' then
        begin
          if ((A = 1) AND (B = 1)) OR (A = 1) OR (B = 1) then
          begin
            C := 1;
          end
          else
          begin
            C := 0;
          end;
        end;

      writeln('|    '+IntToStr(A)+'    '+'|    '+IntToStr(B)+'    '+'|    '+IntToStr(C)+'    |');
      writeln('-------------------------------');

    end;
  end;

readln();

end.

Unit

program project1;
uses sysutils;

var
  Choice, CtoF, PtoD, CtoM: integer;
  answer:real;

begin
  writeln('Choose a conversion:');
  writeln('For Celsius to Farenheit press [1]:');
  writeln('For Pounds to Dollars press [2]:');
  writeln('For Centimetres to Metres press [3]:');
  readln(Choice);

  if Choice = 1 then
   begin
  writeln('Enter a value:');
  readln(CtoF);
  answer:= (CtoF * 9/5)+ 32;
  writeln(FloatToStr(answer),' Degrees Farenheit');
  readln;
   end

  else if Choice = 2 then
   begin
   writeln('Enter a value:');
  readln(PtoD);
  answer:= (PtoD * 1.31);
  writeln('$', FloatToStr(answer));
  readln;
   end

  else if Choice = 3 then
   begin
   writeln('Enter a value:');
  readln(CtoM);
  answer:= (CtoM * 0.000001);
  writeln(FloatToStr(answer), ' Metres');
  readln;
   end;

end.
       

LogicGate

program LogicGates;

var
  Gate: string;
  FBit, SBit: integer;
  FBitBool, SBitBool: boolean;

begin
  FBit:= 2;
  SBit:= 2;
  while ((Gate<>'and') and (Gate<>'or') and (Gate<>'xor') and (Gate<>'nand')) do
        begin
        writeln('Enter logic gate: ');
        readln(Gate);
        Gate := lowercase(Gate);
        end;
  while ((FBit<0) or (FBit>1)) do
        begin
        writeln('Enter first input: ');
        readln(FBit);
        end;
  while ((SBit<0) or (SBit>1)) do
        begin
        writeln('Enter second input: ');
        readln(SBit);
        end;
  if (FBit=1) then
     FBitBool := true
  else
      FBitBool := false;
  if (SBit=1) then
     SBitBool := true
  else
      SBitBool := false;

  if (Gate='and') then
     begin
         if (FBitBool and SBitBool) then
            writeln('Result: 1')
         else
             writeln('Result: 0');
     end;
  if (Gate='or') then
     begin
         if (FBitBool or SBitBool) then
            writeln('Result: 1')
         else
             writeln('Result: 0');
     end;
  if (Gate='xor') then
     begin
          if (FBitBool xor SBitBool) then
            writeln('Result: 1')
          else
             writeln('Result: 0');
     end;
  if (Gate='nand') then
     begin
          if (FBitBool=false and SBitBool=false) then
            writeln('Result: 1')
          else
             writeln('Result: 0');
     end;
  readln();
end.
                                               

armadi

program armadi(input,output);

var N, K:longint; 
const nMax=100001;
var D: array [1..nMax] of longint;
var i,j, aux, max,n_m, DISTANZA, INDMAX: longint;
var DD: array [1..nMax] of longint;
var m: array [1..nMax] of longint;


begin
assign(input, 'input.txt'); reset(input);
assign(output, 'output.txt'); rewrite(output);



read (N); read( k);

 for i:=1 to n do  
    begin
         read(D[i]);
    end;

D[n+1]:=k;



for j := 1 to (N-1) do
  for i := (j+1) to n do
    if D[j] > D[i] then begin
      {scambio valori};
      aux := D[j];
      D[j] := D[i];
      D[i] := aux
    end;

DD[1]:=D[1]-D[0];
DD[N+1]:=K-D[N];
for i:=2 to N do
begin
 DD[i]:=round((D[i]-D[i-1])/2);
end;



max:=DD[1];
n_m:=1;
m[n_m]:=1;

FOR i:=2 TO n+1 DO BEGIN
IF DD[i] > max THEN BEGIN
max:=DD[i];
n_m:=0;
n_m:=n_m+1;
m[n_m]:=i
END ELSE
IF DD[i] = max THEN BEGIN
n_m:=n_m+1;
m[n_m]:=i
END
END;
FOR i:=1 TO n_m DO
BEGIN
INDMAX:=m[I];
END;

CASE INDMAX OF
    1: DISTANZA:=0;
    ELSE DISTANZA:=D[INDMAX-1]+DD[INDMAX];
    
END;


WRITELN(distanza);

end.

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.