PASCAL - RECORDS. To define a record type, you may use the type declaration statement. The record type is defined as

Similar documents
Lab - 10 Write a c# program to prepend the namespace name by calling the namespaceenabled version of either function or variable?

cout << "How many numbers would you like to type? "; cin >> memsize; p = new int[memsize];

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Structures can be easily used as a function parameters. It is done similar as with variables.

PROGRAMMAZIONE I A.A. 2017/2018

Apllications. February 17, Indian Institute of Space Science and Technology. MA122 - Computer Programming and. Apllications. Structures.

Department of Computer Science and Engineering. Programming for Problem Solving. I Year B.Tech. (I - Sem) Assistant Professor (M.

PASCAL - OBJECT ORIENTED

JAVASCRIPT - OBJECTS OVERVIEW

Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION

High level programming language Pascal

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Computer programming UNIT IV UNIT IV. GPCET,Dept of CSE, P Kiran Rao

MODULE 1. Introduction to Data Structures

C# MOCK TEST C# MOCK TEST II

SCALA ARRAYS. Following picture represents array mylist. Here, mylist holds ten double values and the indices are from 0 to 9.

C# MOCK TEST C# MOCK TEST I

DOCUMENT SECURITY IN WORD 2010

COMPUTER PROGRAMMING LOOPS

C# - ATTRIBUTES. Specifying an Attribute. Predefined Attributes. AttributeUsage

DB2 MOCK TEST DB2 MOCK TEST I

Algorithms & Data Structures

History. used in early Mac development notable systems in Pascal Skype TeX embedded systems

Vidyalankar F.Y. Diploma : Sem. II [CD/CM/CO/CW/DE/ED/EE/EI/EJ/EN/EP/ET/EV/EX/IC/IE/IF/IS/IU/MU] Programming in C

FORTRAN - ARRAYS. For example, to declare a one-dimensional array named number, of real numbers containing 5 elements, you write,

PL/SQL MOCK TEST PL/SQL MOCK TEST IV

COBOL - TABLE PROCESSING

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #34. Function with pointer Argument

Writing Functions in C

JAVASCRIPT MOCK TEST JAVASCRIPT MOCK TEST I

CSC 138 Structured Programming CHAPTER 3: RECORDS (STRUCT) [PART 1]

COMPILER DESIGN - RUN-TIME ENVIRONMENT

LISP - SEQUENCES. The function make-sequence allows you to create a sequence of any type. The syntax for this function is:

Database Views & Stored Procedures. Hans-Petter Halvorsen, M.Sc.

DATA STRUCTURES AND APPLICATIONS [As per Choice Based Credit System (CBCS) scheme] (Effective from the academic year ) SEMESTER - III

MATLAB - FUNCTIONS. Functions can accept more than one input arguments and may return more than one output arguments.

RUBY/LDAP TUTORIAL. The common API for application development is described in RFC1823 and is supported by Ruby/LDAP.

C Pointers. 6th April 2017 Giulio Picierro

Lecture 18 Tao Wang 1

SWIFT - CLOSURES. Global Functions Nested Functions Closure Expressions. Have a name. Capture values from enclosing function

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology

3/7/2018. Sometimes, Knowing Which Thing is Enough. ECE 220: Computer Systems & Programming. Often Want to Group Data Together Conceptually

CSCI Compiler Design

Vivekananda College of Engineering & Technology. Data Structures and Applications (15CS33)

G Programming Languages - Fall 2012

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5

Database Management Systems

D - FUNCTIONS. A basic function definition consists of a function header and a function body. Here are all the parts of a function:

GO MOCK TEST GO MOCK TEST I

JAVA.LANG.INTEGER CLASS

* Due 11:59pm on Sunday 10/4 for Monday lab and Tuesday 10/6 Wednesday Lab

Revising CS-M41. Oliver Kullmann Computer Science Department Swansea University. Robert Recorde room Swansea, December 13, 2013.

Microsoft Visual Basic 2005: Reloaded

CS201- Introduction to Programming Current Quizzes

Example. program sort; var a : array[0..10] of integer; procedure readarray; : function partition (y, z :integer) :integer; var i, j,x, v :integer; :

PASCAL. PASCAL, like BASIC, is a computer language. However, PASCAL, unlike BASIC, is a Blocked Structured Language (BASIC is known as unstructured).

C# is a modern, g eneral-purpose, object-oriented prog ramming lang uag e developed by Microsoft and approved by Ecma and ISO.

Chapter 9: Pointers Co C pyr py igh i t gh Pear ea so s n n E ducat ca io i n, n Inc. n c.

GWT - UIOBJECT CLASS

Vivekananda College of Engineering & Technology. Data Structures and Applications

JSP MOCK TEST JSP MOCK TEST III

PYTHON MOCK TEST PYTHON MOCK TEST III

DESIGN PATTERNS MOCK TEST DESIGN PATTERNS MOCK TEST III

Chapter 10 Introduction to Classes

Homework #3 CS2255 Fall 2012

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

ENERGY 211 / CME 211. Functions

FUNCTIONAL MODELLING

C Pointers 2013 Author Riko H i

Beginning Programming (Pascal) Lecture 75. Figure 1. type-declarations. simple-type. pointer-type. array-type. file-type. set-type.

Programming Studio #9 ECE 190

C/C++ Lab Sessions - COL 106

CS2351 Data Structures. Lecture 7: A Brief Review of Pointers in C

DESIGN PATTERNS MOCK TEST DESIGN PATTERNS MOCK TEST II

MAVEN MOCK TEST MAVEN MOCK TEST I

Programming in C++ 5. Integral data types

FORM 4 PASCAL PROGRAMMING 6.1 WHAT IS AN ARRAY? Unit 6: Arrays and Strings

DECLARAING AND INITIALIZING POINTERS

PERL MOCK TEST PERL MOCK TEST II

Linked Lists. Chapter 21

Linked lists Tutorial 5b

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Chapter 5 Names, Binding, Type Checking and Scopes

Pointers. In this section of notes you will learn about another type of variable that stores addresses rather than data. Memory: What You Know

Special Topics: Programming Languages

SWIFT - FUNCTIONS. Function Declaration: It tells the compiler about a function's name, return type, and parameters.

MAHOUT - RECOMMENDATION

Introduction to C++ with content from

VB.NET MOCK TEST VB.NET MOCK TEST III

FORTRAN - CHARACTERS

ANGULARJS - MOCK TEST ANGULARJS MOCK TEST II

APPENDIX TRANSLATING BETWEEN C, FORTRAN, AND PASCAL LANGUAGES

Classes and Methods גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון

XML SCHEMA BASED AOP WITH SPRING

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

COMP1008 Exceptions. Runtime Error

Revising CS-M41. Oliver Kullmann Computer Science Department Swansea University. Linux Lab Swansea, December 13, 2011.

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Chapter 7 Arrays. One-Dimensional Arrays. Fred Jack. Anna. Sue. Roy

Questions Bank. 14) State any four advantages of using flow-chart

