News and changes related to this release are described in whatsnew.txt. There is also partial support for the Macintosh pascal dialect. The language and the runtime library are almost compatible with Turbo Pascal 7.0 and recent Delphi releases. String capacity is omitted and thus set to 255 by default. This package contains an advanced freeware 32-bit/64-bit/16-bit pascal compiler for several platforms. ord returns ASCII-code of a character, while chr converts given ASCII-code into a character. This example processes the string char by char, and works with ASCII-codes to figure out whether they are lower- or uppercase letters. Program Camelcase var text, cc : string c : char i : integer lastSpace : boolean upper, lower : set of char begin upper := lower := readln ( text ) lastSpace := true cc := '' for i := 1 to Length ( text ) do begin c := text if ( c in lower ) or ( c in upper ) then begin if ( lastSpace ) then if ( c in upper ) then c := chr ( ord ( c ) + 32 ) cc := cc + c lastSpace := false end else lastSpace := true end writeln ( cc ) end. Note that in Turbo Pascal series this program works only with Turbo Pascal 4.0 and higher due to the fact that earlier versions didn’t have char datatype. This example is similar to previous one, but uses sets of characters for letter check. Program Quadratic var A, B, C, D : integer begin write ( 'A = ' ) readln ( A ) if ( A = 0 ) then begin writeln ( 'Not a quadratic equation.' ) halt end write ( 'B = ' ) readln ( B ) write ( 'C = ' ) readln ( C ) D := B * B - 4 * A * C if ( D = 0 ) then begin writeln ( 'x = ' ,- B / 2.0 / A ) halt end if ( D > 0 ) then begin writeln ( 'x1 = ', ( - B + Sqrt ( D )) / 2.0 / A ) writeln ( 'x2 = ', ( - B - Sqrt ( D )) / 2.0 / A ) end else begin writeln ( 'x1 = (' ,- B / 2.0 / A, ',', Sqrt ( - D ) / 2.0 / A, ')' ) writeln ( 'x2 = (' ,- B / 2.0 / A, ',' ,- Sqrt ( - D ) / 2.0 / A, ')' ) end end.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |