Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Lab_2_2;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- Function Thousands(ThouOutput : String; ThouValue: Integer) : String;
- begin
- Case ThouValue of
- 1 : ThouOutput := 'M';
- 2 : ThouOutput := 'MM';
- 3 : ThouOutput := 'MMM';
- end;
- Thousands := ThouOutput;
- end;
- Function Hundreads(HunOutput : String; HunValue: Integer) : String;
- begin
- Case HunValue of
- 1 : HunOutput := 'C';
- 2 : HunOutput := 'CC';
- 3 : HunOutput := 'CCC';
- 4 : HunOutput := 'CD';
- 5 : HunOutput := 'D';
- 6 : HunOutput := 'DC';
- 7 : HunOutput := 'DCC';
- 8 : HunOutput := 'DCCC';
- 9 : HunOutput := 'CM';
- end;
- Hundreads := HunOutput;
- end;
- Function Tens(TenOutput : String; TenValue: Integer) : String;
- begin
- Case TenValue of
- 1 : TenOutput := 'X';
- 2 : TenOutput := 'XX';
- 3 : TenOutput := 'XXX';
- 4 : TenOutput := 'XL';
- 5 : TenOutput := 'L';
- 6 : TenOutput := 'LX';
- 7 : TenOutput := 'LXX';
- 8 : TenOutput := 'LXXX';
- 9 : TenOutput := 'XC';
- end;
- Tens := TenOutput;
- end;
- Function Units(UnOutput: String; UnValue : Integer) : String;
- begin
- Case UnValue of
- 1 : UnOutput := 'I';
- 2 : UnOutput := 'II';
- 3 : UnOutput := 'III';
- 4 : UnOutput := 'IV';
- 5 : UnOutput := 'V';
- 6 : UnOutput := 'VI';
- 7 : UnOutput := 'VII';
- 8 : UnOutput := 'VIII';
- 9 : UnOutput := 'IX';
- end;
- Units := UnOutput;
- end;
- Function CheckNumber(CheckInput : Integer; IsCorrect : Boolean) : Integer;
- begin
- repeat
- try
- Readln(CheckInput);
- IsCorrect := True;
- if (CheckInput < 1) or (CheckInput > 3999) then
- begin
- IsCorrect := False;
- Writeln('Enter the number, which is in range [1; 3999](type of integer):');
- end;
- except
- Writeln('Enter the number, which is in range [1; 3999](type of integer):');
- end;
- until IsCorrect;
- CheckNumber := CheckInput;
- end;
- Procedure Main;
- var
- Output, Fourth, Third, Second, First : String;
- Value, Input : Integer;
- IsCorrect : Boolean;
- begin
- Writeln('Enter the number in range [1; 3999]:');
- Input := CheckNumber(Input, IsCorrect);
- Value := Input mod 10;
- First := Units(Output, Value);
- Input := Input div 10;
- if Input <> 0 then
- begin
- Value := Input mod 10;
- Second := Tens(Output, Value);
- end;
- Input := Input div 10;
- if Input <> 0 then
- begin
- Value := Input mod 10;
- Third := Hundreads(Output, Value);
- end;
- Input := Input div 10;
- if Input <> 0 then
- begin
- Value := Input mod 10;
- Fourth := Thousands(Output, Value);
- end;
- Writeln('This is your number in roman system of quantity :');
- Writeln(Fourth + Third + Second + First);
- end;
- Procedure MainCycle;
- var
- Again : String;
- IsCorrect : Boolean;
- begin
- repeat
- begin
- Writeln('Do you want to transform the number again? If yes, write "Yes", if no, write something else :');
- Readln(Again);
- IsCorrect := True;
- if (Again = 'Yes') or (Again = 'yes') or (Again = 'YES') then
- begin
- IsCorrect := False;
- Main();
- end;
- end;
- until IsCorrect;
- end;
- begin
- Main();
- MainCycle();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement