Зайцев М. Г. / 1
.docxМИНИСТЕРСТВО ОБРАЗОВАНИЯ РОССИИ
Новосибирский государственный технический университет
ЛАБОРАТОРНАЯ РАБОТА № 1
по курсу «Информатика и программирование»
«Комбинированные типы»
Факультет бизнеса
Группа: ФБИ-11
Студенты: Рыбаченко А.А.
Преподаватель: Зайцев М.Г.
Новосибирск
2012г.
Цель: Изучение синтаксиса и семантики записей и констант типа"запись".
Задание
Спроектировать и реализовать на Паскале программу, которая в режиме диалога опрашивает пользователя и при наличии у него желания выполняет следующие действия:
- вводит данные в поля переменной типа "запись" с клавиатуры терминала;
- выводит данные из полей переменной типа "запись" на устройство отображения.
Разработать программы для следующих вариантов записей:
- type =
complex = record
re,im : real;
end
Текст программы:
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
complex = record
re,im : real;
end;
var
a:array [1..11] of complex;
b,c:integer;
procedure ReadRecord (var x : complex); // осуществляющая ввод с клавиатуры терминала //значений в поля записи;
var d:real;
begin
write('Enter the real part of the number:');
readln(d);
x.re:=d;
write('Enter the imaginary part of the number:');
readln(d);
x.im:=d;
end;
procedure WriteRecord (x:integer ); // осуществляет вывод на устройство отображения значений //полей записи a;
var e:integer;
begin
e:=x;
while e-x<>e+1 do begin
writeln('#',e-x+1,'Complex:',a[e-x+1].re:0:3,'+',a[e-x+1].im:0:3,'i');
x:=x+1;
end;
end;
Begin
b:=0;
c:=1;
while b<>3 do begin writeln('1. Enter complex number');
writeln('2. The resulting number');
writeln('3. Exit');
readln(b);
end;
if (b=1) and (c<11) then begin
ReadRecord (a[b]);c:=c+1; end
else if b=2 then WriteRecord(b-2);
end.
- type sex = (male, female);
r = record
family : string;
age : word;
case a : sex of
male : (case b: boolean of true:(weight, height:real))
end
Текст программы:
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
type sex = (male, female);
r = record
family : string;
age : word;
case a : sex of
male : (case b: boolean of true:(weight, height:real))
end;
procedure input(var x:r);
var i:integer; t:char; p:string;
begin
i:=0;
while i<>1 do
begin
write('Input family '); readln(x.family);
write(' age '); readln(x.age);
write(' sex(male or female) '); readln(p);
if p = 'male' then begin
x.a:=male;
write(' weight '); readln(x.weight);
write(' height '); readln(x.height);
end
else x.a:=female;
write('Continie input?(Y or N) '); readln(t);
if (t='N') or (t='n') then i:=1;
end;
end;
procedure output(x:r);
begin
Writeln('Family: ',x.family);
Writeln('Age: ',x.age);
if x.a=male then
begin
writeln('Sex: Male');
writeln('Weight: ',x.weight:0:2);
writeln('Height: ',x.height:0:2);
end
else
writeln('Sex: Female');
end;
var t:r; s:char; i:integer;
begin
i:=0;
while i<>1 do
begin
writeln('1 - input');
writeln('2 - output');
writeln('3 - exit');
readln(s);
case s of
'1': input(t);
'2': output(t);
'3': i:=1;
else
begin
writeln;
writeln('ERROR');
writeln;
end;
end;
end;
end.
- type figure = (rectangle, triangle, circle);
r = record
x,y : real;
case kind : figure of
rectangle : (hight, weight : real);
triangle : (size1, size2, angle : real);
circle : (radius : real);
end
Текст программы:
program Project3;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
fuigurForm=( triangle, rectangle, round, defunct);
fuigur=record
x,y:real;
case Form:fuigurForm of
triangle:(stor,ctor,ygl:real);
rectangle:(Vicota,shirina:real);
round:(rad:real);
end;
var fig:array[1..11] of fuigur;
id,i:integer;
procedure input(var n:fuigur);
var clv:string; l:integer;
begin
l:=0;
write('Please, enter the shape of the figure: '); readln(clv);
if clv='Triangle ' then l:=1
else if clv='Rectangle ' then l:=2
else if clv='Round' then l:=3;
case l of
1: begin n.Form:= triangle;
write('Enter a coordinate x '); readln(n.x);
write('Enter a coordinate y '); readln(n.y);
write('Enter a size of the parties 1 '); readln(n.stor);
write('Enter a size of the parties 2 '); readln(n.ctor);
write('Enter a angle '); readln(n.ygl);
end;
2: begin n.Form:= rectangle;
write('Enter a coordinate x '); readln(n.x);
write('Enter a coordinate y '); readln(n.y);
write('Enter a height '); readln(n.Vicota);
write('Enter a width '); readln(n.shirina);
end;
3: begin n.Form:= round;
write('Enter a coordinate x '); readln(n.x);
write('Enter a coordinate y '); readln(n.y);
write('Enter a radius '); readln(n.rad);
end;
else begin writeln('Nonexistent_figure'); n.Form:= defunct end;
end;
end;
procedure exit(k:integer);
var n:integer;
begin
n:=k;
while n-k<>n+1 do begin
write('#',n-k+1,' Forma:');
case fig[n-k+1].Form of
triangle:
writeln(' triangle, ',' Coordinate:',fig[n-k+1].x:0:3,',',fig[n-k+1].y:0:3,', Size of the parties 1:',fig[n-k+1].stor:0:3,', Size of the parties 2:',fig[n-k+1].ctor:0:3,', Angle:',fig[n-k+1].ygl:0:3);
rectangle:
writeln('Rectangle,','Coordinate:',fig[n-k+1].x:0:3,',',fig[n-k+1].y:0:3,',Height:',fig[n-k+1].Vicota:0:3,', Width:',fig[n-k+1].shirina:0:3);
round:
writeln('Round,','Coordinate:',fig[n-k+1].x:0:3,',',fig[n-k+1].y:0:3,',Radius:',fig[n-k+1].rad:0:3);
defunct:
writeln(' Nonexistent figure');
end;
k:=k-1;
end;
end;
begin
id:=0; i:=1;
while id<>3 do begin
writeln('1- Input figure');
writeln('2- Output figure');
writeln('3- Exit');
readln(id);
if (id=1) and (i<11) then begin
input(fig[i]);i:=i+1; end
else if id=2 then exit(i-2);
end;
end.