Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

practica 7 ejercicio 7

program HelloWorld;
{-----------------------------------------------------------------------------------------------------------------------}
{-----------------------------------------------------------------
CONST - Define las constantes para usar en tiempo de compilacion}
const
    bits=64;
{-----------------------------------------------------------------------------------------------------------------------}




{-----------------------------------------------------------------------------------------------------------------------}
{-----------------------------------------------------------------
TYPE - Define los tipos creados por el usuario para usar en tiempo 
de compilacion}
type
    
    rangoBits = 1 .. bits;
    
    Tvector = array [rangoBits] of boolean;
{-----------------------------------------------------------------------------------------------------------------------}




{-----------------------------------------------------------------------------------------------------------------------}
{-----------------------------------------------------------------
VARIABLES GLOBALES - Define variables que se podran usar por todos los modulos
de ser necesarias}
//var
{-----------------------------------------------------------------------------------------------------------------------}





{-----------------------------------------------------------------------------------------------------------------------}
{-----------------------------------------------------------------
AND - Realiza la operacion And}
function operandoAnd(a,b:boolean):boolean;
begin
        if a then begin
            if b then begin
                operandoAnd := true;
            end else
                operandoAnd := false;
        end else operandoAnd:= false;
end;
{-----------------------------------------------------------------
OR - Realiza la operacion OR}
function operandoOr(a,b:boolean):boolean;
begin
    if a then begin
        operandoOr:=true;
     end else
         if b then begin
             operandoOr:=true;
         end else
             operandoOr:= false;
end;
{-----------------------------------------------------------------
NOT - Realiza la operacion NOT}
function operandoNot(a:boolean):boolean;
begin
    if a then begin
        operandoNot:= false;
    end else 
        operandoNot:=true;

end;
{-----------------------------------------------------------------
RANDOM - Elige valor al azar para una variable booleana }
function rand():boolean;
var
    n:integer;
begin
     n := random(50);
     if n mod 2 = 0 then begin            // si es par el valor el random  es verdadero
         rand := true;
     end else                             // si es impar el valor serĂ¡ falso
         rand:=false;
     
end;
{-----------------------------------------------------------------
MOSTRAR VECTOR - Show the results}
procedure mostrarVector(v:Tvector);
var
    i:rangoBits;
begin
    for i:=1 to bits do
        write('--');
    writeln;
    for i:=1 to bits do
        if v[i] then begin
            write('|1');
         end else
             write('|0');
    writeln('|');
    for i:=1 to bits do
        write('--');
end;
{-----------------------------------------------------------------------------------------------------------------------}







{-----------------------------------------------------------------------------------------------------------------------}
{-----------------------------------------------------------------
PROGRAMA PRINCIPAL - Dirige el programa ... }
var
        i:integer;
        v:Tvector;
        a,b:boolean;
begin
    //----------inicializacion-------//
    i:=1;
    a:= true;
    b:= false;
    randomize;
    //----------cargaVector-------//
    while i <= bits do begin
            v[i]:= operandoAnd(a,b);
            i:= i+1;
            if i <= bits then begin
                v[i]:= operandoOr(a,b);
                i:= i+1;
                if i <= bits then 
                    v[i]:=operandoNot(a);
            end;
        //----------refreshOperandos-------//
        a:=rand();
        write('a: ',a,' ');
        b:=rand();
        writeln('b: ',b);
    end; 
    //----------ReportVector-------//
    mostrarVector(v);
end.
{-----------------------------------------------------------------------------------------------------------------------}
 run  | edit  | history  | help 0