Program Turbo Pascal

Posted on by admin

Supplement to Turbo PascalSupplement to Turbo Pascal 7.0Samuel L. Marateck2.1 RUNNING TURBO PASCAL We begin with some definitions.

  1. Turbo Pascal For Windows
  2. Download Program Turbo Pascal

A set of information,be it a program or data, is called a file. A Pascal file name consists of the name,with up to 8 characters, followed by a period, and ending with an extension PAS.The file name is not case sensitive, so PROG1.PAS and prog1.pasare equivalent.2.2 OPENING (LOADING) A NEW PROGRAM Once you open TURBO PASCAL, the followingdisplay will appear on the screen.This is called the Integrated Development Environment, abbreviated IDE.;Position the mouse cursor on the the File menu and then click it. A pull-down menuwill appear.Keeping the mouse button depressed, move the mouse cursor to the Open.option (thisis called dragging the cursor) and release the button. A box requesting informationwill appear on the screen. This type of box is called a dialog box. This dialog boxis entitled Open a File. In a small rectangle at the top of this box,.PASappears with the cursor blinking beneath the asterisk.

Turbo Pascal For Windows

To create your own file, sayprog1.pas, type prog1. This will appear in this rectangle.

You do not haveto type the pas extension. Then either press the Enter key or click theOpen button. The dialog box will then disappear and PROG1.PAS will appear at thetop of the screen.

After you write your program, as shown here,you should save it on disk. To do this, either depress the F2 key or select Saveon the File menu. If you want to save your file on drive A:, when you name your program,type a:prog1. If you have already have opened the file as prog1.pas, youcan still save it on drive A: by selecting Save As on the File menu andtyping a:prog1 and then pressing Enter.Another definition: A directory; is a grouping of files on a disk. Thedirectory name is preceded by a slash.

A directory can be divided into subdirectories.Thus, TPBIN refers to the subdirectory BIN found in the directory TP.2.3 OPENING (LOADING) AN OLD PROGRAM; Select the Open option on the Filesmenu. Then, place the cursor in the Files rectangle appearing in the Open a Filedialog box, on the file name corresponding to the file name that you wish to open,here JOHNNY.PAS.When you click the mouse button, the file name will appear in the name rectangle.Then click the Open option (its also called a button) on the upper right of the dialogbox. The dialog box will disappear and the program you chose appears on the screen.2.4 RUNNING THE PROGRAM Place the mouse cursor on the Run menu and click it.A menu will open with the first option being.i. Run;(Ctrl-F9).Drag the mouse cursor to this option and release the button. If there is an error,correct it as described in section 3.12 (page 68) of the textbook.

If there are noerrors, your program will execute and the results will appear on the output screen.When execution is complete, the output screen disappears and your program will reappearon the screen. If you wish to see your output, either hit Alt and F5 or select theDebug menu and drag to the.i.User screen option, as shown inWhen you release the button, the IDE will dissappear and the output screen with youroutput will appear on the screen.To return to the IDE, hit any key or the mouse button.In order to see your output appear together with your program in the IDE, selectthe Debug menu and drag to the Output option. A window will appear at the bottomof your screen with your output in it. You may position that window anywhere on thescreen by placing the mouse cursor on the border of the output window, depressingthe mouse button and dragging the cursor to the desired spot on the screen and releasingthe button.

The output window will then appear there.If all of your output does not appear in the window, place the mouse cursor on thedown arrow on the right-hand border of the Output window and then click it. Thiswill scroll the screen downward. To scroll upward, place the mouse cursor on theup arrow on the right-hand border and click it.If you want to display another program on the IDE, select the Open option on theFile menu and choose the desired file name from the Files box.

When you open thefile, it will appear on a window which is on top of the window for the previous program.You may then run or edit the program. Each time you open another program, it willappear in a window on top of the previous window. To return to the program in theprevious window, click the green rectangle in brackets imbedded in the top left cornerof the window border.

Download Program Turbo Pascal

If you successively click the green rectangles in all the windows,all the windows will disappear, leaving a blue background on the screen.2.5 CHANGING THE DIRECTORY When you select the Open option on the File menu,only the files in one directory will be displayed. To change the directory, pulldown the Files menu and select Change dir. A dialog box entitled Change Directorywill appear containing a directory tree, as shown here.On the tree, click the C: (which represents the root, the parent of all the directoriesin the tree). This will highlight the C. Then click the Chdir button at the rightof the box. All the directories of the tree will appear.

Then click the desired directoryon the tree, and finally click the Chdir button. Now only the root and the selecteddirectory will appear in the tree. To execute this change, conclude by clicking theOK button. The new directory name will appear in the box entitled Directory name.Now when you choose the Open option in the Files menu, all of the file names in yourselected directory will appear.2.6 THE TILE DISPLAY The mode in which the programs are displayed, one abovethe other, is called the cascade mode. To have the windows containing the separateprograms displayed simultaneously, i.e., sharing the screen, click the Window menuand choose the Tile option. To see a list of all the programs displayed, choose theList option under the same menu.When more than one program is displayed on the screen, as is shown here, becauseyou have choosen the Tile option,the active one (here, PROGRAM1.PAS) has the cursor blinking in its window. To makeanother window active, place the mouse cursor there and click once.

PascalProgram Turbo Pascal

The active windowwill have a green arrow at its upper right hand corner. In order to get the windowto occupy the entire screen, click the green arrow.2.7 SEARCH AND REPLACE To find a string (or word) in your program, selectthe Search menu and drag the cursor to the Search option. A dialog box opens on thescreen and the cursor flashes in the Text to find box.

Type the word you wish tofind. It will appear in that box. After you type the word, do not hit the Enter key(if you do, the search will begin with the default options, the options indicatedwith the parenthesized dots).

Then position the cursor with the mouse on the optionsyou wish and click. For instance, to search the entire program for a given word,click the Whole words only and the Entire scope options. Finally, click the OK button.To replace a string, choose the Replace option. A dialog box opens with the cursorflashing in the Text to find box,however this time, the word you typed in the Find dialog box also appears here. Youmay, if you wish, change the word. Next position the cursor in the New text box andclick it.

Then type the word you wish to substitute and then with the mouse, clickthe options you want. The IDE assumes you wish to be prompted for each replacement,so an X is marked for the Prompt on replacement option.

To override this option,click this X. Finally, click the OK box.

The system then replaces the first occurenceof the selected word. To replace additional occurrences of the word, select the Searchagain option. If you wish to replace all occurrences of a word, click the Replaceall button.2.8 EDITING (See also section C3, page 847 of the textbook for keyboard editingcommands.) To select a block of text to move, copy or erase, click the beginningof the block of text and drag the cursor to the end of the block. The block of textwill be highlighted, as shown here.Select the Edit menu. If you want to copy the block to another place in the program,drag to the Copy option.

The block will then be copied to what is called the clipboard(to see it, choose the Show clipboard option on the Edit menu; to return to yourprogram, click the green spot at the upper left of the window).Then, position the cursor to the place where you want to copy to, and then drag tothe Paste option on the Edit menu. The block will then appear in its original positionand the copied position.

To simply move it from its original position to the desireddestination, drag to the Cut option instead of the Copy option, and then after positioningthe cursor to the desired destination, choose the Paste option. To erase a block,just cut it. To cancel an operation immediately after its performed, select the Undooption.2.9 DEBUGGING To see the values asigned to a variable as execution progresses,place the cursor on the variable. Then click the Debug menu and drag to the Add watchoption. A dialog box entitled Add watch appears on the screen and the variable chosen,here one, will appear in a rectangle labled Watch expression., as shown here,Then click the OK button.

If the proper variable does not appear in the box, typeit. The variable will appear on the bottom of the screen in a window entitled Watches.If it does not, select the Watch option on the Debug menu and the Watch window willappear.Since the program hasn't been executed, the variable appearing in the window is describedas an unknown identifier.To add more watch variables to the watch window, repeat the process by selectingthe Add watch option. To trace the steps in your program, continuously hit the F7key.

Turbo

