Advertisement
Guest User

HUY GOVNO PIZDA BLYAT

a guest
Oct 8th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.46 KB | None | 0 0
  1. program LAB2;
  2. uses
  3.     crt;
  4. const
  5.     allowedParams = ['h', 'i', 'g', 'c', 'e', 'f', 'm', 'n', 'e', 'r'];
  6.     numberOfParam = 10;
  7.     bumberOfFunction = 6;
  8. var
  9.     LCM :real;
  10.     menuSelector, BUFFER1, BUFFER2 :Integer;
  11.     inputParams : array[0..numberOfParam] of Integer;
  12.     functionSwitch :integer;
  13.     inFile, outFile :text;
  14.     inputFromConsole, inputFromFile, informationAboutProgram :Boolean;
  15.     j, i :integer;
  16.     currentParam :string;
  17.     enteredParams :set of char;
  18.     pathToFile :string;
  19.  
  20. function fileExists(fname: String): boolean;                                  
  21. var                                                                          
  22.    f: file of byte;
  23.                                                                    
  24. begin                                                                        
  25.    Assign(f,fname);                                                          
  26.    {$I-}                                                                      
  27.    Reset(f);                                                                  
  28.    {$I+}                                                                      
  29.       if (IOResult = 0) then
  30.       begin
  31.          close(f);
  32.          fileExists:=true;
  33.       end
  34.       else
  35.          fileExists:=false;                                                  
  36. end;
  37. {MENU SELECTOR}
  38.  
  39. {PROGRAMS}
  40. {1ST ONE}
  41. procedure GCDandLCM;
  42. begin
  43.     if informationAboutProgram = true then
  44.     begin
  45.         writeln('Find a greatest common divisor and least common multiple');
  46.     end;
  47.     if inputFromConsole = true then
  48.     begin
  49.         for i := 0 to 1 do
  50.         begin
  51.             readln(inputParams[i]);
  52.         end;
  53.     end;       
  54.     if (inputParams[0] = 0) or (inputParams[1] = 0) then
  55.     begin
  56.         writeln('ERROR DIVISION BY ZERO');
  57.     end
  58.     else
  59.     begin
  60.         BUFFER1 := inputParams[0];
  61.         BUFFER2 := inputParams[1];
  62.         while (inputParams[0] <> 0) and (inputParams[1] <> 0) do
  63.         begin
  64.  
  65.             if (inputParams[0] > inputParams[1]) then
  66.             begin
  67.                 inputParams[0] := inputParams[0] mod inputParams[1];
  68.             end
  69.             else
  70.             begin
  71.                 inputParams[1] := inputParams[1] mod inputParams[0];
  72.             end;
  73.         end;
  74.         LCM := (BUFFER1 * BUFFER2)/(inputParams[0] + inputParams[1]);
  75.         writeln('greatest common divisor: ', inputParams[0] + inputParams[1]);
  76.         writeln('least common multiple: ', LCM:1:5);
  77.     end;
  78. end;
  79. begin
  80.     enteredParams:= [];
  81.     j:=0;
  82.     for i:= 1 to paramCount do
  83.     begin
  84.         currentParam:= paramStr(i);
  85.         if (currentParam[1] = '-') and (currentParam[2] in allowedParams) then
  86.         begin
  87.             include(enteredParams, currentParam[2]);
  88.         end;
  89.         if ((currentParam[1] >= 'a') and (currentParam[1] <= 'z')) or ((currentParam[1] >= 'A') and (currentParam[1] <= 'Z')) then
  90.         begin
  91.             inputFromFile := true;
  92.             pathToFile := currentParam;
  93.             {inFile := currentParam;}
  94.         end;
  95.         if ((currentParam[1] >= '0') and (currentParam[1] <= '9')) then
  96.         begin
  97.             readln(inputParams[j]);
  98.             j:=j+1;
  99.             {inFile := currentParam;}
  100.         end;
  101.     end;
  102.     writeln(paramCount);
  103.  
  104.     if 'h' in enteredParams then
  105.     begin
  106.         informationAboutProgram := true;
  107.     end;
  108.     if 'c' in enteredParams then
  109.     begin
  110.         clrscr;
  111.     end;
  112.     if 'i' in enteredParams then
  113.     begin
  114.         writeln('Dmitry Volobuev');
  115.     end;
  116.     if 'g' in enteredParams then
  117.     begin
  118.         writeln('3INT-1DB-034');
  119.     end;
  120.     if 'n' in enteredParams then
  121.     begin
  122.         readln(functionSwitch);
  123.         if (functionSwitch <= 0) or (functionSwitch >= numberOfParam) then
  124.         begin
  125.             writeln('ERROR ENTERED PROGRAM DOES NOT EXIST');
  126.             halt;
  127.         end;
  128.     end;
  129.     if 'e' in enteredParams then
  130.     begin
  131.         inputFromConsole := true;
  132.     end;
  133.         if ('m' in enteredParams) and (inputFromConsole = true) then
  134.     begin
  135.         menuSelector := 1;
  136.         while menuSelector>0 do
  137.         begin
  138.             writeln('THIS IS PROGRAM SELECTOR');
  139.             writeln('SELECT WHAT YOU NEED BY ENTERING NUMBER');
  140.             writeln('FIRST PROGRAM: 1');
  141.             writeln('TO EXIT: 0');
  142.  
  143.             readln(menuSelector);
  144.  
  145.             if menuSelector = 1 then
  146.             begin
  147.              GCDandLCM;
  148.             end;
  149.         end;
  150.     end;
  151.     if ('f' in enteredParams) and (inputFromFile <> true) then
  152.     begin
  153.         readln(pathToFile);
  154.         inputFromFile := true  
  155.     end;
  156.  
  157.  
  158.     {READ FROM FILE}
  159.     if inputFromFile = true then
  160.     begin
  161.         assign(inFile, pathToFile);
  162.        
  163.         if not (fileExists(pathToFile)) then
  164.         begin
  165.             writeln('ERROR ', pathToFile, ' DOES NOT EXIST');
  166.             halt;
  167.         end;
  168.         if (fileExists(pathToFile)) then
  169.         begin
  170.             reset(inFile);
  171.             for j:=0 to numberOfParam do
  172.             begin
  173.                 readln(inFile, inputParams[j]);
  174.             end;
  175.             close(inFile);
  176.         end;
  177.         {writeln('');
  178.         writeln(pathToFile);}
  179.     end;
  180. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement