Текст задания
Сформировать одномерный массив из элементов массива двумерного по указанному в варианте правилу и упорядочить элементы созданного массива. Числа M и N вводятся с клавиатуры. Для задания исходной матрицы предусмотреть два варианта: ввод с клавиатуры и ввод с помощью датчика случайных чисел. Возможность выбора пользователем варианта ввода матрицы должна быть предусмотрена в тексте программы.
• Элементов строк, стоящих на четных местах. Отсортировать массив по убыванию
Ниже представлен исходный код программы на языке Pascal. Также имеется оформленный отчет в Word, который содержит блок-схему алгоритма работы программы, описание используемых переменных и скриншоты результатов работы программы.
Исходный код программыProgram Kursovaya;
Uses crt, graph;
Type
coordinates = (x, y);
extremums = (min, max);
Var
dataExists: boolean;
activeMenuItem, i: integer;
inputStep: real;
input: array[coordinates, extremums] of real;
key: char;
s: string;
{------------------------------}
Function f (x: real): real;
Begin
f := (x * x * x + 15) / (2 * x + 4);
End;
{------------------------------}
Procedure BuildMenu;
Const
menuItems: array[0..4] of string = (
'Vvod', 'Raschet', 'Grafik', 'O programme', 'Vyhod');
Begin
ClrScr;
For i := 0 to 4 do begin
If i = activeMenuItem then TextColor(Cyan)
Else TextColor(White);
WriteLn(menuItems[i]);
end;
End;
{------------------------------}
Procedure InputMenu;
Var
errorCode: integer;
k: extremums;
Begin
ClrScr;
For k := min to max do input[x][k] := 0;
inputStep := 0;
k := min;
i := 0;
While (inputStep = 0) do begin
If (i < 2) then Write('Vvedite X', (i + 1), ': ')
Else Write('Vvedite shag: ');
ReadLn(s);
If (i < 2) then begin
Val(s, input[x][k], errorCode);
If input[x][k] <> -2 then input[y][k] := f(input[x][k]);
end
Else Val(s, inputStep, errorCode);
If errorCode <> 0 then WriteLn('Vvedite chislo.')
Else If input[x][k] = -2 then WriteLn('Funkciya ne opredelena v to4ke -2.')
Else If (i = 1) and (input[x][min] >= input[x][max]) then WriteLn('X2 doljno byt bolshe X1.')
Else If (i = 2) and (inputStep <= 0) then WriteLn('Shag doljen byt bolshe 0.')
Else begin
Inc(i);
If (k < max) then Inc(k);
end
end;
dataExists := true;
End;
{------------------------------}
Procedure Calc;
Var
xt: real;
Begin
xt := input[x][min];
While (xt <= input[x][max]) do begin
ClrScr;
For i := 0 to 15 do begin
If xt <> -2 then WriteLn(xt:8:3, ' ', f(xt):8:3)
Else WriteLn(xt:8:3, ' ', 'Ne opredelena');
xt := xt + inputStep;
If (xt > input[x][max]) then break;
end;
key := ReadKey;
If key = #27 then break; {Esc}
end;
End;
{------------------------------}
Procedure BuildGraph;
Const
step: real = 0.1;
Var
gd, gm: integer;
xt: real;
display: array[coordinates, extremums] of integer;
scale: array[coordinates] of real;
Begin
gd := Detect;
InitGraph(gd, gm, '');
{Raschet ramki}
display[x][min] := Round(0.1 * GetMaxX);
display[x][max] := Round(0.9 * GetMaxX);
display[y][min] := Round(0.1 * GetMaxY);
display[y][max] := Round(0.9 * GetMaxY);
{Raschet min/max znachenii}
If input[x][max] < -2 then begin
input[y][min] := f(input[x][max]);
input[y][max] := f(input[x][min]);
end
Else If input[x][min] > 2 then begin
input[y][min] := f(input[x][min]);
input[y][max] := f(input[x][max]);
end
Else If (input[x][min] > -2) and (input[x][max] < 2) then begin
input[y][min] := f(input[x][max]);
input[y][max] := f(input[x][min]);
end
Else begin
input[y][min] := f(-2.1);
If (Abs(input[x][max]) <= Abs(input[x][min])) then input[y][max] := f(input[x][min])
Else input[y][max] := f(input[x][max]);
end;
scale[x] := (display[x][max] - display[x][min]) / (input[x][max] - input[x][min]);
scale[y] := (display[y][max] - display[y][min]) / Abs(input[y][max] - input[y][min]);
{Vyvod ramki i min/max znachenii}
SetColor(White);
Line(display[x][min], display[y][min], display[x][min], display[y][max]);
Line(display[x][min], display[y][max], display[x][max], display[y][max]);
Line(display[x][max], display[y][max], display[x][max], display[y][min]);
Line(display[x][max], display[y][min], display[x][min], display[y][min]);
If (input[y][min] <= 0) then begin
Line(display[x][min], display[y][min] + Round(input[y][max] * scale[y]),
display[x][max], display[y][min] + Round(input[y][max] * scale[y]));
end;
If (input[x][min] < 0) AND (input[x][max] > 0) then begin
Line(display[x][min] + Abs(Round(input[x][min] * scale[x])), display[y][min],
display[x][min] + Abs(Round(input[x][min] * scale[x])), display[y][max]);
end;
SetTextJustify(RightText, BottomText);
Str(input[y][min]:5:1, s);
OutTextXY(display[x][min], display[y][max], s);
Str(input[y][max]:5:1, s);
OutTextXY(display[x][min], display[y][min], s);
SetTextJustify(CenterText, TopText);
Str(input[x][min]:5:1, s);
OutTextXY(display[x][min], display[y][max] + 2, s);
Str(input[x][max]:5:1, s);
OutTextXY(display[x][max], display[y][max] + 2, s);
{Postroenie grafika}
xt := Round(input[x][min] / step) * step;
MoveTo(display[x][min], display[y][min] - Round((f(xt) - input[y][max]) * scale[y]));
SetColor(Yellow);
While xt < input[x][max] do begin
xt := xt + step;
If (Round(xt * 10) / 10) <> -2.0 then LineTo(display[x][min] + Round((xt - input[x][min]) * scale[x]),
display[y][min] - Round((f(xt) - input[y][max]) * scale[y]))
Else begin
LineTo(display[x][min] + Round((-2 - input[x][min]) * scale[x]), display[y][max]);
MoveTo(display[x][min] + Round((-2 - input[x][min]) * scale[x]), display[y][min]);
end;
end;
ReadKey;
CloseGraph;
End;
{------------------------------}
Procedure About;
Begin
ClrScr;
WriteLn('O programme');
ReadKey;
End;
{------------------------------}
Begin
activeMenuItem := 0;
dataExists := false;
BuildMenu;
Repeat
key := ReadKey;
If key = #0 then begin
key := ReadKey;
Case key of
#72: begin {Strelka vverh}
Dec(activeMenuItem);
If activeMenuItem < 0 then activeMenuItem := 4;
end;
#80: begin {Strelka vniz}
Inc(activeMenuItem);
If activeMenuItem > 4 then activeMenuItem := 0;
end;
end;
end
Else begin
If key = #13 then {Enter}
Case activeMenuItem of
0: InputMenu;
1: If dataExists then Calc;
2: If dataExists then BuildGraph;
3: About;
4: Break;
end;
end;
BuildMenu;
Until key = #27; {Esc}
End.Работа с массивами в Pascal
- Дисциплина: Программирование
- Код работы: КО-280
- Работу выложил: Администратор
-
200.00 р.
Теги: Pascal
Не подошла работа?
Узнайте стоимость написания работы по Вашему заданию
(это быстро и бесплатно)
