Presentation is loading. Please wait.

Presentation is loading. Please wait.

Foundation Studies Course M.Montebello Records Foundation Studies Course.

Similar presentations


Presentation on theme: "Foundation Studies Course M.Montebello Records Foundation Studies Course."— Presentation transcript:

1 Foundation Studies Course M.Montebello Records Foundation Studies Course

2 Foundation Studies Course M.Montebello More than 1 datatype … A record is a user defined data type suitable for grouping data elements together. All elements of an array must contain the same data type. A record overcomes this by allowing us to combine different data types together.

3 Foundation Studies Course M.Montebello Where is it applicable? Suppose we want to create a data record which holds a student name and mark. The student name is a packed array of characters, and the mark is an integer. We could use two separate arrays for this, but a record is easier. The method to do this is, –define or declare what the new data group (record) looks like –create a working variable to be of that type

4 Foundation Studies Course M.Montebello Definition TYPE RECORD_NAME = record Var1 : data type; Var 2 : data type; Var 3 : data type END; The first portion defines the composition of the record identified as RECORD_NAME. It consists of a number of parts (called fields). Each field will have: –Variable Name : –Data Type for the variable name; And terminates with the reserved word END;

5 Foundation Studies Course M.Montebello Declaring Records A typical declaration follows: TYPE studentinfo = RECORD name : string; age: integer; gender: char; registered:boolean END; VAR student1 : studentinfo;

6 Foundation Studies Course M.Montebello Assigning Values Each of the individual fields of a record are accessed by using the DOT format, recordname.fieldname := value or variable; e.g. student1.name := 'JOE BLOGGS '; student1.age := 21; student1.gender := ‘M’; student1.registered := TRUE;

7 Foundation Studies Course M.Montebello Example - Declarations program prog6; uses CRT; type StudentInfo = record name:string; age:integer; city:string; zip:integer; end; const Max=2; var number:integer; Students: array [1..Max] of StudentInfo;

8 Foundation Studies Course M.Montebello Example - Input Begin clrscr; {INPUT} writeln('Enter Student Details:'); for number:=1 to Max do begin write('Name ',number,': '); readln(Students[number].name); write('Age ',number,': '); readln(Students[number].age); write('City ',number,': '); readln(Students[number].city); write('Zip ',number,': '); readln(Students[number].zip); writeln; end;

9 Foundation Studies Course M.Montebello Example - Output clrscr; {OUTPUT} writeln('These are the Student Details you entered:'); for number:=1 to Max do begin write(Students[number].name); write(' ',Students[number].age); write(' ',Students[number].city); writeln(' ',Students[number].zip); end; End.

10 Foundation Studies Course M.Montebello Lab 1 Change Program 6 to be able to be able to store 30 students with the following details: Name Maths English Maltese Average Mark Grade A (80-100) B (60-80) C (50-60) D (40-50) F (less than 40) Name: Joe Borg Maths: 55 English: 68 Maltese: 75 Average: 66.0 Grade: B Name: Joe Borg Maths: 55 English: 68 Maltese: 75 Average: 66.0 Grade: B

11 Foundation Studies Course M.Montebello Lab 2 The owners of a video shop decided to computerize their database and required a program in order to enter the data they already had stored on cards. Each card had details about a single video, namely: Name of video, Reference number, Location - Shelf number, Type – Love(L), Drama(D), Violent(V), Available ? Write a program to enter 5 items into this database and display them in table form.


Download ppt "Foundation Studies Course M.Montebello Records Foundation Studies Course."

Similar presentations


Ads by Google