records c2

24
Pascal Programming Language Omar ElSabek & Fayez G hazzawi IT Engineering 3 th year UNKNOWN Department programming II

Upload: omar-al-sabek

Post on 13-Apr-2017

239 views

Category:

Education


0 download

TRANSCRIPT

Pascal Programming Language

Omar ElSabek & Fayez GhazzawiIT Engineering3th year – UNKNOWN Department

programming II

Sets

Record

Files (Text & Binary)

Pointers

Linked Lists

Unit

Course Index :

• Let’s Begin learning the RECORDS

Program Test();Var

First_name : array [1..100] of String;Last_name : array [1..100] of String;Age : array [1..100] of Integer;Day : array [1..100] of Integer;Month : array [1..100] of Integer;year : array [1..100] of Integer;i,n : Integer;

BeginReadln(n);For i:=1 to n doRead(First_name[i],Last_name[i],Age[i],Day[i],Month[i],year[i]);Readln;

End.

OMG !!

Record

A record is a special type of data structure that, unlike arrays, collects different data types that define a particular structure such as a book, product, person and many others. Which defines the data structure under the Type user definition.

How we Define it ?

typerecord-name = record

field-1: field-type1;field-2: field-type2;...

end ;

What Data type it can content ?

Simple Data TypeIntegerRealCharStringBoolean

What Data type it can content ?

complex objectDate (D,M,Y)Time (H,M,S)Rectangle (L,W)Employee (….)…

multi arrays for multi data type

Examples:

program exRecords;typeBooks = record

title: String [30];author: String [30];subject: String [30];book_id: longint;

end;

varBook1, Book2: Books;

begin(* book 1 specification *)Book1.title := 'C Programming';Book1.author := 'Nuha Ali '; Book1.subject := 'C Programming Tutorial';Book1.book_id := 6495407;

(* book 2 specification *)Book2.title := 'Telecom Billing';Book2.author := 'Zara Ali';Book2.subject := 'Telecom Billing Tutorial';Book2.book_id := 6495700;

writeln ('Book 1 title : ', Book1.title);writeln('Book 1 author : ', Book1.author);writeln( 'Book 1 subject : ', Book1.subject);writeln( 'Book 1 book_id : ', Book1.book_id);writeln;

(* print Book2 info *)writeln ('Book 2 title : ', Book2.title);writeln('Book 2 author : ', Book2.author);writeln( 'Book 2 subject : ', Book2.subject);writeln( 'Book 2 book_id : ', Book2.book_id);

end.

TypeDate = Record

Day, month, year : Integer;End;STD = Record

First_name : string[20];Last_name : String[20];Age : Real;DODO : Date;

End;

STD

DODOFNAME

LNAME

Age

D M Y

Varx,y : STD; A : array [1..100] of STD; I : integer;

x.First_nameA[i].First_nameA[i].AgeA[i].DODO.Day

x.First_name

Last_name

DODO.

Age

Year

Month

Day

For I:=1 to 100 doBegin

Readln(A[I].First_name);Readln(A[I].Last_name);Readln(A[I].Age);Readln(A[I].Date.year);Readln(A[I].Date.Month);Readln(A[I].Date.Day);

End;

It is using for accessing record fields directlywithout [dot] operator

Accessing fields without [dot]

With X doBegin

Readln(First_name);Readln(Last_name);Readln(Age);

With Date doBegin

Readln(year);Readln(Month);Readln(Day);

End;End;

:كتابة برنامج يدخل موظف شركة طيران بيانات طائرة

يحدد اوال عدد المقاعد في الطائرة

:ثم يقوم ب ادخال بيانات الحجوزات والتي تتضمن

الكنية -3اسم حامل التذكرة -2رقم المقعد -1

قيمة منطقية تحدد هل المقعدد من الدرجة االولى -5موعد الرحلة -4

(يتم ادخال البيانات مرتيين الن الرحلة ذهاب و اياب )

:المطلوب

اجرائية ملئ سجالت الطائرة ذهابا و ايابا -1

اجرائية عرض سجالت الطائرة -2

اجرائية بحث و طباعة معلومات مقعد حسب الرقم -3

:المطلوب

اجرائية ملئ سجالت الطائرة ذهابا و ايابا -1

اجرائية عرض سجالت الطائرة -2

اجرائية بحث و طباعة معلومات مقعد حسب الرقم-3

ترتيب سجل الطائرة حسب رقم المقعد -4

طباعة مجموعة ارقام المقاعد التي تم حجزها ذهابا و ايابا في الرحلة -5