0% found this document useful (0 votes)
37 views

Array & Record (Example)

This document contains two examples of using records in Pascal programs. The first example defines a book record type and procedures to enter a new book record and display its details. It passes a single book record as an argument. The second example defines an array of book records and uses a loop to enter details for 10 records, then displays the details of one selected record.

Uploaded by

lasercrazer
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Array & Record (Example)

This document contains two examples of using records in Pascal programs. The first example defines a book record type and procedures to enter a new book record and display its details. It passes a single book record as an argument. The second example defines an array of book records and uses a loop to enter details for 10 records, then displays the details of one selected record.

Uploaded by

lasercrazer
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Example #1: Passing Records as Arguments

Program MyFavoriteBook; Type Str25 = String[25]; TBookRec = Record Title, Author, ISBN : Str25; Price : Real; End; Procedure EnterNewBook ( var newBook : TBookRec ); Begin Writeln('Please enter the book details: '); Write('Book Name: '); Readln(newBook.Title); Write('Author: '); Readln(newBook.Author); Write('ISBN: '); Readln(newBook.ISBN); Write('Price: '); Readln(newBook.Price); End; Procedure DisplayBookDetails(myBookRec : TBookRec); Begin Writeln('Here are the book details:'); Writeln; Writeln('Title: ', myBookRec.Title); Writeln('Author: ', myBookRec.Author); Writeln('ISBN: ', myBookRec.ISBN); Writeln('Price: ', myBookRec.Price); End; Var bookRec : TBookRec; Begin EnterNewBook(bookRec); Writeln('Thanks for entering the book details'); DisplayBookDetails(bookRec); Readln; End.

Example #2: Arrays of Records


Program MyHomeLibrary; Type Str25 = String[25]; TBookRec = Record Title, Author, ISBN : Str25; Price : Real; End; Procedure EnterNewBook (var newBook : TBookRec); Begin Writeln('Please enter the book details: '); Write('Book Name: '); Readln(newBook.Title); Write('Author: '); Readln(newBook.Author); Write('ISBN: '); Readln(newBook.ISBN); Write('Price: '); Readln(newBook.Price); End; Var bookRecArray : Array[1..10] of TBookRec; i : 1..10; Begin For i := 1 to 10 do EnterNewBook(bookRecArray[i]); Writeln('Thanks for entering the book details'); Write('Now choose a record to display from 1 to 10: '); Readln(i); Writeln('Here are the book details of record #',i,':'); Writeln; Writeln('Title: ', bookRecArray[i].Title); Writeln('Author: ', bookRecArray[i].Author); Writeln('ISBN: ', bookRecArray[i].ISBN); Writeln('Price: ', bookRecArray[i].Price); Readln; End.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy