Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.49 KB | None | 0 0
  1. program Lab_2_2;
  2. {$APPTYPE CONSOLE}
  3. uses
  4.     SysUtils;
  5. Function Thousands(ThouOutput : String; ThouValue: Integer) : String;
  6. begin
  7.     Case ThouValue of
  8.         1 : ThouOutput := 'M';
  9.         2 : ThouOutput := 'MM';
  10.         3 : ThouOutput := 'MMM';
  11.     end;
  12.     Thousands := ThouOutput;
  13. end;
  14.  
  15.  
  16. Function Hundreads(HunOutput : String; HunValue: Integer) : String;
  17. begin
  18.     Case HunValue of
  19.         1 : HunOutput := 'C';
  20.         2 : HunOutput := 'CC';
  21.         3 : HunOutput := 'CCC';
  22.         4 : HunOutput := 'CD';
  23.         5 : HunOutput := 'D';
  24.         6 : HunOutput := 'DC';
  25.         7 : HunOutput := 'DCC';
  26.         8 : HunOutput := 'DCCC';
  27.         9 : HunOutput := 'CM';
  28.     end;
  29.     Hundreads := HunOutput;
  30. end;
  31.  
  32.  
  33. Function Tens(TenOutput : String; TenValue: Integer) : String;
  34. begin
  35.     Case TenValue of
  36.         1 : TenOutput := 'X';
  37.         2 : TenOutput := 'XX';
  38.         3 : TenOutput := 'XXX';
  39.         4 : TenOutput := 'XL';
  40.         5 : TenOutput := 'L';
  41.         6 : TenOutput := 'LX';
  42.         7 : TenOutput := 'LXX';
  43.         8 : TenOutput := 'LXXX';
  44.         9 : TenOutput := 'XC';
  45.     end;
  46.     Tens := TenOutput;
  47. end;
  48.  
  49.  
  50. Function Units(UnOutput: String; UnValue : Integer) : String;
  51. begin
  52.     Case UnValue of
  53.         1 : UnOutput := 'I';
  54.         2 : UnOutput := 'II';
  55.         3 : UnOutput := 'III';
  56.         4 : UnOutput := 'IV';
  57.         5 : UnOutput := 'V';
  58.         6 : UnOutput := 'VI';
  59.         7 : UnOutput := 'VII';
  60.         8 : UnOutput := 'VIII';
  61.         9 : UnOutput := 'IX';
  62.     end;
  63.     Units := UnOutput;
  64. end;
  65.  
  66.  
  67. Function CheckNumber(CheckInput : Integer; IsCorrect : Boolean) : Integer;
  68. begin
  69.     repeat
  70.     try
  71.         Readln(CheckInput);
  72.         IsCorrect := True;
  73.         if (CheckInput < 1) or (CheckInput > 3999) then
  74.         begin
  75.             IsCorrect := False;
  76.             Writeln('Enter the number, which is in range [1; 3999](type of integer):');
  77.         end;
  78.     except
  79.         Writeln('Enter the number, which is in range [1; 3999](type of integer):');
  80.     end;
  81.         until IsCorrect;
  82.         CheckNumber := CheckInput;
  83.     end;
  84.  
  85.  
  86. Procedure Main;
  87. var
  88.     Output, Fourth, Third, Second, First : String;
  89.     Value, Input : Integer;
  90.     IsCorrect : Boolean;
  91. begin
  92.     Writeln('Enter the number in range [1; 3999]:');
  93.     Input := CheckNumber(Input, IsCorrect);
  94.     Value := Input mod 10;
  95.     First := Units(Output, Value);
  96.     Input := Input div 10;
  97.     if Input <> 0 then
  98.     begin
  99.         Value := Input mod 10;
  100.         Second := Tens(Output, Value);
  101.     end;
  102.     Input := Input div 10;
  103.     if Input <> 0 then
  104.     begin
  105.         Value := Input mod 10;
  106.         Third := Hundreads(Output, Value);
  107.     end;
  108.     Input := Input div 10;
  109.     if Input <> 0 then
  110.     begin
  111.         Value := Input mod 10;
  112.         Fourth := Thousands(Output, Value);
  113.     end;
  114.     Writeln('This is your number in roman system of quantity :');
  115.     Writeln(Fourth + Third + Second + First);
  116. end;
  117.  
  118.  
  119. Procedure MainCycle;
  120. var
  121.     Again : String;
  122.     IsCorrect : Boolean;
  123.     begin
  124.         repeat
  125.         begin
  126.             Writeln('Do you want to transform the number again? If yes, write "Yes", if no, write something else :');
  127.             Readln(Again);
  128.             IsCorrect := True;
  129.             if (Again = 'Yes') or (Again = 'yes') or (Again = 'YES') then
  130.             begin
  131.                 IsCorrect := False;
  132.                 Main();
  133.             end;
  134.         end;
  135.         until IsCorrect;
  136.     end;
  137.  
  138.  
  139. begin
  140.     Main();
  141.     MainCycle();
  142. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement