0% found this document useful (0 votes)
61 views19 pages

Programs in Basic'

The document discusses programs written in the BASIC programming language. It provides background on what a program is, the origins and design principles of BASIC, examples of unstructured and structured BASIC code, and an example program to solve simultaneous linear equations in BASIC. The linear equations program demonstrates how BASIC uses line numbers, READ and DATA statements to input values, and conditional logic to check for a unique solution.

Uploaded by

Jay
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views19 pages

Programs in Basic'

The document discusses programs written in the BASIC programming language. It provides background on what a program is, the origins and design principles of BASIC, examples of unstructured and structured BASIC code, and an example program to solve simultaneous linear equations in BASIC. The linear equations program demonstrates how BASIC uses line numbers, READ and DATA statements to input values, and conditional logic to check for a unique solution.

Uploaded by

Jay
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

PROGRAMS IN ‘BASIC’

Presentation By
Jayakanth C V
NO:20
PROGRAM

 Set of directions, which is used to provide


an answer to some problem.

 Consists of a set of instructions to be performed or


carried out in a certain order.
 It starts with the given data and parameters, and
ends up with a set of answers.
BASIC

 ‘BASIC’ stands for Beginner's All-purpose


Symbolic Instruction Code.

 Designed in 1964 by John George Kemeny and


Thomas Eugene Kurtz at Dartmouth College,
USA.
The seven design principles of BASIC

 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 computer
hardware.
Summary of the 15 BASIC Statements

LET- Condition END- end program


READ- read data STOP- stop program
DATA- Values to variables DEF- define
PRINT- print a value GOSUB- gosub ‘line
number’
GOTO- go to line number
RETURN- return to ‘x’
IF-THEN if ‘x’, then ‘y’
DIM- dimension
FOR- for i= ‘x’ to ‘y’
REM- remove string that is
NEXT- next value over
Unstructured BASIC
 New BASIC programmers on a home computer
might start with a simple program.
 This generally involves simple use of the
language's PRINT statement to display the
message (such as the programmer's name) to the
screen.
 Most first generation BASIC languages such
as MSX-BASIC and GW-BASIC supported simple
data types, loop cycles and arrays.
Example for Unstructured BASIC
10 INPUT "What is your name: ", U$
20 PRINT "Hello "; U$
30 INPUT "How many stars do you want: ", N
40 S$ = ""
50 FOR I = 1 TO N
60 S$ = S$ + "*"
70 NEXT I
80 PRINT S$
90 INPUT "Do you want more stars? ", A$
100 IF LEN(A$) = 0 THEN GOTO 90
110 A$ = LEFT$(A$, 1)
120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30
130 PRINT "Goodbye "; U$
140 END
Structured BASIC

 Second generation BASICs (for


example QuickBASIC and PowerBASIC)
introduced a number of features into the
language

 Line numbering is omitted from the


language and replaced
with labels (for GOTO) and procedures to
encourage easier and more flexible design.
Example for Structured BASIC
INPUT "What is your name: ", UserName$
PRINT "Hello "; UserName$
DO
INPUT "How many stars do you want: ", NumStars
Stars$ = STRING$(NumStars, "*")
PRINT Stars$
DO
INPUT "Do you want more stars? ", Answer$
LOOP UNTIL Answer$ <> ""
Answer$ = LEFT$(Answer$, 1)
LOOP WHILE UCASE$(Answer$) = "Y"
PRINT "Goodbye "; UserName$
Program to find the Average height of
Students:
5 REMARK: PROGRAM TO FIND AVERAGE HEIGHT
10 LET S=0
20 LET N=0
30 READ H
35 REMARK: H IS THE HEIGHT OF STUDENT
40 REMARK: N IS THE NUMBER OF STUDENTS
45 REMARK: S IS THE SUM OF HEIGHTS
50 LET S=S+H
60 LET N=N+1
70 IF H=0 THEN 90
80 GO TO 30
90 LET A=S/(N-1)
100 PRINT “AVERAGE HEIGHT”, A
110DATA 20,30,45,50,55,60,0
120 END
OBSERVATIONS

1. All lines in the program start with a line


number.
 It is to identify the lines in the program, each one of
which is called a statement
 It 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 cntd…

3. We use only capital letters.

4. Spaces have no significance in BASIC


 It is to “pretty up” a program and make it more
readable.
Solving two Simultaneous linear
Equations

A1X1+A2X2=B1
A3X1+A4X2=B2
Since there are only two equations, we may find the
solution by the formulas
BASIC Program for Solving two
Simultaneous linear Equations
10 READ A1, A2, A3,A4
15 LET D= A1*A4-A3*A2
20 IF D=0 THEN 65
30 READ B1, B2
37 LET X1= (B1*A4-B2*A2)/D
42 LET X2= (A1*B2-A3*B1)/D
55 PRINT “X1=“; X1
56 PRINT “X2=“; X2
60 GO TO 90
65 PRINT “NO UNIQUE SOLUTION”
70 DATA 1, 2, 4,2
80 DATA -7, 5
90 END
Interpretation
 First statement, numbered 10, is a READ
statement.
 The variables whose names are listed after the
READ will be given values according to the next
available numbers in the DATA statements.
 The statement, numbered 15, is LET statement.
 It compute the value of the expression A1A4-A3A2,
and assigns this value to the variable D.
Interpretation cntd…

 In line 20 the computer asks a question: “Is D


equal to 0”.
 If the answer is yes, then the next statement to be
executed by the computer is the one numbered 65.
 If the answer is no, the computer continues to
statement 30.
Interpretation cntd…

 In line 30, the computer causes the variable B1 and


B2 to be given the value next appearing in the
DATA statement .
 The statements numbered 37 and 42 complete the
computation of the solution, X1 and X2.
 Then statement 60 tells the computer to execute
next statement 30 will cause the variables B1 and
B2 to be given the values 1 and 3, respectively.
Interpretation cntd…

 If D, the determinant of the coefficients, is zero, we


know that the set of equations does not have a
unique solution.
 In this case, statement 20 will cause the computer to
execute statement 65 next.
 Instead of numerical answers being printed out, it
will produce the English message ‘NO UNIQUE
SOLUTION’
Thank you

You might also like