






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







CMSC 330 2
¾ Also known for Code of Hammurabi, an early legal code
CMSC 330 3
A [rectangular] cistern. The height is 3, 20, and a volume of 27, 46, 40 has been excavated. The length exceeds the width by 50. You should take the reciprocal of the height, 3, 20, obtaining 18. Multiply this by the volume, 27, 46, 40, obtaining 8, 20. Take half of 50 and square it, obtaining 10, 25. Add 8, 20, and you get 8, 30, 25 The square root is 2, 55. Make two copies of this, adding [25] to the one and subtracting from the other. You find that 3, 20 [i.e., 3 1/3] is the length and 2, 30 [i.e., 2 1/2] is the width. This is the procedure.
CMSC 330 4
CMSC 330 5
¾ A mechanical calculator for computing polynomials ¾ Uses finite difference method to avoid multiplication & division ¾ Never completely finished ¾ Model built in 1991 at the London Science Museum
CMSC 330 6
CMSC 330 7
CMSC 330 8
CMSC 330 9
CMSC 330 10
CMSC 330 11
CMSC 330 12
CMSC 330 19
Success of FORTRAN led to modern compilers Up to FORTRAN 95
CMSC 330 20
CMSC 330 21
PROGRAM-ID. Iteration-If. AUTHOR. Michael Coughlan.
01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE.
Source: http://www.csis.ul.ie/COBOL/examples/conditn/IterIf.htm
Program data (variables) Single-digit number
Character
Initial value
Level number; can be used to express hierarchy (records) The source of Y2K bugs
CMSC 330 22
Calculator. PERFORM 3 TIMES DISPLAY "Enter First Number : " WITH NO ADVANCING ACCEPT Num DISPLAY "Enter Second Number : " WITH NO ADVANCING ACCEPT Num DISPLAY "Enter operator (+ or ) : " WITH NO ADVANCING ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result END-PERFORM. STOP RUN.
Iteration
CMSC 330 23
CMSC 330 24
CMSC 330 25
(defun factorial (n) (cond ((zerop n) 1) (t (times n (factorial (sub1 n)))))
CMSC 330 27
CMSC 330 28
CMSC 330 29
CMSC 330 30
CMSC 330 37
Source: http://en.wikipedia.org/wiki/APL_programming_language
CMSC 330 38
One language to replace FORTRAN and COBOL
CMSC 330 39
CMSC 330 40
10 INPUT "What is your name: "; U$ 20 PRINT "Hello "; U$ 25 REM 30 INPUT "How many stars do you want: "; N 35 S$ = "" 40 FOR I = 1 TO N 50 S$ = S$ + "” 55 NEXT I 60 PRINT S$ 65 REM 70 INPUT "Do you want more stars? "; A$ 80 IF LEN(A$) = 0 THEN GOTO 70 90 A$ = LEFT$(A$, 1) 100 IF (A$ = "Y") OR (A$ = "y") THEN GOTO 30 110 PRINT "Goodbye "; 120 FOR I = 1 TO 200 130 PRINT U$; " "; 140 NEXT I 150 PRINT* Source: http://en.wikipedia.org/wiki/BASIC_programming_language
Lines numbered
Variables
Comment
Loop
Goto common
CMSC 330 41
CMSC 330 42
Private Sub DisplayPrimeNumbers() Dim Num As Long Dim NN As Long Dim IsPrime As Boolean For Num = 2 To 1000 IsPrime = True For NN = 2 To Int(Num / 2) If Num Mod NN = 0 Then IsPrime = False Exit For End If Next If IsPrime Then MsgBox CStr(Num) + " is a prime number!" End If Next End Sub
CMSC 330 43
CMSC 330 44
type day = (Sun, Mon, Tue, Wed, Thu, Fri, Sat); type weekday = Mon..Fri; type day_of_month = 1..31;
var hours : array[Mon..Fri] of 0..24; var M : array[Mon..Fri] of array[char] of real; for day := Mon to Fri do M[day][‘e’] := 0.0001; Source: http://www.augustana.ca/~mohrj/courses/common/csc370/lecture_notes/pascal.html
CMSC 330 45
var S, T : set of 1..10; S := [1, 2, 3, 5, 7]; T := [1..6]; U := S + T; { set union } if 6 in S * T then ... { set intersection }
Source: http://www.augustana.ca/~mohrj/courses/common/csc370/lecture_notes/pascal.html CMSC 330 46
CMSC 330 47
CMSC 330 48
CMSC 330 55
CMSC 330 56
CMSC 330 57
CMSC 330 58
CMSC 330 59
using System; class Employee { } class Contractor : Employee { } class CastExample { public static void Main () { Employee e = new Employee(); Console.WriteLine("e = {0}", e == null? "null" : e.ToString()); Contractor c = e as Contractor ; Console.WriteLine("c = {0}", c == null? "null" : c.ToString()); } }
CMSC 330 60
CMSC 330 61
(^10) Delphi 2.665%
(^9) Ruby 2.855%
(^7) Python 4.534%
(^6) Perl 5.934%
3 (Visual) Basic 11.699%
1 Java 20.529%
Rank Language Ratings
(^20) ColdFusion 0.384%
(^19) Ada 0.393%
(^17) FoxPro/xBase 0.459%
(^16) Lisp/Scheme 0.476%
(^15) Pascal 0.513%
11 JavaScript 2.434%
RankLanguage Ratings
CMSC 330 62
Java C VBasic PHP C++ Perl Python C# Ruby Delphi
CMSC 330 63
CMSC 330 64