![]() For example: unit calculateArea įollowing are three important steps in creating a Pascal unit: The first line of this file should start with the keyword unit followed by the name of the unit. To create a unit, you need to write the modules, or subprograms you want to store in it and save it in a file with. It is the same program we used right at the beginning of the Pascal tutorial, compile and run it to find the effects of the change. Gotoxy ( 20, 7 ) write ( 'Enter c: ' ) readln (c ) Īrea : = sqrt (s * (s - a ) * (s -b ) * (s -c ) ) Gotoxy ( 20, 5 ) write ( 'Enter b:' ) readln (b ) Gotoxy ( 20, 3 ) write ( 'Enter a: ' ) readln (a ) Gotoxy ( 30, 4 ) (* takes the pointer to the 4th line and30th column *) writeln ( 'This program calculates area of a triangle:' ) writeln ( 'Area = area = sqrt(s(s-a)(s-b)(s-c))' ) writeln ( 'S stands for semi-perimeter' ) writeln ( 'a, b, c are sides of the triangle' ) writeln ( 'Press any key when you are ready' ) Textcolor (green ) (* text color is green *) Textbackground (white ) (* gives a white background *) The following example illustrates using the crt unit: Program Calculate_Area (input, output ) uses crt var However, let us first see how to include a built-in unit crt in your program: program myprog uses crt This tutorial explains creating and including user-defined units. We have already used the variants unit in the Pascal - Variants tutorial. There are many built-in units in Pascal and Pascal allows programmers to define and write their own units to be used later in various programs.īoth the built-in units and user defined units are included in a program by the uses clause. A unit might consist of some code blocks which in turn are made up of variables and type declarations, statements, procedures etc. A Pascal program can consist of modules called units. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |