dikdack

Untitled

Dec 15th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 8.62 KB | None | 0 0
  1. program lab7;
  2.  
  3. {$APPTYPE CONSOLE}
  4. uses crt;
  5.  
  6. type
  7.   Rec1=Record
  8.     tema:string;
  9.     num:integer;
  10.     raz:string;
  11.     zap:integer;
  12.     next1:^Rec1;
  13.   end;
  14.     Rec4=Record
  15.     raz:string;
  16.     zap:integer;
  17.     next4:^Rec4;
  18.   end;
  19.   Rec3=Record
  20.     num:integer;
  21.     next3:^Rec3;
  22.     next4:^Rec4;
  23.   end;
  24.   Rec2=Record
  25.     tema:string;
  26.     next2:^Rec2;
  27.     next3:^Rec3;
  28.   end;
  29.  
  30. var
  31.   tmpM, HeadM: ^Rec1;
  32.   tmpT, HeadT: ^Rec2;
  33.   tmpN, HeadN,tmpk: ^Rec3;
  34.   tmp1: ^Rec4;
  35.   z, numN, zapN, K, L, I, J, count: integer;
  36.   temaN, temaP, razN: string;
  37.   mas: array [1..100] of integer;
  38.  
  39. function check1(temaN:string):boolean;
  40. begin
  41.   tmpT:=HeadT;
  42.   check1:=False;
  43.   while tmpT<>nil do
  44.   begin
  45.     if tmpT^.tema = temaN then
  46.     begin
  47.       check1:=True;
  48.       exit;
  49.     end;
  50.     tmpT:=tmpT^.next2;
  51.   end;
  52. end;
  53.  
  54. function check2(numP:integer):boolean;
  55. begin
  56.   tmpN:=HeadN;
  57.   check2:=False;
  58.   while tmpN<>nil do
  59.   begin
  60.     if tmpN^.num = numP then
  61.     begin
  62.       check2:=True;
  63.       exit;
  64.     end;
  65.     tmpN:=tmpN^.next3;
  66.   end;
  67. end;
  68.  
  69. procedure SHOW3();
  70. begin
  71.   tmpM:=HeadM;
  72.   while tmpM<>nil do
  73.   begin
  74.     if tmpM^.zap > 10 then
  75.     begin
  76.       writeln('| ' ,tmpM^.tema, ' | ',tmpM^.num, ' | ', tmpM^.raz, ' | ',tmpM^.zap, ' |');
  77.     end;
  78.     tmpM:= tmpM^.next1;
  79.   end;
  80. end;
  81.  
  82. procedure SHOW4(temaP:string);
  83. begin
  84.   tmpM:=HeadM;
  85.   while tmpM<>nil do
  86.   begin
  87.     if tmpM^.tema = temaP then
  88.     begin
  89.       writeln('| ' ,tmpM^.tema, ' | ',tmpM^.num, ' | ', tmpM^.raz, ' | ',tmpM^.zap, ' |');
  90.     end;
  91.     tmpM:= tmpM^.next1;
  92.   end;
  93. end;
  94.  
  95.  
  96. procedure NEW(temaN,razN:string;numN,zapN:integer);
  97. begin
  98.   new(tmpM);
  99.   tmpM^.next1:= HeadM;
  100.   HeadM:= tmpM;
  101.   tmpM^.tema:= temaN;
  102.   tmpM^.num:= numN;
  103.   tmpM^.raz:= razN;
  104.   tmpM^.zap:= zapN;
  105.   if check1(temaN) then
  106.   begin
  107.     tmpT:= HeadT;
  108.     while tmpT^.tema <> temaN do
  109.     begin
  110.       tmpT:=tmpT^.next2;
  111.     end;
  112.    
  113.     if check2(numN) then
  114.     begin
  115.       tmpN:=HeadN;
  116.       while tmpN^.num <> numN do
  117.       begin
  118.         tmpN:=tmpN^.next3;
  119.       end;
  120.       new(tmp1);
  121.       tmp1^.next4:=tmpN^.next4;
  122.       tmpN^.next4:=tmp1;
  123.       tmp1^.raz:= razN;
  124.       tmp1^.zap:= zapN;
  125.     end
  126.     else
  127.     begin
  128.       new(tmpN);
  129.       tmpN^.next3:= HeadN;
  130.       HeadN:= tmpN;
  131.       tmpN^.num:= numN;
  132.       new(tmp1);
  133.       tmp1^.next4:=tmpN^.next4;
  134.       tmpN^.next4:=tmp1;
  135.       tmp1^.raz:= razN;
  136.       tmp1^.zap:= zapN;
  137.     end;
  138.   end
  139.   else
  140.   begin
  141.     new(tmpT);
  142.     tmpT^.next2:= HeadT;
  143.     HeadT:= tmpT;
  144.     tmpT^.tema:= temaN;
  145.     new(tmpk);
  146.     tmpk^.next3:=tmpT^.next3;
  147.     tmpT^.next3:=tmpk;
  148.     tmpk^.num:= numN;
  149.     new(tmp1);
  150.     tmp1^.next4:=tmpk^.next4;
  151.     tmpk^.next4:=tmp1;
  152.     tmp1^.raz:= razN;
  153.     tmp1^.zap:= zapN;
  154.   end;
  155. end;
  156.  
  157. procedure Numb ();
  158. begin
  159.   count := 0;
  160.   tmpM := HeadM;
  161.   while tmpM <> nil do
  162.   begin
  163.     inc(count);
  164.     tmpM := tmpM^.next1;
  165.   end;
  166. end;
  167.  
  168. //////////////////////////////////////////////
  169. begin
  170.   HeadM := nil;
  171.   HeadT := nil;
  172.   HeadN := nil;
  173.  
  174.   while true do
  175.   begin
  176.     textcolor(10);
  177.     writeln('');
  178.     writeln('******************** МЕНЮ ********************');
  179.     writeln('|--------------------------------------------|');
  180.     write('| '); textcolor(13); write('Выберите:                                  '); textcolor(10); writeln('|');
  181.     write('| '); textcolor(13); write('0. Завершение работы                       '); textcolor(10); writeln('|');
  182.     write('| '); textcolor(13); write('1. Добавление сведений                     '); textcolor(10); writeln('|');
  183.     write('| '); textcolor(13); write('2. Просмотр разделов с числом записей > 10 '); textcolor(10); writeln('|');
  184.     write('| '); textcolor(13); write('3. Просмотр всей таблицы                   '); textcolor(10); writeln('|');
  185.     write('| '); textcolor(13); write('4. Просмотр темы                           '); textcolor(10); writeln('|');
  186.     write('| '); textcolor(13); write('5. Вывод отсортированной таблицы           '); textcolor(10); writeln('|');
  187.     writeln('|--------------------------------------------|');
  188.     writeln('**********************************************');
  189.     write('Ваш выбор: ');
  190.     textcolor(15);
  191.     readln(z);
  192.     textcolor(10);
  193.     if z = 0 then
  194.       exit;
  195.     if z = 2 then
  196.     begin
  197.       writeln('|-------------------------------------------------------|');
  198.       write('|');
  199.       textcolor(13);
  200.       write('Формат:| тема | номер раздела | раздел | число записей'); textcolor(10); writeln(' |');
  201.       writeln('|-------------------------------------------------------|');
  202.       writeln('************************ ТАБЛИЦА ************************');
  203.       SHOW3();
  204.       writeln('*********************************************************');
  205.     end;
  206.     if z = 3 then
  207.     begin
  208.       tmpM:=HeadM;
  209.       writeln('|-------------------------------------------------------|');
  210.       write('|');
  211.       textcolor(13);
  212.       write('Формат:| тема | номер раздела | раздел | число записей'); textcolor(10); writeln(' |');
  213.       writeln('|-------------------------------------------------------|');
  214.       writeln('************************ ТАБЛИЦА ************************');
  215.       while tmpM<>nil do
  216.       begin
  217.         writeln('| ' ,tmpM^.tema, ' | ',tmpM^.num, ' | ', tmpM^.raz, ' | ',tmpM^.zap, ' |');
  218.         tmpM:= tmpM^.next1;
  219.       end;
  220.       writeln('*********************************************************');
  221.     end;
  222.     if z = 4 then
  223.     begin
  224.       write('Введите название темы: ');
  225.       textcolor(15);
  226.       readln  (temaP);
  227.       textcolor(10);
  228.       writeln('|-------------------------------------------------------|');
  229.       write('|');
  230.       textcolor(13);
  231.       write('Формат:| тема | номер раздела | раздел | число записей'); textcolor(10); writeln(' |');
  232.       writeln('|-------------------------------------------------------|');
  233.       writeln('************************ ТАБЛИЦА ************************');
  234.       SHOW4(temaP);
  235.       writeln('*********************************************************');
  236.     end;
  237.     if z = 5 then
  238.     begin
  239.       writeln('|-------------------------------------------------------|');
  240.       write('|');
  241.       textcolor(13);
  242.       write('Формат:| тема | номер раздела | раздел | число записей'); textcolor(10); writeln(' |');
  243.       writeln('|-------------------------------------------------------|');
  244.       writeln('************************ ТАБЛИЦА ************************');
  245.       Numb();
  246.       tmpM := HeadM;
  247.       i := 1;
  248.       while tmpM <> nil do
  249.       begin
  250.         mas[i] := tmpM^.zap;
  251.         tmpM := tmpM^.next1;
  252.         inc(i);
  253.       end;
  254.       K := 1;
  255.       for I
  256.       := 1 to count - 1 do
  257.         begin
  258.              K:= I;
  259.              for J := I + 1 to count do
  260.                if mas[J] < mas[K] then K := J;
  261.                L:=mas[I];
  262.                mas[I] := mas[K];
  263.                mas[K] := L;
  264.         end;
  265.         for i := 1 to count do
  266.         begin
  267.           tmpM:=HeadM;
  268.           while tmpM<>nil do
  269.           begin
  270.             if tmpM^.zap = mas[i] then
  271.             begin
  272.               writeln('| ' ,tmpM^.tema, ' | ',tmpM^.num, ' | ', tmpM^.raz, ' | ',tmpM^.zap, ' |');
  273.               break;
  274.             end;
  275.             tmpM:= tmpM^.next1;
  276.           end;
  277.         end;
  278.         writeln('*********************************************************');
  279.     end;
  280.     if z = 1 then
  281.     begin
  282.       textcolor(10);
  283.       writeln('**********************************************');
  284.       write('|'); textcolor(13); write('Название темы:               '); textcolor(10); write('|');
  285.       textcolor(15);
  286.       readln(temaN);
  287.       textcolor(10);
  288.       write('|'); textcolor(13); write('Номер раздела:               '); textcolor(10); write('|');
  289.       textcolor(15);
  290.       readln(numN);
  291.       textcolor(10);
  292.       write('|'); textcolor(13); write('Название раздела:            '); textcolor(10); write('|');
  293.       textcolor(15);
  294.       readln(razN);
  295.       textcolor(10);
  296.       write('|'); textcolor(13); write('Число записей в разделе:     '); textcolor(10); write('|');
  297.       textcolor(15);
  298.       readln(zapN);
  299.       textcolor(10);
  300.       writeln('**********************************************');
  301.       NEW(temaN,razN,numN,zapN);
  302.     end;
  303.     writeln('');
  304.   end;
  305. end.
Add Comment
Please, Sign In to add comment