?>
Составить блок-схему по коду(с++) или по условию. ХЕЛПаните Описать структуру с именем Aeroflot, содержащую следующие поля: dest – название пункта назначения рейса, number – номер рейса, type – тип самолета. Написать программу, выполняющую ввод с клавиатуры данных в массив Aeroport, состоящий из 7 структур типа Aeroflot. Записи должны быть упорядочены по возрастанию номера рейса. Вывести на экран номера рейсов и типы самолетов, вылетающих в пункт назначения, название которого совпало с названием, введённым с клавиатуры. Если таких рейсов нет, то вывести соответствующее сообщение. #include using namespace std; struct Aeroflot { char punkt_naznachenia[40]; int nomer_reisa; char tip_samoleta[20]; }; int main() { Aeroflot as[7]; int i = 0, kol = 7; for (i = 0; i < kol; i++) { cout « i + 1 « "-aya zapis " « endl; cout « "Vvedite nazvanie punkta naznachenia reisa(ne bolee 40 simvolov) " « endl; cin » as[i].punkt_naznachenia; cout « "Vvedite nomer reisa " « endl; cin » as[i].nomer_reisa; cout « "Vvedite tip samoleta(ne bolee 20 simvolov) " « endl; cin » as[i].tip_samoleta; } int temp; for (i = 0; i < kol; i++) { if (as[i].nomer_reisa > as[i + 1].nomer_reisa) { temp = as[i].nomer_reisa; as[i].nomer_reisa = as[i + 1].nomer_reisa; as[i].nomer_reisa = as[i + 1].nomer_reisa = temp; continue; } cout « "Vivod zapisey " « endl; for (i = 0; i < kol; i++) { cout « as[i].punkt_naznachenia « " "; cout « as[i].nomer_reisa « " "; cout « as[i].tip_samoleta « endl; } char poisk_samoletov[40]; cout « "Punkt naznachenia reisa " « endl; cin » poisk_samoletov; bool f = false; for (i = 0; i < kol; i++) if (strcmp(as[i].punkt_naznachenia, poisk_samoletov) == 0) { cout « "Nomer reisa "; cout « as[i].nomer_reisa « endl; cout « "Tip samoleta "; cout « as[i].tip_samoleta « endl; f = true; } if (!f) { cout « "Net takogo punkta naznachenia reisa " « endl; } system("pause"); } return 0; }
Ответы
var
f:file of integer;
i,k:integer;
begin
Randomize;
Assign(f,'in.dat'); Rewrite(f);
for i:=1 to 20 do begin
k:=Random(99)+1;
Write(f,k)
end;
Close(f)
end.
Тестовое решение
38 35 14 46 92 49 51 48 84 90 26 14 38 79 82 77 7 24 94 13
2. Основная программа
uses Crt;
const
nn=100;
var
i,j,k,n:integer;
fin,fout:file of integer;
a:array[1..nn] of integer;
dub:boolean;
begin
ClrScr;
Assign(fin,'in.dat'); Reset(fin);
Read(fin,k);
if not eof(fin) then begin
n:=1; Write(k,' '); a[n]:=k
end
else n:=0;
while (not eof(fin)) and (n<=nn) do begin
Read(fin,k); Write(k,' ');
j:=1; dub:=false;
while (j<=n) and (not dub) do begin
dub:=(a[j]=k); Inc(j);
end;
if not dub then begin Inc(n); a[n]:=k; Inc(j) end
end;
Writeln;
Close(fin);
for i:=1 to n do Write(a[i],' ');
Writeln; Writeln('n=',n);
Assign(fout,'out.dat'); Rewrite(fout);
Write(fout,n); Close(fout);
ReadKey
end.
Тестовое решение:
38 35 14 46 92 49 51 48 84 90 26 14 38 79 82 77 7 24 94 13
38 35 14 46 92 49 51 48 84 90 26 79 82 77 7 24 94 13
n=18
В качестве бонуса - решение этой же задачи в современной системе программирования PascalABC.NET.
// PascalABC.NET 3.1, сборка 1219 от 16.04.2016
begin
var fin,fout:file of integer;
Reset(fin,'in.dat');
var k:integer;
var a:=new integer[fin.FileSize];
var n:=0;
while not eof(fin) do begin
Read(fin,k); a[n]:=k; Inc(n)
end;
Close(fin);
a.Println;
var b:=a.ToHashSet;
b.Println; Writeln('n=',b.Count)
end.
Тестовое решение
38 35 14 46 92 49 51 48 84 90 26 14 38 79 82 77 7 24 94 13
38 35 14 46 92 49 51 48 84 90 26 79 82 77 7 24 94 13
n=18
И вопрос: для чего давать школьникам, 9/10 из которых никогда не будут программистами, устаревшие и громоздкие, сложные для понимания, написания и отладки системы программирования? Чтобы показать, "как все это сложно"?