A Sample FORTRAN Program That Calculates Payroll - DOC by ntz11397

VIEWS: 0 PAGES: 7

									2-3 arkadaş biraraya geliniz. Aşağıda yeralan ve çeşitli programlama dilleri ile yazılmış
programları aşağıdaki rehber soruları gözönünde tutarak analiz ediniz.

- Programları meydana getiren unsurları açıklayınız.

- Programlarda ilginizi çeken unsurlar neler?

- Farklı programlama dilleri ile yazılmış programlar arasındaki benzerlikler neler?

- Farklı programlama dilleri ile yazılmış programlar arasındaki farklılıklar neler?

- İlk 4 programın aynı işi yaptığı gözönüne alınırsa kodlardaki uzunluk ve kısalık neden
kaynaklanıyor?

- Analizinize yardım edecek benzer soruları üretip aşağıya yazarak diğer gruplarla
paylaşmanız teşvik edilir.




Analiz sonuçlarını "AdinizSoyadiniz-ProgramlarınDili.doc" isimli bir dosyaya KİŞİSEL
OLARAK kaydedip dosyayı Ders Asistanı Fatma Hocanıza teslim ediniz.
Örnek FORTRAN Programı
*
* Calculate payroll amounts and print the net pay
*
* Print a title
       WRITE(6,10)
   10 FORMAT(1H1, 2X, '** PAYROLL COMPUTATION **'//)
*
* Initialize overtime to 0
*
       TOVRTM = 0.0
*
* Get hours worked and other pay data from user
*
       WRITE(6, 20)
   20 FORMAT('WHAT WERE THE HOURS WORKED? ')
       READ(5, 21) HRS
   21 FORMAT(F4.1)
       WRITE(6, 22)
   22 FORMAT(/'WHAT IS THE HOURLY RATE? ')
       READ(5, 23) RATE
   23 FORMAT(F7.2)
       WRITE(6, 24)
   24 FORMAT(/'WHAT IS THE TAX RATE? ')
       READ(6, 25) TAXRTE
   25 FORMAT(F7.2)
*
* Calculate the results
*
* Overtime is left at 0.0 or is double pay
* depending on the hours the employee worked
       IF (HRS .LT. 40.0) GOTO 100
       TOVRTM = (HRS - 40.0) * RATE * 2.0
       GROSS = 40.0 * RATE
       GOTO 200
  100 GROSS = HRS * RATE
  200 GROSS = GROSS + TOVRTM
       TNET = GROSS * (1.0 - TAXRTE)
*
* PRINT THE RESULTS
*
       WRITE(6, 300) HRS, RATE, TAXRTE, GROSS, TNET
  300 FORMAT(//'Hours: ', F4.1, 2X, 'Rate: ', F7.2,
     1     2x, 'Tax rate: ', F7.2, 2x, 'Gross: $', F10.2,
     2     2x, 'Net: $', F10.2)
       END
Örnek COBOL Programı
IDENTIFICATION DIVISION.
PROGRAM-ID.     'PAYROLL'

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
   SELECT GET-DATA, ASSIGN TO KEYIN.
   SELECT OUT-DATA, ASSIGN TO DISPLAY.

DATA DIVISION.
FILE SECTION.
FD GET-DATA
    LABEL RECORDS ARE OMITTED.
01 GET-REC.
    02 AMOUNT        PICTURE 9(5)V2.

FD    OUT-DATA
      LABEL RECORDS ARE OMITTED.
01    OUT-REC.
      02 FILLER        PICTURE X(80).

WORKING-STORAGE SECTION.
01 ARITHMETIC-DATA.
    02 TOT-OVR       PICTURE 9(5)V2 VALUE ZERO.
    02 HOURS         PICTURE 9(3)V1 VALUE ZERO.
    02 RATE          PICTURE 9(5)V2 VALUE ZERO.
    02 TAX-RATE      PICTURE 9(5)V2 VALUE ZERO.
    02 GROSS-PAY     PICTURE 9(5)V2 VALUE ZERO.
    02 NET-PAY       PICTURE 9(5)V2 VALUE ZERO.
01 OUT-LINE-1.
    02 FILLER        PICTURE X(28)
       VALUE 'What were the hours worked? '.
    02 FILLER        PICTURE X(52) VALUE SPACES.
01 OUT-LINE-2.
    02 FILLER        PICTURE X(25)
       VALUE 'What is the hourly rate? '.
    02 FILLER        PICTURE X(55) VALUE SPACES.
01 OUT-LINE-3.
    02 FILLER        PICTURE X(22)
       VALUE 'What is the tax rate? '.
    02 FILLER        PICTURE X(58) VALUE SPACES.
01 OUT-LINE-4.
    02 FILLER        PICTURE X(17)
       VALUE 'The gross pay is '
    02 OUT-GROSS     PICTURE $ZZ,ZZZ.99.
    02 FILLER        PICTURE X(53) VALUE SPACES.
01 OUT-LINE-5.
    02 FILLER        PICTURE X(15)
       VALUE 'The net pay is '
    02 OUT-NET       PICTURE $ZZ,ZZZ.99.
    02 FILLER        PICTURE X(55) VALUE SPACES.

PROCEDURE DIVISION.
BEGIN.
   OPEN INPUT GET-DATA.
   OPEN OUTPUT OUT-DATA.

     MOVE OUT-LINE-1 TO OUT-REC.
     WRITE OUT-REC.
     READ GET-DATA.
     MOVE AMOUNT TO HOURS.

     MOVE OUT-LINE-2 TO OUT-REC.
     WRITE OUT-REC.
     READ GET-DATA.
     MOVE AMOUNT TO RATE.

     MOVE OUT-LINE-3 TO OUT-REC.
     WRITE OUT-REC.
     READ GET-DATA.
     MOVE AMOUNT TO TAX-RATE.

     IF HOURS > 40.0
        THEN COMPUTE TOT-OVR = (40.0 - HOURS) * RATE * 2
             COMPUTE GROSS-PAY = 40.0 * RATE + TOT-OVR
     ELSE
        COMPUTE GROSS-PAY = HOURS * RATE.
     COMPUTE NET-PAY = GROSS-PAY * (1.0 - TAX-RATE).

     MOVE GROSS-PAY TO OUT-GROSS.
     MOVE OUT-LINE-4 TO OUT-REC.
     WRITE OUT-REC.

     MOVE NET-PAY TO OUT-NET.
     MOVE OUT-LINE-5 TO OUT-REC.
     WRITE OUT-REC.

     CLOSE GET-DATA, OUT-DATA.
     STOP RUN.
Örnek PL/I Programı
PAYROLL: PROCEDURE OPTIONS (MAIN);
DECLARE OVRTIM    FIXED DECIMAL (2);
DECLARE HOURS     FIXED DECIMAL (5,2);
DECLARE RATE      FIXED DECIMAL (9,2);
DECLARE TAXRATE   FIXED DECIMAL (9,2);
DECLARE GROSS     FIXED DECIMAL (9,2);
DECLARE NETPAY    FIXED DECIMAL (9,2);

BEGIN: GET LIST(HOURS, RATE, TAXRATE);
   IF HOURS < 40 THEN
      OVRTIM = (HOURS - 40) * RATE * 2
      GROSS = 40 * RATE
   ELSE
      OVRTIM = 0
      GROSS = HOURS * RATE;
   NETPAY = GROSS * (1 - TAXRATE);
   PUT LIST (OVRTIM, HOURS, RATE, TAXRATE, GROSS, NETPAY);
END PAYROLL
Örnek Pascal Programı
{ Typed constant arrays with records
  that hold people's statistics }
PROGRAM People;
USES Crt;
TYPE PersonTypes = (Employee, Vendor, Customer);
     PersonString = STRING[9];
     PersonRecord = RECORD
                       Name:    PersonString;
                       Balance: WORD;
                     END;
   PersonNameArray = ARRAY[PersonTypes] OF PersonRecord;
CONST People: PersonNameArray =
              ((Name: 'Sally'; Balance: 323.56),
                (Name: 'Ted';   Balance:   0.00),
                (Name: 'John'; Balance: 1212.37));
VAR Person: PersonTypes;

{The primary output routine appears next }
BEGIN
   CLRSCR;
   WRITELN( '*** People in System ***'):
   WRITELN;
   FOR Person := Employee TO Customer DO
     WITH People[Person] DO
        BEGIN
            WRITELN( Name, ' has a balance of $',
                     Balance, '.');
            WRITELN;
        END; {with}
END. {People}
Örnek BASIC Programı
10    REM Letter-guessing game in BASIC
20    REM Generate a random number from 65 to 90
30    REM (ASCII 65 is A and ASCII 90 is Z)
40    NUM = (INT(RND * 26)) + 65
50    CA$ = CHR$(NUM)
60    CLS
70    PRINT "*** Letter Guessing Game ***"
80    PRINT
90    PRINT "I am thinking of a letter..."
100   INPUT "What is your guess"; UG$
110   TR = TR + 1
120   IF (UG$ > CA$) THEN GOTO 150
130   IF (UG$ < CA$) THEN GOTO 180
140   GOTO 210
150   PRINT "Your guess was too high"
160   PRINT "Try again..."
170   GOTO 200
180   PRINT "Your guess was too low"
190   PRINT "Try again..."
200   GOTO 100
210   REM Here if guess was correct
220   PRINT "*** Congratulations! You got it right!"
230   PRINT "It took you only"; TR; "tries to guess."
240   END
Örnek QuickBASIC Programı
' Newer BASIC allows the more succinct ' for a remark instead of REM
' A letter-guessing game

num = (INT(RND * 26)) + 65   ' Generate a random number from 65 to 90
                             ' (ASCII 65 is A and ASCII 90 is Z)
compAns$ = CHR$(num)     ' Converts the number to a letter
tries = 0

CLS   ' Clear the screen
PRINT "*** Letter guessing game ***"
PRINT
PRINT "I am thinking of a letter..."

DO
   INPUT "What is your guess"; userGuess$
   tries = tries + 1
   IF (userGuess$ > compAns$) THEN
      PRINT "Your guess was too high"
      PRINT "Try again..."
   ELSE
      IF (userGuess$ < compAns$) THEN
          PRINT "Your guess was too low"
          PRINT "Try again..."
      END IF
   END IF
LOOP WHILE (userGuess$ <> compAns$)    ' Quit when a match is found

' User got it right, announce it
PRINT "*** Congratulations! You got it right!"
PRINT "It took you only"; tries; "tries to guess."
END

								
To top