Anda di halaman 1dari 8

STANDAR KOMPETENSI : Mengenal bahasa pemrograman MATERI : menggunakan menu yang disediakan suatu editor bahasa pemrograman Program

adalah instruksi-instruksi yang diberikan ke komputer agar komputer dapat melaksanakan tugas-tugas tertentu, sebuah program berisi sekumpulan kode dan kode-kode yang digunakan tergantung pada bahasa pemrograman yang dipakai, contoh program diantaranya adalah : games ( catur, MagicLine,Vcoop, dll), aplikasi dokumen (Ws, Ms Word, WordPad, dll), dan lain-lain. Bahasa Pemrograman merupakan perangkat lunak komputer yang digunakan untuk membuat program sehingga program begitu mudah dibuat. Pada dasarnya ada 2 (dua) golongan bahasa pemrograman komputer : 1. Bahasa pemrograman tingkat rendah ( low level language ) - Bahasa mesin - Bahasa rakitan 2. Bahasa pemrograman tingkat tinggi ( high level language ) Berorientasi pada bahasa yang mudah dipahami oleh manusia, contohnya : Turbo Pascal, Basic, Visual Basic, Borland Delphi, Fox Pro, dll. Tetapi yang akan dibahas dalam buku ini adalah bahasa pemrograman TURBO PASCAL. Tampilan bahasa pemrograman Turbo Pascal ver 1.5 for Windows

Gambar. Tampilan Turbo Pacal for Windows MATERI : Memulai bekerja dengan bahasa pemrograman Terdapat 2 (dua) cara atau metode untuk menggunakan atau menjalankan aplikasi Turbo Pascal for Win ini, yaitu : 1. Untuk sistem operasi Windows XP, klik tombol START kemudian masuk ke ALL PROGRAM dan pilih TPW 1.5 dan program akan langsung dieksekusi.

2. Untuk method yang ke-2, kita harus mencari file executablenya yaitu file TPW.EXE dari drive C:\TPW dan bisa langsung didouble klik untuk membuka aplikasi pascal.

In particular, note the Edit Window. If you opened Turbo Pascal by double-clicking on a .pas file, the contents of that file will appear here (as in the example above). Some of the other features of the Turbo Pascal development environment are described below: Menu Bar The Menu Bar is how you will access most of the functions of Turbo Pascal. You can send various commands to Turbo Pascal by clicking once on one of the words in the Menu Bar. This will pull down a menu that you can select commands from. Do this: 1. Pull down the "Help" menu (by clicking on it). 2. Select "About Turbo Pascal." A window, like the one on the left, should appear. 3. Click on the "OK" button in the window to close it.

Speed Bar The Speed Bar (Button Bar) provides short cuts to commonly used functions in Turbo Pascal. Instead of moving the mouse all the way to a pull-down menu and then making a selection, the speed bar is a simple one-click process. Here are what each speed button does: Turbo Pascal Help Open a file Save a file Find a piece of text Find again Cut a highlighted piece of text and place it on the clipboard Copy a highlighted piece of text and place the copy on the clipboard Paste text from the clipboard to where the cursor is. Undo the last action Send the current file to the compiler.

Turbo Pascal Desktop The desktop inside Turbo Pascal is similar to the desktop provided in the Program Manager or Windows NT itself. You can have several editing windows open at the same time, but only one is active (or in the foreground). If this is your first time opening Turbo Pascal, then you should have two edit windows open, but you will only see the first one, titled "c:\tpw\windemo\dirdemo.pas". Move this edit window so you can see the edit window beneath it, titled c:\tpw\welcome.pas". (See Below).

Notice how the title bar for edit window "dirdemo.pas" is a dark blue and the entire edit window it is in the foreground. This indicates that it is the active edit window. All commands, such as cut and paste, and compilations, are performed on the active edit window. You can switch between the active and the inactive edit windows but clicking once on the title bar of the edit window you want to become active. Do this: Practice switching between the "dirdemo.pas" edit window and the "welcome.pas" edit window, by clicking on their title bars. Edit windows can also be iconified. If you click on the iconify button, the edit window will become an icon, usually on the lower left of the Turbo Pascal desktop

(as in the picture to the left). The icon can be brought back into a full edit window by double-clicking on the icon. Compiler Error This section of the Turbo Pascal window is where the description of compiling errors will appear. Examples of error messages will be shown later in the tutorial. Right now, all you need to know is its location. Edit Style There are two ways of entering text in the middle of a line. Either you text to the left of the cursor and "push" the rest of the line to the right, or you the characters to the right of the cursor. Use the "Insert" key on your keyboard to switch between the two. File Status This area indicates if the current file has been changed since the last save. If it is empty then the file does not need to be saved. If the area has in it, then changes have been made and you probably want to save the file soon. Cursor Position This indicates where the edit cursor is. The first number is the line number, the second is the column number. For example indicates that the cursor is 118 lines from the top, and 33 characters from the left side. MATERIAL : Introducting with the basic elements on Turbo Pascal Example the simple program :

1. Head of Program Pada contoh di atas baris yang berisi : PROGRAM Lat1; Is used to identity the program and optional function . u can remove the command without change the output program. The other word, program can be write : BEGIN Writeln (Selamat belajar dan mencona Turbo Pascal); END. 2. Begin End

Dalam program akan banyak dijumpai pasangan : BEGIN END. Didalam program Pascal minimal mengandung sebuah BEGIN END dengan bentuk BEGIN pernyataan-pernyataan END. END yang diakhiri dengan tanda titik (.) Menunjukan akhir dari program. 3. Pernyataan Adalah perintah yang menyebabkan komputer melakukan suatu tindakan. Pernyataan merupkan bagian yang terdapat di dalam : BEGIN END Sebagai contoh berikut : PROGRAM Lat2; BEGIN Writeln (Selamat belajar dan mencoba); Writeln (Turbo Pascal); END Tanda titik koma (;) dipakai sebagai pemisah dua buah pernyataan dan bukan sebagai pengakhir pernyataan dan harus ada, diantaranya : - di akhir kepala program - di akhir setiap pendeklarasian konstanta - di akhir setiap pendeklarasian variabel - di Akhir pernyataan-pernyataan yang terletak di dalam BEGIN END

Examining a Simple Working Program


We will begin by looking at a program that already works, and seeing how Turbo Pascal handles various aspects of it. We will be using the "welcome.pas" program that should be loaded into an edit window when you open up Turbo Pascal for the first time. You may have to move, iconify, or close the other "dirdemo.pas" edit window in order to locate it. If "welcome.pas" is not in the window, or if you have closed it, see Opening welcome.pas to find out how to open it again. Take a look at welcome.pas. The first line is the standard Pascal opening line. It has program and a name , that name being Welcome. Notice how program is in bold. This is because it is a reserved word in Pascal (meaning that this word in Pascal has a special meaning and should only be used for its designated purpose). Turbo Pascal puts all reserved words in bold.

Modifying a Simple Working Program


Do this: 1. Delete the "p" out of program. The remaining word "rogram" is not a reserved word, so the bold disappears. 2. Replace the "p" in program. The next line is a "uses WinCrt" statement. Most of the programs you will be writing will need this line. This statement allows your program's output to appear in a window, as well as allowing input from that window to be read by your program. The next lines are comments. Turbo Pascal italicizes comments in blue. The comments here describe more about what "uses WinCrt" does. (Do not try to run the program as indicated in the comments yet). It is not necessary that you understand all of what is said in these comments. Do this: 1. Move the cursor down the screen (using the arrow keys) until the entire program (ending in "end.") is displayed. 2. Delete the closing bracket for the comment (it is the curly bracket "}" after Guide.) Notice how the program is now in italic blue. This is because the comment is not closed. 3. Put the "}" back to properly close the comment. Examine the program. The program is between the "begin" and "end" statements. The program only contains one line. The writeln statement will print out its contents to the screen. In this case the contents are the string, "Welcome to Turbo Pascal for Windows." You will notice that the string is in blue. All constants (constants are numbers and strings) will be highlighted like this. Do this: 1. Move the cursor to the writeln statement and remove the first ' (So that it reads writeln(Welcome..). The string is no longer blue (and "to" and "for" become bold because they are reserved words). A text string must be between a set of single quotes ('). This is because Pascal is written in characters; in order for Pascal to distinguish between a Pascal statement and a string of characters the, quotes are used. 2. Replace the ' at the start of Welcome.

Try to compile the program. There are 2 methods: Do either of these: Method 1: Pull down the Compile window and choose "Compile" Method 2: Press the Atl and F9 keys, at the same time. What should happen is that an error window, such as one on the left should open.

To understand why this error occurred and how to fix it, go directly to the Saving your Turbo Pascal File.

To save "welcome.pas" on your H: drive:


Do this: 1. Pull down the file menu and select "Save As..." 2. When the File Save As window is opened, look at the Directories area. Use the scroll bar to scroll down to the list of disk drives (disk drives are indicated by [-x-], where X can be any letter, as seen by the figure on the left). Double click on the [-h-] drive. 3. If the Path is "h:\windows" the double click on the [..] selection at the top of the Directory listing. 4. When the Path is "h:\" and the Name is "welcome.pas" click on the Ok button.

ow that we have "welcome.pas" saved, we can proceed to actually compiling a program.

Compiling is where a Turbo Pascal compiler takes the code you have written, and translates it into a machine language that it can execute. When you compile a program. You are asking the computer to translate the Pascal code into a machine language, or set of commands, that the computer can execute directly. The file that contains the compiled code is called an executable file, because this code can be run or executed directly by the computer. Compile "welcome.pas" by one of two methods: Do either: Method 1: Pull down the Compile window, and select Compile. Method 2: Press the Alt and F9 Keys at the same time. At this point a "Compile Status" window, like the one to the left, should open. Compile Status Sections Status Tells you if your program is being compiled, has an error, or if it compiled successfully. In the case of "welcome.pas" it should compile successfully. Files Tells the status of the various files you are compiling Main Most of the program you write for your first year course will consist of only one file, known as the main file. The first part of the name of the main file, will be used as the name for the executable file. So if the main was, "Welcome.pas" then the executable file would be, "Welcome.exe". Current The file that Turbo Pascal is compiling at the moment. More complex programs might be split up among several files. For most first year courses you will not create programs that require more then one file. Statistics This shows you the progress of the compiler through your Pascal program. For small files like "welcome.pas" you will not see the progress. For large files you would. When you are compiling you might get the error to the left. This means that you are over your disk quota. See Problems with Disk Quota in the previous section of the manual titled "Problems with Saving a Turbo Pascal File". If you have compiled and executed your program previously, you may get this error. See Problems with Compiling

Anda mungkin juga menyukai