- •Лекции 17-19: Модули и их использование.
- •1. Концепция модуля.
- •2. Структура описания модуля.
- •Interface
- •3. Разработка модулей.
- •4. Примеры модулей.
- •Interface
- •Implementation
- •Interface
- •Implementation
- •5. Использование модулей в программах.
- •6. Стандартный модуль сrt.
- •7. Стандартный модуль graph.
Interface
type array_s =array[1..5] of string;
procedure conv_int(int:string;var s_int:array_s);
Implementation
procedure conv_int(int:string;var s_int:array_s);
type string3 =string[3];
var k:byte;{длина числа} j:byte;{параметр}
trd:array[1..5] of string3;{массив строк-триад}
function s_trd(t:string3;numt:byte):string;{перевод в название триады}
const d:array[2..5] of string =('тысяч','миллион','миллиард','триллион');
dig:array['1'..'9'] of string= ('один','два','три','четыре','пять','шесть','семь','восемь','девять');
var c:char;{переводимая цифра} j:byte; m:array[2..5] of string;
str1,str2,str3:string;{строки-названия цифр триады}
begin for j:=2 to 5 do m[j]:=d[j];
if t<>'000' then begin
c:=t[3];case c of '0':str3:='' else str3:=dig[c] end;
c:=t[2];case c of '0':str2:='';
'1':begin case t[3] of
'0':str2:='десять ';
'2':str2:='двенадцать ';
'3':str2:='тринадцать '
else str2:=copy(str3,1,length(str3)-1) +'надцать ';
end; if str2<>'' then str3:='';
end;
'2','3':str2:=dig[c]+'дцать ';
'4':str2:='сорок ';
'9':str2:='девяносто ' else str2:=dig[c]+'десят ';
end; c:=t[1];case c of '0':str1:='';
'1':str1:='сто ';
'2':str1:='двести ';
'3'..'4':str1:=dig[c]+'ста ';
'5'..'9':str1:=dig[c]+'сот ';
end;
if(numt=2)and(str3<>'') then case t[3] of '2'..'4':
begin if str3 ='два' then str3:='две ';m[2]:=m[2]+'и' end;
'1':if str3 ='один' then
begin str3:='одна ';m[2]:=m[2]+'а' end;
end;
if(numt>2)and(str3<>'') then case t[3] of '2'..'4':m[numt]:=m[numt]+'а';
'0','5'..'9':m[numt]:=m[numt]+'ов';
end
else if numt>2 then m[numt]:=m[numt]+'ов';
if numt>1 then s_trd:=str1+str2+str3+' '+m[numt]
else s_trd:=str1+str2+str3;
end
else s_trd:='';
end{s_trd};
begin{conv_int} k:=length(int); if k<15 then
for j:=1 to 15-k do int:='0'+int;
if k>15 then halt ;
for j:=1 to 5 do
trd[j]:=int[15-(j-1)*3-2]+int[15-(j-1)*3-1]+int[15-(j-1)*3];
for j:=5 downto 1 do
s_int[6-j]:=s_trd(trd[j], j);
end{conv_int};
END {convert}.
program demo_conv_int; {Тест модуля convert}
uses convert;
var j:byte;i:string;str_i:array_s;{type array_s=array[1..5] of string}
begin repeat write('Введите целое число:');readln(i);
conv_int(i,str_i);for j:=1 to 5 do { Построчный вывод названия числа i}
if str_i[j]<>'' then writeln(str_i[j]); readln(i);
until i=''; {Выход из цикла при нажатии enter}
end{dem_conv}.