Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program LAB2;
- uses
- crt;
- const
- allowedParams = ['h', 'i', 'g', 'c', 'e', 'f', 'm', 'n', 'e', 'r'];
- numberOfParam = 10;
- bumberOfFunction = 6;
- var
- LCM :real;
- menuSelector, BUFFER1, BUFFER2 :Integer;
- inputParams : array[0..numberOfParam] of Integer;
- functionSwitch :integer;
- inFile, outFile :text;
- inputFromConsole, inputFromFile, informationAboutProgram :Boolean;
- j, i :integer;
- currentParam :string;
- enteredParams :set of char;
- pathToFile :string;
- function fileExists(fname: String): boolean;
- var
- f: file of byte;
- begin
- Assign(f,fname);
- {$I-}
- Reset(f);
- {$I+}
- if (IOResult = 0) then
- begin
- close(f);
- fileExists:=true;
- end
- else
- fileExists:=false;
- end;
- {MENU SELECTOR}
- {PROGRAMS}
- {1ST ONE}
- procedure GCDandLCM;
- begin
- if informationAboutProgram = true then
- begin
- writeln('Find a greatest common divisor and least common multiple');
- end;
- if inputFromConsole = true then
- begin
- for i := 0 to 1 do
- begin
- readln(inputParams[i]);
- end;
- end;
- if (inputParams[0] = 0) or (inputParams[1] = 0) then
- begin
- writeln('ERROR DIVISION BY ZERO');
- end
- else
- begin
- BUFFER1 := inputParams[0];
- BUFFER2 := inputParams[1];
- while (inputParams[0] <> 0) and (inputParams[1] <> 0) do
- begin
- if (inputParams[0] > inputParams[1]) then
- begin
- inputParams[0] := inputParams[0] mod inputParams[1];
- end
- else
- begin
- inputParams[1] := inputParams[1] mod inputParams[0];
- end;
- end;
- LCM := (BUFFER1 * BUFFER2)/(inputParams[0] + inputParams[1]);
- writeln('greatest common divisor: ', inputParams[0] + inputParams[1]);
- writeln('least common multiple: ', LCM:1:5);
- end;
- end;
- begin
- enteredParams:= [];
- j:=0;
- for i:= 1 to paramCount do
- begin
- currentParam:= paramStr(i);
- if (currentParam[1] = '-') and (currentParam[2] in allowedParams) then
- begin
- include(enteredParams, currentParam[2]);
- end;
- if ((currentParam[1] >= 'a') and (currentParam[1] <= 'z')) or ((currentParam[1] >= 'A') and (currentParam[1] <= 'Z')) then
- begin
- inputFromFile := true;
- pathToFile := currentParam;
- {inFile := currentParam;}
- end;
- if ((currentParam[1] >= '0') and (currentParam[1] <= '9')) then
- begin
- readln(inputParams[j]);
- j:=j+1;
- {inFile := currentParam;}
- end;
- end;
- writeln(paramCount);
- if 'h' in enteredParams then
- begin
- informationAboutProgram := true;
- end;
- if 'c' in enteredParams then
- begin
- clrscr;
- end;
- if 'i' in enteredParams then
- begin
- writeln('Dmitry Volobuev');
- end;
- if 'g' in enteredParams then
- begin
- writeln('3INT-1DB-034');
- end;
- if 'n' in enteredParams then
- begin
- readln(functionSwitch);
- if (functionSwitch <= 0) or (functionSwitch >= numberOfParam) then
- begin
- writeln('ERROR ENTERED PROGRAM DOES NOT EXIST');
- halt;
- end;
- end;
- if 'e' in enteredParams then
- begin
- inputFromConsole := true;
- end;
- if ('m' in enteredParams) and (inputFromConsole = true) then
- begin
- menuSelector := 1;
- while menuSelector>0 do
- begin
- writeln('THIS IS PROGRAM SELECTOR');
- writeln('SELECT WHAT YOU NEED BY ENTERING NUMBER');
- writeln('FIRST PROGRAM: 1');
- writeln('TO EXIT: 0');
- readln(menuSelector);
- if menuSelector = 1 then
- begin
- GCDandLCM;
- end;
- end;
- end;
- if ('f' in enteredParams) and (inputFromFile <> true) then
- begin
- readln(pathToFile);
- inputFromFile := true
- end;
- {READ FROM FILE}
- if inputFromFile = true then
- begin
- assign(inFile, pathToFile);
- if not (fileExists(pathToFile)) then
- begin
- writeln('ERROR ', pathToFile, ' DOES NOT EXIST');
- halt;
- end;
- if (fileExists(pathToFile)) then
- begin
- reset(inFile);
- for j:=0 to numberOfParam do
- begin
- readln(inFile, inputParams[j]);
- end;
- close(inFile);
- end;
- {writeln('');
- writeln(pathToFile);}
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement