PROGRAMS IN ‘BASIC’

  • Upload
    jay

  • View
    226

  • Download
    0

Embed Size (px)

Citation preview

  • 8/8/2019 PROGRAMS IN BASIC

    1/19

    PROGRAMS IN BASIC

    Presentation By Jayakanth C V

    NO:20

  • 8/8/2019 PROGRAMS IN BASIC

    2/19

    Set of directions, which is used to providean answer to some problem.

    Consists of a set of instructions to be performed orcarried out in a certain order.It starts with the given data and parameters, andends up with a set of answers.

    PROGRAM

  • 8/8/2019 PROGRAMS IN BASIC

    3/19

    BASIC stands for Beginner's All-purpose Symbolic Instruction Code .

    D esigned in 1964 by J ohn George Kemeny andThomas Eugene Kurtz at D artmouth College,USA.

    BASIC

  • 8/8/2019 PROGRAMS IN BASIC

    4/19

    Be easy for beginners to use.Be a general-purpose programming language.

    Allow advanced features to be added for experts(while keeping the language simple for beginners).Be interactive.Provide clear and friendly error messages.

    Respond quickly for small programs.Not to require an understanding of computerhardware.

    The seven design principles of

    BASIC

  • 8/8/2019 PROGRAMS IN BASIC

    5/19

    LET - ConditionREAD - read dataDATA - Values to variablesPRINT - print a valueGOTO - go to line number IF-THEN if x , then yFOR

    - for i= x to yNEXT - next value

    Summary of the 15 BASIC Statements

    END - end programSTOP - stop programDEF - defineGOSUB - gosub line

    numberRETURN - return to xDIM - dimensionREM - remove string that is

    over

  • 8/8/2019 PROGRAMS IN BASIC

    6/19

  • 8/8/2019 PROGRAMS IN BASIC

    7/19

    10 INPUT "What is your name: ", U$20 PRINT "Hello "; U$30 INPUT "How many stars do you want: ", N40 S$ = ""50 FOR I = 1 TO N60 S$ = S$ + "*"70 NEXT I80 PRINT S$90 INPUT " D o you want more stars? ", A$100 IF LEN(A$) = 0 THEN GOTO 90110 A$ = LEFT$(A$, 1)120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30130 PRINT "Goodbye "; U$140 EN D

    Example for Unstructured BASIC

  • 8/8/2019 PROGRAMS IN BASIC

    8/19

    Second generation BASICs (forexample QuickBASIC and PowerBASIC)

    introduced a number of features into thelanguage

    Line numbering is omitted from thelanguage and replaced

    with labels (for GOTO) and procedures toencourage easier and more flexible design.

    Structured BASIC

  • 8/8/2019 PROGRAMS IN BASIC

    9/19

    INPUT "What is your name: ", UserName$PRINT "Hello "; UserName$D O

    INPUT "How many stars do you want: ", NumStarsStars$ = STRING$(NumStars, "*")PRINT Stars$D OINPUT " D o you want more stars? ", Answer$LOOP UNTIL Answer$ ""

    Answer$ = LEFT$(Answer$, 1)LOOP WHILE UCASE$(Answer$) = "Y"PRINT "Goodbye "; UserName$

    Example for Structured BASIC

  • 8/8/2019 PROGRAMS IN BASIC

    10/19

    5 REMARK: PROGRAM TO FIN D AVERAGE HEIGHT10 LET S=020 LET N=0

    30 REA D H35 REMARK: H IS THE HEIGHT OF STU D ENT40 REMARK: N IS THE NUMBER OF STU D ENTS45 REMARK: S IS THE SUM OF HEIGHTS50 LET S=S+H60 LET N=N+170 IF H=0 THEN 9080 GO TO 3090 LET A=S/(N-1)100 PRINT AVERAGE HEIGHT, A 110 D ATA 20,30,45,50,55,60,0

    120 END

    Program to find the Average height

    of Students:

  • 8/8/2019 PROGRAMS IN BASIC

    11/19

    1. All lines in the program start with a linenumber.

    It is to identify the lines in the program, each one of which is called a statementIt specifies the order in which the statements are to be performed by the computer

    2. Each statement starts, after its line number, with an English word.

    This word denotes the type of the statement.

    There are fifteen types of statements in BASIC.

    OBSERVATIONS

  • 8/8/2019 PROGRAMS IN BASIC

    12/19

    3. We use only capital letters.

    4. Spaces have no significance in BASICIt is to pretty up a program and make it more

    readable.

    OBSERVATIONS cntd

  • 8/8/2019 PROGRAMS IN BASIC

    13/19

    A 1X

    1+A

    2X

    2=B

    1 A 3X1+A 4X2=B 2Since there are only two equations, we may find the

    solution by the formulas

    Solving two Simultaneous linear

    Equations

  • 8/8/2019 PROGRAMS IN BASIC

    14/19

    10 REA D A1, A2, A3,A415 LET D = A1*A4-A3*A220 IF D =0 THEN 65

    30 REA D B1, B237 LET X1= (B1*A4-B2*A2)/ D42 LET X2= (A1*B2-A3*B1)/ D55 PRINT X1=; X156 PRINT X2=; X260 GO TO 9065 PRINT NO UNIQUE SOLUTION70 D ATA 1, 2, 4,280 D ATA -7, 5

    90 EN D

    BASIC Program for Solving two

    Simultaneous linear Equations

  • 8/8/2019 PROGRAMS IN BASIC

    15/19

    First statement, numbered 10, is a REA D statement.

    The variables whose names are listed after theREA D will be given values according to the nextavailable numbers in the D ATA statements.The statement, numbered 15, is LET statement.It compute the value of the expression A 1 A 4-A 3 A 2,and assigns this value to the variable D .

    Interpretation

  • 8/8/2019 PROGRAMS IN BASIC

    16/19

    In line 20 the computer asks a question: Is D equalto 0.If the answer is yes, then the next statement to beexecuted by the computer is the one numbered 65.If the answer is no, the computer continues tostatement 30.

    Interpretation cntd

  • 8/8/2019 PROGRAMS IN BASIC

    17/19

    In line 30, the computer causes the variable B1 andB2 to be given the value next appearing in theD ATA statement .The statements numbered 37 and 42 complete thecomputation of the solution, X1 and X2.

    Then statement 60 tells the computer to executenext statement 30 will cause the variables B1 andB2 to be given the values 1 and 3, respectively.

    Interpretation cntd

  • 8/8/2019 PROGRAMS IN BASIC

    18/19

    If D , the determinant of the coefficients, is zero, weknow that the set of equations does not have aunique solution.In this case, statement 20 will cause the computer toexecute statement 65 next.

    Instead of numerical answers being printed out, it will produce the English message NO UNIQUESOLUTION

    Interpretation cntd

  • 8/8/2019 PROGRAMS IN BASIC

    19/19

    Thank you