Introduction to DOS Environment dir - lists the files in a directory dir a: - lists the files in the "a" directory copy - copies a file from one place to another erase - erases a file del - deletes a file (same as erase) move - relocates a file from one directory to another deltree - deletes every file in a directory type - types the contents of a file cd - change directory mkdir - creates a directory rmdir - removes a directory (if empty) diskcopy - image copies the contents of a disk format - (re)formats a disk drive Introduction to Turbo Environment Hot Keys turbo7 - starts turbo 7 environment F10 - returns you to the main screen - closes open window F10 - make the main menu the active window menuletter - opens the menu for that letter (alt-f: file menu) d - scroll right x - scroll down e - scroll up s - scroll left v - paste (insert) F9 - compile program q w - redisplays error messages F9 - run program F5 - switches you between user and environment screens Program Development Components: Hardware versus Software. Natural language versus programming language versus machine language, and the role of compilers. What is an algorithm? Set of instructions, recipes, directions, method, routine. Partial and total algorithms. I/O and data. Examples. What are the five phases of program development? Analysis, design, implementation, coding, maintenance Pascal language origin. Designed by Niklaus Wirth as a teaching language. Differences between Standard Pascal and Turbo. Named after Blaise Pascal, famous mathematician, engineer and scientist. Constants in Pascal pi := 3.14159; star := '*'; Variables in Pascal Four properties: label or identifier, data type, value, and location Identifiers: Must start with a letter. May only contain alpha numeric characters or the underscore Max length of 63 not case-sensitive cannot be reserved words Data Types: Integer, Real, Char, String, Boolean, Array, Record, Enumerated, Pointers, Linked Lists, Stacks, Queues, Matrices, Literals Values: The valid set of data that a variable can hold. Location: Where the data is stored. Operators in Pascal assignment {:=} arithmetic {*, +, -, / , div, mod, unary +, unary -} relational {<,>,<=, >=, =, <>, in} logical {and, or, not} set {=, -, *} LEARN ABOUT operator precedence. Standard Functions in Pascal abs(x) absolute value of x exp(x) value of "e" (2.71828) raised to the power of x ln(x) logarithm (to the base of e) of x sqr(x) x squared sqrt(x) square root of x round(x) closest integer value of x trunc(x) integral part of x arctan arc tangent of x cos(x) cosine of x sin(x) sine of x chr(x) given an integer, returns the character whose ordinal number is x odd(x) given an integer, returns a boolean value indicating whether x is odd or not ord(x) given an ordinal, returns the integer value of x pred(x) returns the predecessor of x succ(x) returns the successor of x Standard Procedures in Pascal Dispose (p) Get (f) New (p) Pack (u, i, p) Page(f) Put (f) Read (f, variables) Readln (f, variables) Reset (f) Rewrite(f) Unpack ( u, i, p) Write (f, outputs) Writeln (f, outputs) where: f=file, p=pointer, u=unpacked array, i=index Comments in Pascal {This is a comment} (*This is a comment too*) {This is a multi-line comment} LEARN how to handle single quotes within a string Standard Pascal Program Format Program Hello; (************************************************************************) (*Author: Maysa Peterson *) (*Date: Aug 22, 1997 *) (*Class: Pascal 2210 Section 0007 *) (************************************************************************) (* This program takes as input, the users name and year of birth. *) (* As output it greets *) (* the user as in the simple "hello world" and tells him about *) (* how old he is. *) (************************************************************************) Const Message= 'Hello There'; {standard message} Year= 1997; {the current year} Var FirstName, LastName: string;{input variables for the user's name} BirthYear, Age: integer; {input var. for birth year, calculated age} Begin (******************************************************************) (* First initialize variable *) (******************************************************************) BirthYear, Age:= 0; {initializing variables} FirstName, LastName:= ''; (******************************************************************) (* Next Accept Input *) (******************************************************************) Write('What is your first and last name?);{prompt for input - name vars.} Writeln; Read(FirstName, LastName); {read in values} Readln; Write('What year were you born in ?'); {prompt for input - birth year} Writeln; Read('BirthYear'); {read in values} Readln; (******************************************************************) (* Second Step: Process Input *) (******************************************************************) Age:= Year - BirthYear; {calculate age estimate} (******************************************************************) (* Final Step: Prepare and print output *) (******************************************************************) Write (Message); Write(' ', FirstName, ' ', LastName); Writeln; Write('You are about '); Write(Age); Write(' years old!'); Writeln; Writeln('Welcome.'); End. EXAMPLE TWO: Program Hello; Const Message= 'Hello There'; {standard message} Year= 1997; {the current year} Var FirstName, LastName: string; {input variables for the user's name} BirthYear, Age: integer; {input var. for birth year, calculated age} Error: boolean; {flag to indicate erroneous input} Begin BirthYear, Age:= 0; {initializing variables} FirstName, LastName:= ''; Error = false; Write('What is your first and last name?); {prompt for input - name vars.} Writeln; Read(FirstName, LastName); {read in values} Readln; Write('What year were you born in ?'); {prompt for input - birth year} Writeln; Read('BirthYear'); {read in values} Readln; If BirthYear < Year Then Begin Age:= Year - BirthYear; {calculate age estimate} End; If BirthYear >= Year Then Begin Error:= true; End; Write (Message:12); Write (FirstName:10, LastName); Writeln; If NOT Error Then Begin Write('You are about '); Write(Age); Write(' years old!'); Writeln; End; Else Begin Write('I would estimate your age, if you gave me a correct year!'); Writeln; End; Writeln('Welcome!'); End.