PASCAL NOTES.doc

download PASCAL NOTES.doc

of 52

Transcript of PASCAL NOTES.doc

  • 8/11/2019 PASCAL NOTES.doc

    1/52

    Computer hard waresHard wares are physical parts of a computer system. They are tangible parts. They areclassi ed into input devices and output devices.

    Input devices are:

    a) Key boardb) Mouse

    c) Scanner etc

    Output devices are:a) Printer

    b) Monitor etc

    Soft wares These are sets of programs that are used to tell the computer hardware what to do and

    how to do it.They are classi ed into:

    a) System software

    b) pplication software

    c) Programming languages

    Types of structured programming languages.a) Pascal

    b) Structured !

    c) !obold) "ortran etc

    History of programming languages

    a. Machine languages

    !onsists of strings of digits or numbness that instructs the computer to perform acertain operation.

    b. ssembly language

    !lose machine language other than human language. They are symbolicrepresentation of machine code.

    c. High level language it close to human language or synta#. llows a problem to bespeci ed in a human understandable and oriented manner. The grammer of highlevel language is close to human vocabulary.

    P S! $ %&T'S( P !P" !# $%:&"$"

    1

  • 8/11/2019 PASCAL NOTES.doc

    2/52

    d. th generation language

    They are languages that allow the user of a program to *uery a database. Thesynta# of th generation languages is natural and user friendly. +ses menus toprompt a non,specialist to retrieve data with easy.

    e. - th generation languages

    These are languages that will allow program developed to mimic and copy humancharacters. Most of them are still under development. '.g. '#pert systems andrti cial intelligence.

    Programming paradigms

    a. Procedural programming

    t combines returning se*uences of statements into one program. procedurecall is used to invo/e the procedure to return one or more values.

    b. Modular programming

    The procedures of common functionalities are grouped together into separatemodules. The program is then divided into several smaller modules whichinteract through procedure calls and form a whole program.

    c. +nstructured programming

    programming techni*ue whereby statements in a program have a speci edarrangements of statements. global statement can be called from any part

    of a program.

    d. Structured programming

    Statements in a program are arranged and e#ecuted in a speci ed order. &nestatement after another are translated to machine code.

    e. &b0ect oriented programming

    Techni*ues where ob0ects communicate with one another while don1t /nowhow they are implemented.

    f. 'vent driven programming

    techni*ue where programs written respond to events.

    P S! $ %&T'S( P !P" !# $%:&"$"

    2

  • 8/11/2019 PASCAL NOTES.doc

    3/52

    g. Pseudo code

    This is an arti cial and informal language that helps programmers to developalgorithms. Pseudo code programs are not e#ecuted in the computer. Theyhelp a programmer to thin/ out a problem2program before attempting to writeon a computer programming language.

    Assignment Computer hardware and software consideration in structured programming.

    a) Hardware re*uirementsb) ppropriate operating system

    P O' "( #!)!*OP(!+T "+# #!SI'+

    Program development The process of formulating codes in a computer program. Program developmentinvolves coding a given tas/ in a programming language

    Program design The activity of progressing from a speci cation of some re*uired program to adescription of the program itself. The input to this phase is a speci cation of what theprogram is re*uired to do. 3uring the phase the design decisions are made as to howthe program will meet these re*uirements4 and the output of the phase is a descriptionof the program in some form that provides a suitable basis for subse*uent

    Characteristics of a good Pascal program . !larity 5obustness 5eliability '6cient

    Program development cyclec) Problem solving phase

    i. nalysis and speci cation

    +nderstand 7de ne the problem and what the problem must be.

    ii. 8eneral solutions7program)

    3evelop a logical se*uence of steps to be used to solve the problem.

    iii. 9erify

    "ollow the steps e#actly to see if the solution really does solve the problem.

    P S! $ %&T'S( P !P" !# $%:&"$"

    3

  • 8/11/2019 PASCAL NOTES.doc

    4/52

    d) mplementation phase

    i. speci cation solution

    Translate the algorithm into a programming language 7code).

    ii. TestHave the computer follow instructions and then chec/ the results. f yound errors4 analy:e the program and the algorithm to determine their

    source and then ma/e corrections.

    e) Maintenance phase

    i. +se the program. $et users use the program and see if it meets it needs.

    ii. Maintain

    Modify the program to meet changing needs from end,users4 or correct

    any routine errors that may show up in using it.

    Program design tools

    a, -low chart

    ;ow chart is a graphical method of designing programs. well,drawn ;ow chart isalso very easy to read since it basically uses 0ust two symbols4 two decision constructsand two iteration constructs.

    P S! $ %&T'S( P !P" !# $%:&"$"

    4

  • 8/11/2019 PASCAL NOTES.doc

    5/52

  • 8/11/2019 PASCAL NOTES.doc

    6/52

    !/ample!onstruct a ;ow chart that can be used to get the sum of two numbers.

    Some rules for 0ow charts

    a) 'very ;ow chart has a ST 5T symbol and a ST&P symbolb) The ;ow of se*uence is generally from the top of the page to the bottom of

    the page.

    c) +se arrow,heads on connectors where ;ow direction may not be obvious.

    d) There is only one ;ow chart per page

    e) page should have a page number and a title

    f) ;ow chart on one page should not brea/ and 0ump to another page

    g) ;ow chart should have no more than around =- symbols 7not includingST 5T and ST&P)

    , Pseudo code

    This is an arti cial and informal language that helps programmers to developalgorithms. Pseudo code programs are not e#ecuted in the computer. They help aprogrammer to thin/ out a problem2program before attempting to write on a

    P S! $ %&T'S( P !P" !# $%:&"$"

    6

    Start

    Enter values x and y

    Sum = x + y Sum

    Stop

  • 8/11/2019 PASCAL NOTES.doc

    7/52

  • 8/11/2019 PASCAL NOTES.doc

    8/52

    -. 'lse

    B 8ross pay ? pay rate times hours wor/ed plus overtime hours times overtime payrate

    E. 3isplay gross pay

    D. Halt

    d, #ecision ta les

    decision table is a tabular form that presents a set of conditions and theircorresponding actions.

    Condition Stu s!ondition stubs describe the conditions or factors that will aFect the decision orpolicy. They are listed in the upper section of the decision table.

    "ction Stu sction stubs describe4 in the form of statements4 the possible policy actions ordecisions. They are listed in the lower section of the decision table.

    ules5ules describe which actions are to be ta/en under a speci c combination of conditions. They are speci ed by rst inserting diFerent combinations of condition attribute values and then putting G s in the appropriate columns of theaction section of the table.

    #ecision Ta le (ethodology

    =. dentify !onditions I9alues

    "ind the data attribute each condition tests and all of theattribute s values.

    @. !ompute Ma# %umberof 5ules

    Multiply the number of values for each condition dataattribute by each other.

    A. dentify Possible ctions 3etermine each independent action to be ta/en for thedecision or policy.

    . 'nter ll Possible 5ules "ill in the values of the condition data attributes in eachnumbered rule column.-. 3e ne ctions for each5ule

    "or each rule4 mar/ the appropriate actions with an G in thedecision table.

    B. 9erify the Policy 5eview completed decision table with end,users.

    E. Simplify the Table 'liminate and2or consolidate rules to reduce the number of columns.

    P S! $ %&T'S( P !P" !# $%:&"$"

    8

  • 8/11/2019 PASCAL NOTES.doc

    9/52

    !/ample

    mar/eting company wishes to construct a decision table to decide how to treatclients according to three characteristics( 8ender4 !ity 3weller4 and ge group( underAC4 J between AC and BC4 ! over BC. The company has four products 4 G4 L and to

    test mar/et. Product will appeal to female city dwellers. Product G will appeal toyoung females. Product L will appeal to Male middle aged shoppers who do not live incities. Product will appeal to all but older females.

    1. Identify Conditions 6 )alues The three data attributes tested by the conditions in this problem are gender4 withvalues M and "N city dweller4 with value L and %N and age group4 with values 4 J4 and !as stated in the *uestion.

    3. Compute (a/imum +um er of ules

    The ma#imum number of rules is @ # @ # A ? =@7. Identify Possi le "ctions

    The four actions are( mar/et product 4 mar/et product G4 mar/et product L4 mar/etproduct .

    8. !nter "ll Possi le ules The top of the table would loo/ as follows( %ote that all combinations of values arepresent.

    The format9structure of a Pascal Program

    structure is the order in which programs statement in Pascal must follow. Jelow is thebasic structure that every Pascal program must follow.

    &ptional comments!omments address solely the readers of a program. They provide an overview of a program or one of its components. They also supply the e#tra information aboutwhy a program was constructed. !omments are enclosed in curly brac/ets O .!omments appear anywhere in the program other within a string constant.

    Header The header identi es the program and is terminated by a semicolon. The headermust ahave the name of the program. nd the speci cation on how to thisprogram interacts with the e#ternal data. '.g.

    Program sum input; output,< 3eclarations

    3escribes and identi es the ob0ects used by the program. '.g.

    )ar /; y; =: integer>>>>>>>>>>>>>>>>>1)Nf7input?1basic1) thenbeginriteln7Vbasic is not very hard to hard1)N'ndNf7input?1C1 then

    riteln7Vwrong password1)N'nd.!/ample 3Program e#ample@7input4output)N+S'S !5TN9ar maths4english4/iswa(integerN9ar sum(integerN9ar average(realNJegin!lrscrNriteln7Venter your mar/s1)N

    5eadln7maths4'nglish4/iswa)NSum(?mathsQ'nglishQ/iswaNverage(?sum2ANf 7averageU?DC) and 7average ?1=CC1) thenriteln7V 1)Nf7averageU?EC) and 7average ?EY) thenriteln7VJ1)Nf 7averageU?BC) and 7average ?BY) then

    P S! $ %&T'S( P !P" !# $%:&"$"

    24

  • 8/11/2019 PASCAL NOTES.doc

    25/52

    riteln7V!1)Nf 7averageU?-C) and 7average ?-Y) thenriteln7V31)Nf7averageU? C) and 7average ? Y) thenriteln7V 1)N

    f7averageU?=) and 7average ?AY) thenriteln7V'1)Nf 7averageU?1C1) thenriteln7VLou never sat for e#ams1)N'nd.

    The case...of Statementhen de ning an e#pression whose result would lead to a speci c program e#ecution4the case...of statement considers that result and e#ecutes a statement based on thepossible outcome of that e#pression. The diFerent outcomes are listed in the body of the case...of statement and each case has its own e#ecution4 if necessary.

    Case synta/ (Case #$pression o Case Choice%:Statement%"Case Choice&:Statement&"Case Choice-n:Statement-n"#nd'

    The e#pression to e#amine can be an integer4 a character4 an enumeration type4 or aprede ned list of items.

    !/ample1Program e#ample=7input4output)N+ses crtNvar %umber( ntegerNnswer( !harNJegin!lrscrNrite7 Type a number between = and A( )N

    5eadln7%umber)Ncase %umber of

    =( riteln7 Lou typed = )N@( riteln7 Lou typed @ )NA( riteln7 Lou typed A )N

    'lseriteln7Vyou entered an invalid numberX..1)NendN

    P S! $ %&T'S( P !P" !# $%:&"$"

    25

  • 8/11/2019 PASCAL NOTES.doc

    26/52

    rite7!hr7=C)4 Press any /ey to continue.................... )N5eadlnNend.

    Introduction to Pascal su programsSubprograms refer to any set of statements forming part of a program used to performa speci c tas/. They are instructions that are incorporated in the main program to dosome tas/ before passing control to the main program. properly constructedsubprogram should be self contained4 perform de ned operations on well de ned dataand have an internal structure that is independent of the program in which itscontained.

    Types of su programs

    -unctions

    function is an assignment that must be performed to complete a program. +nli/e aprocedure4 a function must return a value. self contained program structure that canbe called to do an operation and return a single value to nish e#ecution. ts referencedby specifying the name within the e#pression as though it was an ordinary simple typevariable. The function name can be be followed by one or more actual parametersenclosed in paranthesis and separated by commas

    Function s(nta$:

    P S! $ %&T'S( P !P" !# $%:&"$"

    26

  • 8/11/2019 PASCAL NOTES.doc

    27/52

    Function Function)ame: *eturn+(pe",egin

    #nd"

    "unction sum ( ntegerNbegin5esult (? =@-C Q DN

    endN

    "unction Perimeter( 3oubleNbegin

    endN

    The begin and end /eywords are re*uired because they would enclose the assignment

    performed by the function. Jetween the begin and end /eywords4 do whatever thefunction is supposed to do7instructions). fter performing the assignment for function4you must specify what value the function is returning. function can return a either of the following(

    " character:

    "unction ShowSome!haracter ( charNbegin

    5esult (? N

    endN "n integer (

    "unction %atural ( ntegerNbegin

    5esult (? @@DN

    endN " 0oating num er:

    "unction 3ecimal%umber ( 3oubleNbegin

    5esult (? [email protected]

    endN " $oolean value:

    "unction sMarried ( JooleanNbegin

    5esult (? trueN

    P S! $ %&T'S( P !P" !# $%:&"$"

    27

  • 8/11/2019 PASCAL NOTES.doc

    28/52

    endN " string:

    "unction !omplete%ame( stringNbegin

    5esult (? showed you mine. %ow show me yours NendN

    -unction call

    &nce a function e#ists or is /nown4 you can call it the same by simply typing its namewhere the function is needed. function returns a value and this can be any values of the dataytypes4 but the value must be the type stated by the 5eturnType word.

    Jecause a function returns a value4 it can be passed to a rite or a riteln procedureto display its return value.

    !/ample 1Program e#ample=7input4 output)N

    "unction ddition( ntegerNbeginaddition (? =@-C Q DNendNbeginriteln7 "ddition )Nend.

    Scope of varia les9ariables can be declared in function. These variables belong to the functions in which

    they are declared.

    *ocal varia les$ocal variables are accessed anywhere between begin and the matching end/eywords. These variables are only important inside the function.

    !/ample1

    P S! $ %&T'S( P !P" !# $%:&"$"

    28

  • 8/11/2019 PASCAL NOTES.doc

    29/52

    Program e#ample=7input4 output)N9ar #4y(integerN"unction additionN9ar answer(integerNJegin

    nswer(?#QyNriteln7VThe answer is( V4answer)N'ndNJeginriteln7VPlease enter the two numbers1)N5eadln7#4 y)NdditionN'nd.

    'lo al varia les Theses are variables declared for the entire programN that is within the bloc/ containing

    the function declaration. 8lobal variables can be utili:ed anywhere within the bloc/whether inside or e#ternal to the function.

    !/ample1Program e#ample=7input4output)N9ar n4p4m(integerN

    "unction ma#imumN9ar ma#(integerNJeginf nUp then ma#(?n else ma#(?pNf mU ma# then ma#(?m else ma#(?nNriteln7Vthe ma#imum is( V4ma#)N'ndNJegin5eadln7n4p4m)NJeginMa#imumN

    5eadln7n4p4m)N'ndN'nd.

    Procedures

    P S! $ %&T'S( P !P" !# $%:&"$"

    29

  • 8/11/2019 PASCAL NOTES.doc

    30/52

    self contained program structure that can be called to do an operation and return asingle value to nish e#ecution. The procedures ma/e the program easy to debug4understand and use. They also ma/e ;e#ible the use of parameters.

    Procedure structure

    rocedure compliment ,egin.riteln /statement0!".riteln /statement0!"#nd"

    procedure is referenced by its name followed by its optional parameters.

    !/ample1

    Program e#ample=7input4output)N9ar #4y4:(integerNProcedure largestN9ar ma#(integerNJeginf #Uy then ma#(?# else ma#(?yNf #(?ma# then ma#(?:Nriteln7Vthe highest is( V4ma#)N'ndNJegin5eadln7#4y4:)N

    Jegin$argestN'ndN'nd.

    !/ample1

    Program e#ample@7input4 output)N9ar #4y(integerNProcedure addition(integerN9ar answer(integerN

    Jeginnswer(?#QyNriteln7Vthe answer is( V4answer)N'ndNJeginriteln7Vplease enter the two numbers1)N5eadln7#4y)NdditionN

    P S! $ %&T'S( P !P" !# $%:&"$"

    30

  • 8/11/2019 PASCAL NOTES.doc

    31/52

    'nd.

    Parameter passingParameters are those variables that are used to hold data to be passed to the callingstatement or procedure. The process of transferring these parameters is called

    parameter passing. rguments are real or actual values passed to calling statement orprocedure.

    Types of parameters

    -ormal parameters These are labeled memory blan/ areas that are to be used to store values to be usedduring e#ecution. They are identi ers rather than reserved words.

    "ctual parameters These are variables that replace the formal parameters when the procedure or functionis called. They are given the actual parameter list of procedure call.

    Classes of parameters )alue parameters

    +sed to to supply information to the procedure but they cannot be used to getinformation out of a procedure. 9alue parameter are declared by including their namesand the corresponding datatypes within a procedure header without any pre # 9 5.

    e.g.program parameter7input4output)Nvar #4y(integerNvar :4m(integerNprocedure number7#(integerNy(real)NbeginendNbeginnumber7A4#R7:Qm)2yNnumner7@R7#Qy)4,C.-)Nend.%ote( # and y are value parameter in a procedure.

    )aria le parameter

    P S! $ %&T'S( P !P" !# $%:&"$"

    31

  • 8/11/2019 PASCAL NOTES.doc

    32/52

    +sed in applications where binformation must be transferred in both directions betweenthe procedure and procedure reference. hen the procedure containing a variableparameter is accessed the actual parameter in the procedure refernce is substituted bythe formal parameter within the procedure itself.

    "ssignment to students Procedure parameters

    -unction parameters

    #ata structures in structured programming These are variables that hold data two or more elements together instead of one sinleelement. tool for handling a group of logically related data items. They are userde ned and provide a method for pac/ing together data of diFerent typCes.

    Classi cation of data structures

    Static data structures These are data structures which don1t change when the program e#ecutes.

    3ynamic data structures. They are data structures that change when the program e#ecutes.

    Types of data structures

    1. "rrays This is a consecutive group of memory location that all have the same name anddatatype. This is a list of variables all with the same name and datatype.

    P S! $ %&T'S( P !P" !# $%:&"$"

    32

  • 8/11/2019 PASCAL NOTES.doc

    33/52

    hen we wor/ with a single item4 we only need to use one variable. However4 if we a list of items which are similar in type we need to declare an array of insteadof using a variable for each item variables.

    3eclaring arraysrrays are declared the same way we declare normal arrays e#cept that you have to

    say how many elements you have in the array.

    e.g.

    9ar #(arrayZ=..-[ of integerN

    9ar names(arrayZ=..=C[ of stringN

    One dimensional array 1# arrays ,

    This is an array that consists of one row.

    !/ample1 program that prints an array of ve names on the screen.Program array7input4output)N9ar names(arrayZ=..-[ of stringN9ar #(integerNJegin"or #(?= to =C do5eadln7namesZ#[)Nriteln7namesZ#[)N'nd.

    !/ample 3 program that prints an array of ten numbers on the screen.Program array7input4output)N9ar #(arrayZ=..=C[ of integerN9ar i(integerNJegin"or i(?= to - do5eadln7#Zi[)Nriteln7#Zi[)N'nd.

    P S! $ %&T'S( P !P" !# $%:&"$"

    33

  • 8/11/2019 PASCAL NOTES.doc

    34/52

    '#ampleA program that prints an array of ten numbers on screen and calculates their sum.Program arrays7input4output)N+ses crtN!onst students?-N

    9ar numbers(arrayZ=..-[ of integerN9ar total4count(integerN9ar average(realNJegin!lrscrN

    Total(?CN"or count(?= to students do5eadln7numbersZcount[)Nriteln7numbersZcount[)N

    Total(?totalQnumbersZcount[Nriteln7VThe total is V4total)N

    verage(?total2studentsNriteln7VThe average is V4average)N'nd.

    Two dimensional arrays 3# arrays, These are arrays that have both rows and columns.

    3eclaring two dimensional arrays

    +(pe multi = 1**12 3%''%45 %''%46 o integer"Var numbers:arra(3%''76 o integer"Var names:arra(3%''76 o integer"

    !/ample 1

    8iven the following mar/s achieved in a test4 and that the pass mar/ is the average of all the mar/s4 write a program to calculate the total mar/s4 average mar/s and list allthose students who have passed.

    "5'3 @= 8'&58' -B %%' -@ M 5L DY 5&J'5T E= $"5'3 E= !'! $ AA M K' - \'%% "'5 = P +$ %' D

    P S! $ %&T'S( P !P" !# $%:&"$"

    34

  • 8/11/2019 PASCAL NOTES.doc

    35/52

    Program e#ample=7input4 output)N+ses crtN!onst noofstudents ? =CN9ar names(arrayZ=..=C[ of stringNMar/s( arrayZ=..=C[ of integerN

    Total4 count( integerNverage( realNJegin!lrscrNnameZ=[ (? "5'3 N mar/sZ=[ (? @=NnameZ@[ (? 8'&58' N mar/sZ@[ (? -BNnameZA[ (? %%' N mar/sZA[ (? -@NnameZ [ (? M 5L N mar/sZ [ (? DYNnameZ-[ (? 5&J'5T N mar/sZ-[ (? E=Ntotal(? CNfor count(? = to noofstudents do

    total (? total Q mar/sZcount[Nwriteln7 The average mar/ was 4total)Naverage(?total 2 noofstudentsNwriteln7 The average mar/s is 4average)Nwriteln7 The students who passed the test are )Nfor count (? = to ma#students doif mar/Zcount[ U?-C thenwriteln7nameZcount[)NwritelnNend.

    Trees Trees these are hierarchal data structure constructed using rule of precedence for dataitems using alphabetical or numerical se*uence. The elements of a tree are callednodes and each element consists of a datum and at least two pointers.

    -B @ DY B- D

    -B is the rst datum placed the tree. ts node is therefore called parent node or root

    node. e add @ to the tree ne#t using rule of precedenceN lower number to the leftand higher number to the right.

    P S! $ %&T'S( P !P" !# $%:&"$"

    35

    e*t po#nter -atum #"'t po#nter

  • 8/11/2019 PASCAL NOTES.doc

    36/52

    DA!A!S This a chain of of data items in the computer memory awaiting e#ecution. ]ueues use

    " "&4 rst datum in is the rst datum out.

    !haracteristics of *ueues 3ata is entered to the end but removed from the front. The term " "& is used to describe *ueues because rst datum in is the rst

    datum out.

    P S! $ %&T'S( P !P" !# $%:&"$"

    36

    42

    Start

    56

    89

    1 48 1 1 65 1

    S

    BS

    ES

    ! S

    D

    "

    C

    E #

    $%

    /

    S

    S

  • 8/11/2019 PASCAL NOTES.doc

    37/52

    'ach data stays in the storage location until its turn comes thereby reducing timespent in data movement.

    ST"C&S They are used too temporarily store information or data. 5elated to *ueues but data is

    removed and added diFerently. 3ata is added at the top and removed from top using$ "&.

    %e#t removal pointer$ocation of address =C= =C@ =CA =C =C- =CB =CE =CD =CY ==C!ontents @C =Y =@ =B&rder of arrival = @ A -&rder of removal - A @ =

    Pointers

    These are variables that stores memory addresses. They point to a particular addressthat can be used to store data items. There are two types of pointers(

    Typed pointers They point to variables such as integers.

    Typed pointers They appoint to any type of variable.

    Typed pointers Lou declare typed pointers using in front of he variable type which you want to pointto. The ^ symbol can also be used in front of a variable to get its memory address. Thismemory address can be stored in a pointer because pointers store memory addresses.

    e.g.

    program pointersNvar #(integerNp( integerN

    beginp(?^iNend.

    f you change the value stored at the memory address pointed at by a pointer you mustrst deference the pointer variable using after the pointer name.

    e.g.

    P S! $ %&T'S( P !P" !# $%:&"$"

    37

  • 8/11/2019 PASCAL NOTES.doc

    38/52

    program pointersNvar i(integerNvar p( integerNbegin

    i(?=Np(?^iNp (?@Nwriteln7i)Nend.

    Lou can allocate new memory to a typed pointer using new command. The newcommand gets the memory that is the si:e of the variable type of the pointer and thensets the pointer to point to a memory address of it. hen you nish using the pointeruse dispose command to free the memory that was allocated to the pointer.

    Program pointersN9ar p( integerNJegin%ew7p)NP (?ANriteln7p )N3ispose7p)N'nd.

    Antyped pointers

    To declare the untyped pointers you must use the variable type called pinter. Toallocate memory to an untyped pointer you must use the 8etmem command instead of new command. Lou must also use "reemem command instead of dispose command tofree the memory. The 8etmem command have a second parameter which is the si:e inbytes of the amount of memory which must be allocated to the pointer. Lou can eitheruse a number for the si:e or si:efuction to get the si:e of a speci c variable type.

    e.g.

    program pointersN

    var p(pointerNbegingetmem7p4si:efunctionof7integer))Nfreemem7p4si:efunctioof7integer))Nend.

    *in4ed lists

    P S! $ %&T'S( P !P" !# $%:&"$"

    38

  • 8/11/2019 PASCAL NOTES.doc

    39/52

    -oes ot #,e a,es

    $ists are ;e#ible ways of handling data items in order. "or e#ample(

    "le/

    'ach word in the sentence is a data item4 which is lin/ed to the ne#t data item by apointer. 3atum plus a pointer ma/e a node or element of a list. The last item in the listis a terminator. This may be stored in an array of records. 'ach row of an array is oneelement in the list. start pointer saying where the rst datum is stored and a freestorage pointer saying where the ne#t datum can go.

    Start pointer

    "ree storagepointer

    Types of lin/ed lists Single lin/ed lists

    The element of the record has only one pointer.

    Head

    P S! $ %&T'S( P !P" !# $%:&"$"

    5& %& 3 T+M P& %T T& TH' %'GT %& !&MM'%T= _ $'GW @ %'GT 3T+M@ _3&'SW A %'GT 3T+MA _%&TW %'GT 3T+M

    _$ K'W - %'GT 3T+M- _! K'SW ,= $ ST 3T+MB 'MPTLE 'MPTL

    39

    .ddress 1 .ddress 2 .ddress 3

  • 8/11/2019 PASCAL NOTES.doc

    40/52

    3ouble lin/ed lists The element of the record has two pointers4 one pointer for giving the address of the following record another for giving the address of the proceeding record.

    Head

    !ircular lin/ed lists The pointer of the last record gives the address rst record thus this form acircular or ring of records.

    Introduction to Strings

    n order to understand strings4 one has to /eep in mind that a string is made up of anarray of characters. The string data type is an in,built data type that is an array of @-Bcharacters 7 Type String ? Pac4ed "rray ZC..@--[ of Char ). hen stored in memory4the processor should /now where the string starts and where it nishes. n order to/now where the string nishes4 in Pascal4 the Cth element of a string is de ned as thelength of the string. So4 if you try to access character C of a string4 the number of

    P S! $ %&T'S( P !P" !# $%:&"$"

    40

    .ddress 1 .ddress 2 .ddress 3

  • 8/11/2019 PASCAL NOTES.doc

    41/52

  • 8/11/2019 PASCAL NOTES.doc

    42/52

    Program e#ample=7input4output)N9ar S( StringNJegin

    S(? Hey there> How are you` N rite7 The word How is found at char inde# )N

    riteln7Pos7 How 4S))N f Pos7 hy 4S) ? C then riteln7 hy is not found. )N

    'nd.

    -unction Copy S : String< Inde/ : Integer< Count : Integer , : String< This function will copy some characters from string S starting from characterinde# Inde$ and copies as much as Count . The copied string is then returned.

    !/ample 1

    Program e#ample=7input4output)N9ar S ( StringNJegin

    S (? Hey there> How are you` N S (? !opy7S4 -4 B)N O there>

    rite7S)N'nd.

    Procedure #elete var S : String< Inde/ : Integer< Count : Integer , How are you` N 3elete7S4 4 )N OVHey> How are you`1 rite7S)N

    'nd.

    P S! $ %&T'S( P !P" !# $%:&"$"

    42

  • 8/11/2019 PASCAL NOTES.doc

    43/52

  • 8/11/2019 PASCAL NOTES.doc

    44/52

  • 8/11/2019 PASCAL NOTES.doc

    45/52

    !/ample 1

    Program e#ample=7input4 output)N9ar

    S( StringN 'rror( ntegerN 5( 5ealN

    Jegin S( ? ,C.-BA N

    9al7S4 54 error)N f 'rror U C then rite7 'rror in conversion. ) 'lse rite75)N

    'nd.

    P S! $ %&T'S( P !P" !# $%:&"$"

    45

  • 8/11/2019 PASCAL NOTES.doc

    46/52

    -I*!S H"+#*I+' I+ P"SC"* ST ACTA !# P O' "((I+'

    le is a collection of related records on some items of interest.

    -ile concepts

    Jit

    Jyte

    !haracter

    3ata7!ollection of characters)

    "ield

    7!ollection of data)

    5ecord7!ollection of elds)

    "ile7!ollection of related records)

    3atabase

    7Structured collection of les)

    "SSI'+(!+T TO TH! C*"SS'GP$ % TH' 9 5 &+S TLP'S &" " $'S +S'3 % !&MP+T'5.

    Types of les There are diFerent types of les(

    P S! $ %&T'S( P !P" !# $%:&"$"

    46

  • 8/11/2019 PASCAL NOTES.doc

    47/52

    Master le Transaction le Jac/up le Sort le 'tc

    -I*! O '"+IE"TIO+ T!CH+IDA!S These are the methods involved in storing les in a computer memory.O Fectives of le organi=ation

    ncrease processing speed 'asy accessibility To increase security of data "or easy references

    SeGuential le organi=ation

    "iles are arranged serially in a se*uence4 one after another. "iles are accessed inthe same order they were stored.

    "dvantages Simple to understand and follow 5elatively ine#pensive %o gap between the records Simple to create "ast to process data.

    #isadvantages %o bac/up facility Mandatory sorting 3ata redundancy is high $in/ing of records impossible

    andom le organi=ation There is no order in the storage of les. "iles are stored randomly in the memory.

    "dvantages 'asy to access les 'asy and *uic/ to update Sorting is not mandatory

    mmediate processing#isadvantages '#pensive %ot suitable for all storage media $ow speed 5e*uires special security measures

    P S! $ %&T'S( P !P" !# $%:&"$"

    47

  • 8/11/2019 PASCAL NOTES.doc

    48/52

    Inde/ed seGuential le organi=ation"iles are stored se*uentially but directly accessed using an inde#.

    "dvantages mmediate access %o need to sort the input "le#ible 'asy to update $in/ing of records is possible

    #isadvantages 5e*uires additional storage space. %o bac/up facility '#pensive

    -I*! #!SI'+ To create a le you rst declare a variable of that le. fter declaration you should

    assign the le a name using a command. To create an empty le use rewrite command. To read from an e#isting le we use reset command. +se readln to read lines of te#tfrom the le. Lou will also need to use while loop that repeats until it comes to the endof the le. ppend command is also used to let you add more te#t to the end of thele. +se close command to close a le when you have nished using it. +ses renamecommand to change the le name. "inally4 you can also use erase command to erasecommand to delete a le.

    Creating and writing to a te/t le

    !/ample 1

    Program te#t le7input4 output)N9ar "name4 t#t( stringZ=C[N+ser le(te#tNJegin"name(?1te#t le1Nssign7user le41c( 1Q"nameQ1.t#t1)N5ewrite7user le)Nriteln7user le41This is structured programming1)Nriteln7user le41 t is easy to learn and understand1)Nriteln7user le41 f you did not understand1)Nriteln7user le41Please send a mail to my inbo#1)N

    riteln7user le41/enny^yahoo.com1)N5eadln7t#t)Nriteln7user le411)Nriteln7user le41the user entered this te#t1)Nriteln7user le4t#t)N!lose7user le)'nd.

    P S! $ %&T'S( P !P" !# $%:&"$"

    48

  • 8/11/2019 PASCAL NOTES.doc

    49/52

    eading from a le!/ample 1

    Program leN9ar user le( te#tN

    "name( te#t le( stringNJeginriteln7V'nter the name of the le1QQ7with its full path)of the te#t le(1)N5eadln7"name)Nssign7user le4"nameQ1.te#t le1)N5eset7user le)N5epeat5eadln7user le4te#t le)Nriteln7te#t le)N+ntil '&"7user le)N!lose7user le)N

    5eadlnN'nd.

    Creating data les

    Program lesN Type studentrecords?record%ame( stringNdmno( integerN8ender( stringNge( integerN

    'ndN9ar student( te#tNStudents( studentrecordsNJeginssign7student41c( student.t#t1)N5ewrite7student)NStudents.name(?1\ohn Karani1NStudents.admno(?1=@A 1NStudents.gender(?1Male1NStudents.age(?@@Nriteln7Vname(?students.name1)N

    riteln7Vadmno(?students.admno1)Nriteln7Vgender(?students.gender1)Nriteln7Vage(?students.age1)Nriteln7students)N5eadlnN'nd.

    P O' "( #OCA(!+T"TIO+

    P S! $ %&T'S( P !P" !# $%:&"$"

    49

  • 8/11/2019 PASCAL NOTES.doc

    50/52

    Program documentation describes information that helps users4 managers and peopleinvolved that must interact with the system. '#plains the use and technical operationof the system.

    Importance of documentation

    5educes downtime costs. Speeds maintenance costs. Supports system users

    Types of program documentation System documentation

    3escribes system function and how they are implemented. This includes datadictionary4 ;owcharts4 data ;ow diagrams4 ob0ect oriented models4 screen layoutand source documents.

    &perational documentation!ontains all the information needed for processing and distributing online andprinted output. t includes( system analyst4 programmer and systemidenti cation. nput les4 scheduling information for printed output and emailsand report distributing lists.

    +ser documentation!onsists of instructions and information to the system end,users who will interactwith the system. t includes( user manuals4 help screens and tutorials.

    >riting a program documentation

    +ser manuals The styles and formats used in user manuals include the following.

    HeadingsMar/s he /ey contents$ists+se numbered and bulleted lists to help the user scan information *uic/ly.Special notices+se notices and warning to alert user to some potential problems.nstructional design+se standard design of instructions.8raphicsShows readers /ey components of the ob0ects they will be wor/ing with.

    Tables

    Provides statistical information and easy to access.Components of a user manual "ront and bac/ covers Title 'dition notice Trademar/s 3isclaimers.

    P S! $ %&T'S( P !P" !# $%:&"$"

    50

  • 8/11/2019 PASCAL NOTES.doc

    51/52

    arranties $icence agreements Safety notice Preface ppendices 8lossary nde#

    P S! $ %&T'S( P !P" !# $%:&"$"

    51

  • 8/11/2019 PASCAL NOTES.doc

    52/52