Transcription:

http://www.tutorialspoint.com/pascal/pascal_records.htm PASCAL - RECORDS Copyright tutorialspoint.com Pascal arrays allow you to define of iables that can hold several data items of the same kind but a record is another user-defined data available in Pascal which allows you to combine data items of different kinds. Records consist of different fields. Suppose you want to keep track of your books in a library, you might want to track the following attributes about each book Title Author Subject Book ID Defining a Record To define a record, you may use the declaration statement. The record is defined as record-name = record field-1: field-1; field-2: field-2; field-n: field-n; Here is the way you would declare the Book record book_id: integer; The record iables are defined in the usual way as r1, r2, : record-name; Alternatively, you can directly define a record iable as Books : record book_id: integer; Accessing Fields of a Record To access any field of a record, we use the member access operator.. The member access operator is coded as a period between the record iable name and the field that we wish to access. Following is the example to explain usage of structure

Book1, Book2: Books; (* Declare Book1 and Book2 of Books *) 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; 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); Book 1 title : C Programming Records as Subprogram Arguments You can pass a record as a subprogram argument in very similar way as you pass any other iable or pointer. You would access the record fields in the similar way as you have accessed in the above example Book1, Book2: Books; (* Declare Book1 and Book2 of Books *)

(* procedure declaration *) procedure printbook( book: Books ); (* print Book info *) writeln ('Book title : ', book.title); writeln('book author : ', book.author); writeln( 'Book subject : ', book.subject); writeln( 'Book book_id : ', book.book_id); Book2.title := 'Telecom Billing'; Book2.author := 'Zara Ali'; Book2.subject := 'Telecom Billing Tutorial'; Book2.book_id := 6495700; printbook(book1); writeln; printbook(book2); Book 1 title : C Programming Pointers to Records You can define pointers to records in very similar way as you define pointer to any other iable as follows record-ptr = ^ record-name; record-name = record field-1: field-1; field-2: field-2; field-n: field-n; Now, you can store the address of a record iable in the above-defined pointer iable. To declare a iable of the created pointer, you use the keyword r1, r2, : record-ptr; Before using these pointers, you must create storage for a record-name iable, which will be manipulated by these pointers.

new(r1); new(r2); To access the members of a record using a pointer to that record, you must use the ^. operator as follows r1^.feild1 := value1; r1^.feild2 := value2; r1^fieldn := valuen; Finally, don't forget to dispose the used storage, when it is no longer in use dispose(r1); dispose(r2); Let us re-write the first example using a pointer to the Books record. Hope this will be easy for you to understand the concept BooksPtr = ^ Books; (* Declare Book1 and Book2 of pointer that refers to Book *) Book1, Book2: BooksPtr; new(book1); new(book2); Book1^.title := 'C Programming'; Book1^.author := 'Nuha Ali '; Book1^.subject := 'C Programming Tutorial'; Book1^.book_id := 6495407; 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 ('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); dispose(book1); dispose(book2);

Book 1 title : C Programming The With Statement We have discussed that the members of a record can be accessed using the member access operator.. This way the name of the record iable has to be written every time. The With statement provides an alternative way to do that. Look at the following code snippet taken from our first example The same assignment could be written using the With statement as With Book1 do title := 'C Programming'; author := 'Nuha Ali '; subject := 'C Programming Tutorial'; book_id := 6495407; Loading [MathJax]/jax/output/HTML-CSS/jax.js