NBPrg40. CONCALC.PAS. MiniOS. OpenSource.

NBPrg40. CONCALC.PAS. MiniOS. OpenSource.
***************************************

{ Nikita Beloshenko (GNU) 2013 }

Unit ConCalc;

(*
   CONCALC.PAS

   +---------------------------+ 
   |                           | 
   |      C O N C A L C        | 
   |                           | 
   +---------------------------+ *)

Interface

Procedure ConCalc_run;

Implementation



Const
  MaxMem = 100;



{ Memory }
Var
  CONCALC_Memory:Array[1..MaxMem] Of Real;



{ Console calculator }
Procedure ConCalc_run;
Label START,EXIT;
Var Ch  : Char;
    x,y : Real;

    { CONCALC_Memory }
    i   : Integer;
    S   : String;

{ Input x procedure }
Procedure Input_x_procedure;
Begin
  S := ' ';
  While ((S<>'1') And (S<>'2')) Do
  Begin
    WriteLn('x?');
    WriteLn('---- Yours input way? ----');
    WriteLn('Enter "1" to console input.');
    WriteLn('Enter "2" to memory input.');
    ReadLn(S);
  End;
  If S='1' Then Begin ReadLn(x); End;
  If S='2' Then
  Begin
    WriteLn('Num? [1..',MaxMem,']');
    ReadLn(i);
    x := CONCALC_Memory[i];
  End;
End;

{ Input y procedure }
Procedure Input_y_procedure;
Begin
  S := ' ';
  While ((S<>'1') And (S<>'2')) Do
  Begin
    WriteLn('y?');
    WriteLn('---- Yours input way? ----');
    WriteLn('Enter "1" to console input.');
    WriteLn('Enter "2" to memory input.');
    ReadLn(S);
  End;
  If S='1' Then Begin ReadLn(y); End;
  If S='2' Then
  Begin
    WriteLn('Num? [1..',MaxMem,']');
    ReadLn(i);
    y := CONCALC_Memory[i];
  End;
End;

{ Put x to memory }
Procedure Put_x_to_mem_procedure;
Begin
  S := ' ';
  While ((S<>'y') And (S<>'n')) Do
  Begin
    WriteLn('Put x to mem?');
    WriteLn('y/n? [Yes/No]');
    ReadLn(S);
  End;
  If S='y' Then
  Begin
    WriteLn('Num? [1..',MaxMem,']');
    ReadLn(i);
    CONCALC_Memory[i] := x;
  End;
End;

Begin

  { Init Memory }
  For i := 1 To MaxMem Do
  Begin
    CONCALC_Memory[i] := 0;
  End;

START :

  WriteLn(' +---------------------------+ ');
  WriteLn(' |                           | ');
  WriteLn(' |      C O N C A L C        | ');
  WriteLn(' |                           | ');
  WriteLn(' +---------------------------+ ');
  WriteLn('                               ');
  WriteLn(' Nikita Beloshenko (GNU) 2013 ');
  WriteLn(' ----- Console Calc 2013 {(math) (module)} ----- ');

  WriteLn('1). "+"');
  WriteLn('2). "-"');
  WriteLn('3). "*"');
  WriteLn('4). "/"');
  WriteLn('5). "SQRT"');
  WriteLn('6). "SIN"');
  WriteLn('7). "COS"');
  WriteLn('8). EXIT.');

  ReadLn(Ch);

  If (Ch='1') Then
  Begin
    WriteLn('Please input numbers.');
    WriteLn('x?');
    ReadLn(x);

    { Input y procedure }
    Input_y_procedure;

    x:=x+y;
    WriteLn('x+y = ');
    WriteLn(x);

    { Put x to memory }
    Put_x_to_mem_procedure;

  End;

  If (Ch='2') Then
  Begin
    WriteLn('Please input numbers.');
    WriteLn('x?');
    ReadLn(x);

    { Input y procedure }
    Input_y_procedure;

    x:=x-y;
    WriteLn('x-y = ');
    WriteLn(x);

    { Put x to memory }
    Put_x_to_mem_procedure;

  End;

  If (Ch='3') Then
  Begin
    WriteLn('Please input numbers.');
    WriteLn('x?');
    ReadLn(x);

    { Input y procedure }
    Input_y_procedure;

    x:=x*y;
    WriteLn('x*y = ');
    WriteLn(x);

    { Put x to memory }
    Put_x_to_mem_procedure;

  End;

  If (Ch='4') Then
  Begin
    WriteLn('Please input numbers.');
    WriteLn('x?');
    ReadLn(x);

    { Input y procedure }
    Input_y_procedure;

    x:=x/y;
    WriteLn('x/y = ');
    WriteLn(x);

    { Put x to memory }
    Put_x_to_mem_procedure;

  End;

  If (Ch='5') Then
  Begin
    WriteLn('Please input numbers.');

    { Input x procedure }
    Input_x_procedure;

    x:=sqrt(x);
    WriteLn('sqrt(x) = ');
    WriteLn(x);

    { Put x to memory }
    Put_x_to_mem_procedure;

  End;

  If (Ch='6') Then
  Begin
    WriteLn('Please input numbers.');

    { Input x procedure }
    Input_x_procedure;

    x:=sin(x);
    WriteLn('sin(x) = ');
    WriteLn(x);

    { Put x to memory }
    Put_x_to_mem_procedure;

  End;

  If (Ch='7') Then
  Begin
    WriteLn('Please input numbers.');

    { Input x procedure }
    Input_x_procedure;

    x:=cos(x);
    WriteLn('cos(x) = ');
    WriteLn(x);

    { Put x to memory }
    Put_x_to_mem_procedure;

  End;

  { Exit or Start? }
  If (Ch='8') Then
  Begin
    Goto EXIT;
  End Else
  Begin
    Goto START;
  End;

EXIT:


End;




End.