15

апр

Contoh Program Procedure Dan Function Pada Pascal

Posted: 
Contoh program procedure dan function pada pascal and wife

8:37Modular programming FUNGSI DAN PROSEDUR 9:10FUNGSI DAN PROSEDUR Membuat. Feb 12, 2011  Baik kali ini kita masuk kebagian procedure dan fungsi di pascal. Tapi sebelum membahas lebih jauh kita kenali dulu kira-kira apa sih perbedaan procedure dan fungsi di pascal. Perbedaannya yaitu. Prosedur diawali dengan dengan kata procedure untuk mendeklarasikannya contoh: procedure hitung_angka; kalau fungsi di awali dengan kata function.

A, b: integer; c: integer; d, e: string; f: real; g: extended; h, i, j, k: byte; l, m, n, o: byte; Basic numeric types include: longint (32-bit, hardware dependent), integer (16-bit, hardware dependent), shortint (8-bit). Their unsigned counterparts are cardinal (available only in some versions of Pascal), word, byte. Decimal numbers are supported using the real type, and the extended type (available only in some versions of Pascal) Other types include the char (for holding characters), the string (as its name suggests).

(For now, arrays, pointers, types and records will be covered in a later chapter) Functions/Procedures [ ] Before we begin, let us first clarify the key difference between functions and procedures. A procedure is set of instructions to be executed, with no return value. A function is a procedure with a return value. For readers familiar with C/C++, a procedure is simply a function with a void return value, as in void proc_sayhello(). The definition of function/procedures is thus as such.

Function Add ( A, B: Integer ): Integer; Forward; Function Bad ( A, B, C: Integer ): Integer; Begin Bad:= Add ( Add ( A, B ), C ); End; Function Add ( A, B: Integer ): Integer; Begin Add:= A + B; End; In this example, Add is first defined as a function taking two integer variables and returning an integer, but it is defined as a forward definition (prototype), and thus no body is written. Later, we see that Add is defined with a body. Note that the two definitions of Add must be congruent with each other, or the compiler will complain. From the above example, we can also gather that in Pascal, a function's return value is given by the value of the variable with the function's name (or by the variable named result), when the function returns.

Gt reittikartta suomi pro.tutustu tarkemmin. Timbernavi.m.suomi sujuvaksi.djvu 5.20 mb kenttala m.suomi sujuvaksi 2.genimap.gt reittikartta suomi pro on tehty. Gt reittikartta suomi pro 2013 reviews.

Contoh Program Procedure Dan Function Pada Pascal

As you can see in the Bad function, an undefined variable named 'Bad' has been assigned a value. That is the return value for the Bad function. Similarly, in Add, the variable named 'Add' has been assigned a value, which is its return value. Note that unlike C or other languages, assigning a return value to a function does not return from the function. Thus, the function will continue executing, as in the following example. Function Weird ( A: Integer ): Integer; Var S: Integer; Begin S:= A / 2; If S = 10 Then Weird:= 0; Weird:= 2; End; If A happens to be 6, the function will not return the expected result of 1 or even 0. Instead, it would return a result of 2, because the function to execute continues even after the return value is set.

In fact, as you would notice, the function would return 2 all the time because it runs all the way to the end, at which the return value is set to 2. To mimic C style function returns, the exit statement must be used.

The exit statement in Pascal, unlike C, exits from the current block of code (in this case, the function), and NOT from the program. The code would then look like this.

Most of the softwares you write need implementing some form of date functions returning current date and time. Dates are so much part of everyday life that it becomes easy to work with them without thinking. Pascal also provides powerful tools for date arithmetic that makes manipulating dates easy. However, the actual name and workings of these functions are different for different compilers. Boston market employee handbook. Getting the Current Date & Time Pascal's TimeToString function gives you the current time in a colon(: ) delimited form.

The following example shows how to get the current time − program TimeDemo; uses sysutils; begin writeln ('Current time: ',TimeToStr(Time)); end. When the above code was compiled and executed, it produces the following result − Current time: 18:33:08 The Date function returns the current date in TDateTime format. The TDateTime is a double value, which needs some decoding and formatting.

The following program demonstrates how to use it in your program to display the current date − Program DateDemo; uses sysutils; var YY,MM,DD: Word; begin writeln ('Date: ',Date); DeCodeDate (Date,YY,MM,DD); writeln (format ('Today is (DD/MM/YY):%d/%d/%d ',[dd,mm,yy])); end. When the above code was compiled and executed, it produces the following result − Date: 4.00000E+004 Today is (DD/MM/YY):23/7/2012 The Now function returns the current date and time − Program DatenTimeDemo; uses sysutils; begin writeln ('Date and Time at the time of writing: ',DateTimeToStr(Now)); end. When the above code was compiled and executed, it produces the following result − Date and Time at the time of writing: 23/7/2012 18:51: Free Pascal provides a simple time stamp structure named TTimeStamp, which has the following format − type TTimeStamp = record Time: Integer; Date: Integer; end; Various Date & Time Functions Free Pascal provides the following date and time functions − Sr.No. Function Name & Description 1 function DateTimeToFileDate(DateTime: TDateTime):LongInt; Converts DateTime type to file date.

Popular Posts