Records - PowerPoint PPT Presentation

About This Presentation
Title:

Records

Description:

... required a program in order to enter the data they already had stored on cards. ... Type Love(L), Drama(D), Violent(V), Available ? ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 12
Provided by: willia442
Category:
Tags: cards | love | records

less

Transcript and Presenter's Notes

Title: Records


1
Records
Foundation Studies Course
2
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
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
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
Declaring Records
  • A typical declaration follows
  • TYPE
  • studentinfo RECORD
  • name string
  • age integer
  • gender char
  • registeredboolean
  • END
  • VAR student1 studentinfo

6
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
Example - Declarations
  • program prog6
  • uses CRT
  • type
  • StudentInfo record
  • namestring
  • ageinteger
  • citystring
  • zipinteger
  • end
  • const
  • Max2
  • var
  • numberinteger
  • Students array 1..Max of StudentInfo

8
Example - Input
  • Begin
  • clrscr
  • INPUT
  • writeln('Enter Student Details')
  • for number1 to Max do
  • begin
  • write('Name ',number,' ')
  • readln(Studentsnumber.name)
  • write('Age ',number,' ')
  • readln(Studentsnumber.age)
  • write('City ',number,' ')
  • readln(Studentsnumber.city)
  • write('Zip ',number,' ')
  • readln(Studentsnumber.zip)
  • writeln
  • end

9
Example - Output
  • clrscr
  • OUTPUT
  • writeln('These are the Student Details you
    entered')
  • for number1 to Max do
  • begin
  • write(Studentsnumber.name)
  • write(' ',Studentsnumber.age)
  • write(' ',Studentsnumber.city)
  • writeln(' ',Studentsnumber.zip)
  • end
  • End.

10
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
11
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.
Write a Comment
User Comments (0)
About PowerShow.com