+ All Categories
Home > Software > 2Bytesprog2 course_2014_c2_records

2Bytesprog2 course_2014_c2_records

Date post: 12-Aug-2015
Category:
Upload: kinan-ke
View: 22 times
Download: 0 times
Share this document with a friend
Popular Tags:
22
Prog_2 course- 2014 2 bytes team Kinan keshkeh IT Engineering-Damascus University 3 rd year
Transcript
Page 1: 2Bytesprog2 course_2014_c2_records

Prog_2 course- 2014

2 bytes team

Kinan keshkeh

IT Engineering-Damascus University

3rd year

Page 2: 2Bytesprog2 course_2014_c2_records

Record

Page 3: 2Bytesprog2 course_2014_c2_records

Data Structure:

Data Structure are divided into :

Complex types

Simple types

Records

• (char,integer,Boolean .... )

• User design type :

• Type mytype=1.. 100 ;

var x : mytype;

Page 4: 2Bytesprog2 course_2014_c2_records

Definition

Records are complex type which enables us to

combine a set of simple variables in one Data

structure named Record ....

Example: ( car’s information ) type

engine

production year

Example(2): date (year.. Month... Day).....

How we can define Records ?

Page 5: 2Bytesprog2 course_2014_c2_records

Ex:

• Type person=record

fname: string ;

lname: string;

age: integer;

end;

Note : we can define a record in one of its fields

• Type employee=record

address: string;

salary: real;

per: person;

end ;

Page 6: 2Bytesprog2 course_2014_c2_records

fname lname age

fname

per salary address

lname age

Page 7: 2Bytesprog2 course_2014_c2_records

• var Emp :array[1..100] of employee

Define variable of type record

• Note : you can define a matrix records

person

employee •var y:employee

•var x:person

Page 8: 2Bytesprog2 course_2014_c2_records

Using records :

Read record’s data :

readln(x);

Readln(y);

{ True }

readln(x.fname);

readln( y.address);

readln(y.per.age);

{ False }

Page 9: 2Bytesprog2 course_2014_c2_records

Read matrix of records

• for i=1 to 50 do

• begin

readln(Emp[i].salary);

readln(Emp[i].per.fname);

……………………………….

……………………………….

end;

• Var Emp : array[1..100] of employee;

Page 10: 2Bytesprog2 course_2014_c2_records

Write record’s data

{↔ writeln(y.per.fname);}

<<<Using with >>>

With y do Begin writeln(address); writeln(per.name); with per do begin writeln(fname); writeln(age); writeln(lname); end; end;

Page 11: 2Bytesprog2 course_2014_c2_records

In matrix of records

For i:=1 to 75 do

with Emp[i] do

begin

readln(address);

writeln(per.age);

……………………………….

……………………………….

end;

salary:=50000;

Page 12: 2Bytesprog2 course_2014_c2_records

Exercise : We have (record) of complex number :

1. Write procedure to input this number

2. Write procedure to print this number

3. Write procedure to combine two numbers

4. Write function to calculate Abs of number

Let’s go ....

Page 13: 2Bytesprog2 course_2014_c2_records

Program prog2_bytes

Uses wincrt

Type complex=record

re,Img : real;

end;

Procedure Inputcom(var c:complex);

Begin

with c do

Begin

writeln(‘enter the real part ‘);

readln(re);

writeln(‘enter the Img part ‘);

readln(Img);

end;

End;

Page 14: 2Bytesprog2 course_2014_c2_records

Procedure printcom( c: complex);

Begin

With c do

If Img<>0 then

Writeln(‘z= ‘,re:5:2,Img:5:2,’i’);

Else writeln(‘z=‘,re:5:2);

end;

End;

Procedure sumcom( a , b: complex ; var c:complex);

Begin

with c do

begin

re:=a.re+b.re;

Img:=a.Img+b.Img;

end;

End;

Page 15: 2Bytesprog2 course_2014_c2_records

Function Abscom(c : complex):real;

Begin

Abscom:=sqrt(sqr(c.re)+sqr(c.Img));

End;

Var x,y,z:complex;

Begin

Inputcom(x);

Inputcom(y);

Sumcom(x ,y ,z );

Printcom(z);

Writeln(‘|z|=‘,Abscom(z:5:2));

End.

Page 16: 2Bytesprog2 course_2014_c2_records

Homework: يىظف وانًطهىب كتاتح تشَايج عاو nنذٌُا ششكح تحىي

:تاستخذاو اإلجشائٍاخ وانتىاتع ورنك نهقٍاو تانًهاو انتانٍح

ادخال انثٍاَاخ انتانٍح عٍ يىظفً انششكح:

,انًذٌُح )انعُىاٌ انًفصم, تاسٌخ انعًم ,انشاتة ,االسى { }(سقى انثُاء ,انشاسع

طثاعح تٍاَاخ انًىظفٍٍ عهى شكم جذول

تشتٍة انسجالخ تصاعذٌا حسة االسى وطثاعح انسجالخ انًشتثح

سُح تانخذيح نهتقاعذ 25إحانح انًىظفٍٍ انزٌٍ عًهىا يٍ ساتثهى % 25يع خصى

Additional demand for creative

:قشسخ انششكح استخذاو يىظف جذٌذ وانًطهىب

ادخال تٍاَاخ انًىظف إنى انجذول دوٌ األخالل تتشتٍة انثحث عٍ انًىقع انًُاسة فً ) انسجالخ فٍه

( انسجم يثاششج

+3.5

+2.5

+4

+2.5

+2.5

Page 17: 2Bytesprog2 course_2014_c2_records

Revision Practice

Page 18: 2Bytesprog2 course_2014_c2_records

المطلوب كتابة إجرائية و تابع لحساب المضاعف المشترك األصغر والقاسم المشترك األكبر لعددين

program prog_2bytesteam;

procedure Lcm(a,b:integer; var c:integer);

var i,L,temp : integer;

begin

if (a>b) then

begin

temp:=a;

a:=b;

b:=temp;

end;

i:=1;

L:=a;

while( L mod b <> 0) do

begin

i:=i+1;

L:=a*i;

end;

c:=L;

end;

Page 19: 2Bytesprog2 course_2014_c2_records

program prog_2bytesteam;

function Lcm(a,b:integer):integer;

var i,L,temp:integer;

begin

if (a>b) then

begin

temp:=a;

a:=b;

b:=temp;

end;

i:=1;

L:=a;

while( L mod b <> 0) do

begin

i:=i+1;

L:=a*i;

end;

Lcm:=L;

end;

Page 20: 2Bytesprog2 course_2014_c2_records

program prog_2bytesteam;

procedure gcd(a,b:integer; var c:integer);

begin

while( a <> b ) do

if (a>b) then

a:=a-b

else

b:=b-a;

c:=a;

end;

Page 21: 2Bytesprog2 course_2014_c2_records

program prog_2bytesteam;

function gcd(a,b:integer):integer;

begin

while( a <> b ) do

if (a>b) then

a:=a-b

else

b:=b-a;

gcd:=a;

end;

Page 22: 2Bytesprog2 course_2014_c2_records

Group : group link

Mobile phone- Kinan : 0994385748

Facebook account : kinan’s account

2 bytes team


Recommended