As you do this, the statement being executed will be highlighted in the programwindow, and the the variable's value at that statement will appear at the variable'sright in the Watches window. We see in the following that the value of one is 23.If you do not want to trace the statements in a procedure, hit the F8 key insteadof the F7 key when the procedure call is highlighted.To start the trace at a given statement in the program, position the cursor to thatstatement and then hit the F4 key. To stop a trace press Ctrl-F2.

For more informationon using the Watch window, see page 194 in the textbook for tracing the value ofvariables, page 456 for tracing arrays, and page 634 for tracing records.Breakpoints. To see the values of the watch variables at certain points in the program,position the cursor on the statement of interest and press Ctrl-F8. The statement,called a breakpoint will be highlighted in red. You may select up to 20 breakpointsin the program. To see the values of the watch variables at the first breakpoint,press Ctrl-F9 and the program will execute until the first breakpoint. If the watchwindow is not displayed, choose the Watch option on the Debug menu. Each time youpress Ctrl-F9, the program wil execute to the next breakpoint.

To see where all thebreak points are, choose the Breakpoints option on the Debug menu and a window willappear. To erase all breakpoints, click the Clear all button in this window. Allbreakpoints should be cleared before the next program is executed.Erasing variables from the Watch window.

To erase a variable from the Watch window,select the window by clicking the mouse button. Next click the variable to be erasedand it will be highlighted. Then hit the Del key. To clear all the watch variablesfrom the window, select the Close option on the Window menu. This will also erasethe watch window. To erase all the variables from the watch window without erasingthe window itself, hit Alt-F10 while the watch window is selected. A pop-up menuwill appear, as indicated here.Select the Clear all option, and then select the OK button on the Confirmation dialogbox.

If another window is active, for instance a program window or output window,hitting Alt-F10 will produce a pop-up menu dedicated to the active window.2.10 PRINTINGTo print your program, select Print on the File menu. To print an image of what ison the screen, including any windows that are open, hit the PrScr key (print screen).You should use this last technique to print your output, after you have made theoutput window cover the entire screen (click the green arrow for this). See page138 of the textbook for another way of printing output.2.11 REDIRECTING THE INPUT AND OUTPUT FILESIts possible to substitute files for the standard input from the keyboard and outputto the screen. This is called redirection of input and output. Redirecting inputallows you write your data only once and use it for several versions of your program.On the other hand, if your output fills several screenfulls and you therefore can'tprint it using the PrtSc key, redirecting output allows you to print all your outputon a file and then print the file. It also allows you to print your output on a fileand use that file as input to another program.Redirecting input/output can be done without changing your program if you are notusing the CRT unit (if you are, please see the next section). First, you must compileyour program to disk as described on page 92 of the textbook in Saving the CompiledVersion of a program, by:1.

Selecting the Destination option on the Compile menu until Disk is displayed.2. Selecting the Compile option on the Compile menu and your program will be savedas a file with the extension EXE on the disk selected. For instance if you call yourprogram prog1, it will be saved as prog1.exe. To see which directory this file issaved, select Directories on the Options menu. To the right of EXE & TPU directorywill be displayed the desired directory.To redirect the input file:1. Write your data using the IDE with each line of data written in the same way younormally would write data for you program. Then save it in a file with the extensiontxt, for instance, to differentiate it from a pas file.

For example you might saveyour data as data1.txt2. Save this data file by hitting the F2 key.3. Exit from Turbo Pascal and at the DOS prompt write prog1 out1 at the DOS prompt.

All of you output will be written tothe file out1 instead of to the printer. If you run the program again with, say,different input, the original contents of out1 will be erased and the new outputprinted to out1. Note that all the output, even the message you use to prompt theuser will be written to the file. So you will have to remember what the prompts arein order to run your program.To redirect both the input and output files:1. Type prog1 out1.

Your program will then take its input fromdata1.txt and write its output to out1.2.12 REDIRECTING THE INPUT AND OUTPUT FILES WHEN USING THE CRT UNIT.If you are using the CRT unit in your program, you cannot redirect input unless youassign the null string to the input file and reset it as described on page 372 ofthe textbook. To redirect the output file, writeassign(output, ');rewrite(output).