SlideShare a Scribd company logo
Building blocks No. 2
and
GWBASIC PROGRAMMING
– For new comers,GWBASIC a good start-
easy to learn, portable executable program
with graphics capability, and is a freeware.
– BASIC-acronym for Beginners All-purpose
Symbolic Instruction Code
• designed as a language for beginners
• developed by John Kemeny and Kenneth Kurtz
• GWBASIC-version of BASIC produced by
Microsoft,Inc.
– Other languages:
• FORTRAN - Formula Translation; for S and E.
• Gnu Fortran 77- freeware ; FORTRAN 90 is
most recent version.
We will learn to write simple
programs in GWBASIC
– Gwbasic, Fortran and other higher level languages
do essentially the same thing-they interpret the
program or souce code we write into a language
the machine can understand.
– Gwbasic is a program by itself. It is an interpreter,
that is, it translates our code line by line to the
computer while our program is running.
– Fortran and similar languages interpret or compile
the entire code into a machine language before
the computer can run the program.
GETTING STARTED
• Beginning a session
– Gwbasic screen; KEY OFF, KEY ON
• Coding or writing a new program (NEW)
• Saving a program (SAVE or F4 key)
• Loading or recalling a program (LOAD or F3
key)
• Running a program (RUN or F2 key)
• Ending your computer session (SYSTEM)
Getting started- see how these
commands work.
• NEW
• SAVE “filename”
• LOAD “filename”
• RUN “filename”
• SYSTEM
• Note: close quotation optional. Extension
name if not present is understood to be .BAS.
GWBASIC EDITOR
• A Gwbasic pgm consists of numbered
program lines: all lines are executable except
REM (or ‘) lines. The lines are executed
according to numerical sequence.
• Correcting errors-key operations
• Inserting lines
• Some commands for editing:
– CLS, FILES, LIST
– RENUM, DELETE
BUILDING BLOCKS OF A
GWBASIC PROGRAM - 1
A Gwbasic program as shown in the examples is made
up of a structured collection of numbered LINE
STATEMENTS, which are executed by the computer
according to numerical sequence.
Structured means the line statements carry out specific
tasks in accordance with some clear and logical
procedure.
SYNTAX
Line number statement [ : statement ] [ ‘comment ]
Note:[ ] refer to optional elements in the line statement.
BUILDING BLOCKS OF A
GWBASIC PROGRAM - 2
EXAMPLES OF LINE STATEMENTS
10 X = 5 : R = 8.03 : C=A*B ‘C is the speed in cm/sec
300 Z = 2.98*(X+1.07)
500 PRINT X, Y, Z
600 GOTO 198
89 GOSUB 345
900 LPRINT A,B,C
40 IF X<=2 THEN GOTO 30 ELSE GOTO 90
10 REM Program does linear regression analysis.
BUILDING BLOCKS OF A
GWBASIC PROGRAM - 3
QUESTION: What makes up a line statement? How do
we construct them?
1. NUMERIC CONSTANTS - 2, 1/4, -56.083, 0.000367,
-3.45E+12, 12.9213, 6.213453678921234
2. VARIABLES - X , Y, DIST , A(2), B(3,4), NAME$
3. OPERATIONS - arithmetic/algebraic operations: + , -,
^ , / , , MOD
4. RULES - naming of variables, hierarchy of
operations, use of parentheses, ...
5. STRUCTURE - flow of control, program layout, ...
1. NUMERIC CONSTANTS - 1
TYPES OF NUMERIC CONSTANTS
1. Integer - an ordinary integer, positive or negative.
Range -32768< x < 32768 .
Example 7, -23, 21346, +789
2. Single precision - a number with six or fewer
significant digits that has a decimal point.
Range 10^(-38) < x < 10^(+38)
(^ refers to exponentiation, meaning raised to)
Example 234.567, -9.8765, 6.023E+23
1. NUMERIC CONSTANTS – 2
3. Double precision – a number with seven or more
significant digits and a decimal point. May have as
many as 17 significant digits.
Range As in single precision constants
Example 3.76324523, 0.9987698543574532,
1.6578438D-12
1. NUMERIC CONSTANTS - 3
TYPE DECLARATION TAGS
The type of a number can be indicated by a type
declaration tag:
TYPE TAG EXAMPLE
1. Integer % 3%, 564%
2. Single precision ! 1.34! , 43.7865!,
23.56E-8
3. Double precision # 3.4567#, 2.67D+21
2. VARIABLES - 1
RULES FOR NAMING OF VARIABLES
1. Characters must be alphanumeric,i.e., use
alphabetic (A-Z) and numeral (0 – 9) characters
only.
2. First character must be a letter.
3. Variable name may contain as many as 40
characters. No blank spaces in a name.
Note: Use variable names which reflect the data stored
in the variable. Also, long variable names are not
practical or advisable to use in a program.
2. VARIABLES - 2
Variables in Gwbasic and other programming
languages are classified according to the data they
store. We have the following types in Gwbasic:
Variable type Type declaration tag Example
1. Integer % J%, KK%, ICT%
2. Single ! X!, A7!, DIST!
3. Double # XJ23#, AREA#
4. String $ TITLE$, A5B$
5. Note: String variables in Gwbasic are initialized to
the null character “ “. The other variables are
initialized to 0.
2. VARIABLES - 3
VARIABLE DECLARATION
1. Each variable must be assigned a type.
2. In general, however, it is not necessary to worry
about variable type declaration in a program.
Gwbasic adopts an implicit declaration of variables:
variable names which end with the $ tag are
declared string variables; variable names which do
not end in any tag character are declared variable
names of type SINGLE.
3. Explicit variable type declaration can be
accomplished using either the type declaration tags
(%.!,#,$) or the DEFtype statements.
2. VARIABLES - 4
EXAMPLES – EXPLICIT VARIABLE TYPE
DECLARATION
1. Using the tag characters – A%, ITEM$, Y!, BBC#
2. Using the DEFtype statements – put these
statements at the beginning of the program.
DEFINT B-F, L-M, P This means that all variable
names which begin with the letters B to F, L to M,
and P are to be treated as integer variables, that is,
the values they store are integer constants.
DEFSNG, DEFDBL, DEFSTR statements for
single, double, and string variables respectively
follow the same syntax.
Note: Tag characters override DEFtype statements.
2. VARIABLES - 5
SUBSCRIPTED VARIABLES
The purpose is to use the same variable name to refer to
a collection of data or numbers.
Example: X(I), I = 1, 10
A(K , L ), K = 1,10 , L = 1, 25
Here , X is a one-dimensional array while A is a two-
dimensional array. The dimensions or sizes of the arrays
are communicated to the computer by using the DIM
statement:
10 DIM X(10), A(10,25)
Note:Put DIM statements at the beginning of the
program.
3. OPERATIONS - 1
1. 1. Hierarchy of operations: list is of descending
priority
2. Operation Symbol Example
Exponentiation ^ 2^15, X^5,
5.12^(1/3)
Multiplication, division *, / X*Y, A/2.35
Integer division  32, 92
Remainder in integer MOD 8 MOD 3
division
Addition,subtraction +, - 6.7 +89.3 – 5.7
3. OPERATIONS - 2
2. Arithmetic operations are carried out LEFT to RIGHT.
3. Use parentheses whenever their use will help clarify
the order of the operations that must be carried out.
Inner parentheses are calculated first.
Examples
3.6*89.2+6^3-8.7+2.3-1.9
((2.8-3.5*6)/3.9)-(2.7/3.8+43.3)
4. Algebraic expressions are constructed using the
numeric constants,variables and the arithmetic
operations discussed above. Built-in mathematical
functions in Gwbasic enlarge the kind of algebraic
expressions we can employ in a program.
BUILT-IN FUNCTIONS - 1
FUNCTION SYNTAX
1. Sine SIN(X) , X in radians
2. Cosine COS(X)
3. Tangent TAN(X)
4. Arc tangent ATN(X)
5. Square root SQR(X) , X >= 0
6. Exponential EXP(X)
7. Natural logarithm LOG(X) , X > 0
BUILT-IN FUNCTIONS - 2
FUNCTION SYNTAX
8. Absolute value ABS(X)
9. Greatest integer INT(X)
less than or equal
to X
10. Remove decimal FIX(X)
part of a number
11. Remove the number SGN(X)
but keep its sign
BUILT-IN FUNCTIONS - 3
FUNCTION SYNTAX
12. Convert X to integer constant CINT(X)
13. Convert X to single precision CSNG(X)
constant
14. Convert X to double precision CDBL(X)
constant
4. RULES
By this we mean the specific procedures that we must
use in order to correctly translate our code into a
language the computer can understand. We have
seen several of these rules.
Other rules relating to the various constructs of
Gwbasic may be found in the appropriate sections of
the manual you downloaded from the internet.
5. STRUCTURE
The structure for the various commands will be
discussed when we get to them. However,the structure
or layout of a Gwbasic program should look like the one
below:
10 ‘Program documentation
20 ‘Main program
- dimension, type and user-defined function
statements
30 ‘Subroutines
40 ‘Data statements
50 ‘End statement
INPUT/OUTPUT STATEMENTS - 1
The purpose of these statements is to receive data for
computer processing and to output the results generated
by the program.
Input statements
1. INPUT - gets input data from keyboard.
100 INPUT X,Y, Z, AY$
20 INPUT “IFLAG=“; IFLAG
2. READ and DATA statements come together.
50 READ X, T, N$, H
‘
100 DATA 10.3, 25.6, “argon”, 234.1
INPUT/OUTPUT STATEMENTS - 2
Output statements
1. PRINT - prints output to the screen.
100 PRINT A
50 PRINT TITLE$
350 PRINT TAB(5);X;TAB(15);Y
2. PRINT USING - for formatting output
120 PRINT USING “##.###”;A
70 PRINT USING “A= ##.### J=###”;A,J
3. LPRINT - as above, but print is transferred to the
line printer for a hardcopy.
4. LPRINT USING - as in no. 3 above.
CONTROL STATEMENTS - 1
There are four control statements in Gwbasic: FOR-
NEXT, GOTO, IF-THEN, and IF-THEN-ELSE.
1. FOR-NEXT - for repetitive calculations.
Syntax
line # FOR X = X1 TO X2 [STEP X3]
line # statement 1
‘
line # statement n
line # NEXT X
Note: The default value of the increment X3 is 1 if the
optional bracketed expression is omitted.
CONTROL STATEMENTS - 2
Example : FOR-NEXT statement
120 FOR J = 1 TO 50
130 K = 3*J+1
140 PRINT “J =“;J;TAB(12);”K =“;K
150 NEXT J
-------------------------------------------------------------------
20 SUM = 0. : KF%= 12 : KL% = 32 : KDEL% = 5
30 FOR K% = KF% TO KL% STEP KDEL%
40 SUM = SUM + 2.87*CSNG(K%)^3
50 NEXT K%
CONTROL STATEMENTS - 3
Example: nested FOR-NEXT statements
10 DIM A(50), B(50,20), C(50)
‘
40 FOR N = 1 TO 30 STEP 3
50 X = A(N)^2 + 3.87
60 FOR L = 1 TO 10
70 B(N, L) = A(N)*C(L) *X + COS(X)/LOG(X-1.05)
80 NEXT L
90 NEXT N
‘
CONTROL STATEMENTS - 4
2. GOTO statement - for unconditional transfer of control
Syntax
line # GOTO line #
Example
120 GOTO 230
70 GOTO 10
CONTROL STATEMENTS - 5
3. IF-THEN statement
Relational operators Symbol
Equal =
Less than <
Greater than >
Less than or equal to <=
Greater than or equal to >=
These operators are used in the argument of the IF
statement to determine the flow of control.
CONTROL STATEMENTS - 6
Compound relational operators: AND , OR
Simple relational expression - involves a single
relational operator: A > 12, B<= 3.
Complex relational expression - involves several simple
relational expressions joined by the relational operators
AND and OR.
Examples:
(A>8) AND (C<2) This is true if both expressions are
true; false otherwise.
(A>8) OR (C<2) This is true provided one or the
other of the two expressions is true; false otherwise.
More in the next part…..

More Related Content

PPT
Programming
PPTX
C Programming Unit-1
PPT
Interm codegen
PPTX
Intermediate code generation1
PPT
C++ rajan
PPS
Learn C
DOC
20 C programs
PPT
Ch4 functions
Programming
C Programming Unit-1
Interm codegen
Intermediate code generation1
C++ rajan
Learn C
20 C programs
Ch4 functions

What's hot (20)

PPTX
C Programming Unit-2
PPT
1 Revision Tour
PDF
C programming session5
PPT
Ch3 repetition
PPTX
C language basics
PDF
programming fortran 77 Slide02
PPT
Introduction To Algorithm [2]
PPTX
Back patching
PDF
User Defined Functions in C Language
PPT
Ch2 introduction to c
PPTX
Three address code In Compiler Design
PPT
Unit iv functions
PDF
Introduction to c programming
PPT
Intermediate code generation
PDF
C programming & data structure [arrays & pointers]
PPTX
Programming C Language
PPS
C programming session 01
DOC
Compiler notes--unit-iii
PPT
Ch1 principles of software development
PPTX
Introduction to code optimization by dipankar
C Programming Unit-2
1 Revision Tour
C programming session5
Ch3 repetition
C language basics
programming fortran 77 Slide02
Introduction To Algorithm [2]
Back patching
User Defined Functions in C Language
Ch2 introduction to c
Three address code In Compiler Design
Unit iv functions
Introduction to c programming
Intermediate code generation
C programming & data structure [arrays & pointers]
Programming C Language
C programming session 01
Compiler notes--unit-iii
Ch1 principles of software development
Introduction to code optimization by dipankar
Ad

Similar to Building blocks 2 (20)

PPT
3 algorithm-and-flowchart
PPT
Lecture 01 2017
PPTX
Module 3 Computer Organization Data Hazards.pptx
PPTX
Compilers
PDF
Lec04-CS110 Computational Engineering
PPTX
C programming language
PPT
Variable< Arithmetic Expressions and Input
PPTX
Algorithms and flowcharts
PDF
Problem solving using computers - Chapter 1
PDF
Chap 3 c++
PPTX
Algorithms and Flowcharts
PPTX
Chapter1.pptx
PPTX
Introduction%20C.pptx
PDF
MATLAB_Practice_lect details about matlab3 (1).pdf
PDF
C standard library functions
PPTX
Matlab-3.pptx
PPT
c-programming
PDF
Problem solving using computers - Unit 1 - Study material
PPTX
Programming in C by SONU KUMAR.pptx
3 algorithm-and-flowchart
Lecture 01 2017
Module 3 Computer Organization Data Hazards.pptx
Compilers
Lec04-CS110 Computational Engineering
C programming language
Variable< Arithmetic Expressions and Input
Algorithms and flowcharts
Problem solving using computers - Chapter 1
Chap 3 c++
Algorithms and Flowcharts
Chapter1.pptx
Introduction%20C.pptx
MATLAB_Practice_lect details about matlab3 (1).pdf
C standard library functions
Matlab-3.pptx
c-programming
Problem solving using computers - Unit 1 - Study material
Programming in C by SONU KUMAR.pptx
Ad

Recently uploaded (20)

DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Well-logging-methods_new................
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Construction Project Organization Group 2.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPT
Project quality management in manufacturing
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
PPT on Performance Review to get promotions
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
UNIT 4 Total Quality Management .pptx
DOCX
573137875-Attendance-Management-System-original
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
bas. eng. economics group 4 presentation 1.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Well-logging-methods_new................
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Construction Project Organization Group 2.pptx
OOP with Java - Java Introduction (Basics)
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Embodied AI: Ushering in the Next Era of Intelligent Systems
Project quality management in manufacturing
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPT on Performance Review to get promotions
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
UNIT 4 Total Quality Management .pptx
573137875-Attendance-Management-System-original
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
bas. eng. economics group 4 presentation 1.pptx

Building blocks 2

  • 1. Building blocks No. 2 and GWBASIC PROGRAMMING
  • 2. – For new comers,GWBASIC a good start- easy to learn, portable executable program with graphics capability, and is a freeware. – BASIC-acronym for Beginners All-purpose Symbolic Instruction Code • designed as a language for beginners • developed by John Kemeny and Kenneth Kurtz • GWBASIC-version of BASIC produced by Microsoft,Inc. – Other languages: • FORTRAN - Formula Translation; for S and E. • Gnu Fortran 77- freeware ; FORTRAN 90 is most recent version.
  • 3. We will learn to write simple programs in GWBASIC – Gwbasic, Fortran and other higher level languages do essentially the same thing-they interpret the program or souce code we write into a language the machine can understand. – Gwbasic is a program by itself. It is an interpreter, that is, it translates our code line by line to the computer while our program is running. – Fortran and similar languages interpret or compile the entire code into a machine language before the computer can run the program.
  • 4. GETTING STARTED • Beginning a session – Gwbasic screen; KEY OFF, KEY ON • Coding or writing a new program (NEW) • Saving a program (SAVE or F4 key) • Loading or recalling a program (LOAD or F3 key) • Running a program (RUN or F2 key) • Ending your computer session (SYSTEM)
  • 5. Getting started- see how these commands work. • NEW • SAVE “filename” • LOAD “filename” • RUN “filename” • SYSTEM • Note: close quotation optional. Extension name if not present is understood to be .BAS.
  • 6. GWBASIC EDITOR • A Gwbasic pgm consists of numbered program lines: all lines are executable except REM (or ‘) lines. The lines are executed according to numerical sequence. • Correcting errors-key operations • Inserting lines • Some commands for editing: – CLS, FILES, LIST – RENUM, DELETE
  • 7. BUILDING BLOCKS OF A GWBASIC PROGRAM - 1 A Gwbasic program as shown in the examples is made up of a structured collection of numbered LINE STATEMENTS, which are executed by the computer according to numerical sequence. Structured means the line statements carry out specific tasks in accordance with some clear and logical procedure. SYNTAX Line number statement [ : statement ] [ ‘comment ] Note:[ ] refer to optional elements in the line statement.
  • 8. BUILDING BLOCKS OF A GWBASIC PROGRAM - 2 EXAMPLES OF LINE STATEMENTS 10 X = 5 : R = 8.03 : C=A*B ‘C is the speed in cm/sec 300 Z = 2.98*(X+1.07) 500 PRINT X, Y, Z 600 GOTO 198 89 GOSUB 345 900 LPRINT A,B,C 40 IF X<=2 THEN GOTO 30 ELSE GOTO 90 10 REM Program does linear regression analysis.
  • 9. BUILDING BLOCKS OF A GWBASIC PROGRAM - 3 QUESTION: What makes up a line statement? How do we construct them? 1. NUMERIC CONSTANTS - 2, 1/4, -56.083, 0.000367, -3.45E+12, 12.9213, 6.213453678921234 2. VARIABLES - X , Y, DIST , A(2), B(3,4), NAME$ 3. OPERATIONS - arithmetic/algebraic operations: + , -, ^ , / , , MOD 4. RULES - naming of variables, hierarchy of operations, use of parentheses, ... 5. STRUCTURE - flow of control, program layout, ...
  • 10. 1. NUMERIC CONSTANTS - 1 TYPES OF NUMERIC CONSTANTS 1. Integer - an ordinary integer, positive or negative. Range -32768< x < 32768 . Example 7, -23, 21346, +789 2. Single precision - a number with six or fewer significant digits that has a decimal point. Range 10^(-38) < x < 10^(+38) (^ refers to exponentiation, meaning raised to) Example 234.567, -9.8765, 6.023E+23
  • 11. 1. NUMERIC CONSTANTS – 2 3. Double precision – a number with seven or more significant digits and a decimal point. May have as many as 17 significant digits. Range As in single precision constants Example 3.76324523, 0.9987698543574532, 1.6578438D-12
  • 12. 1. NUMERIC CONSTANTS - 3 TYPE DECLARATION TAGS The type of a number can be indicated by a type declaration tag: TYPE TAG EXAMPLE 1. Integer % 3%, 564% 2. Single precision ! 1.34! , 43.7865!, 23.56E-8 3. Double precision # 3.4567#, 2.67D+21
  • 13. 2. VARIABLES - 1 RULES FOR NAMING OF VARIABLES 1. Characters must be alphanumeric,i.e., use alphabetic (A-Z) and numeral (0 – 9) characters only. 2. First character must be a letter. 3. Variable name may contain as many as 40 characters. No blank spaces in a name. Note: Use variable names which reflect the data stored in the variable. Also, long variable names are not practical or advisable to use in a program.
  • 14. 2. VARIABLES - 2 Variables in Gwbasic and other programming languages are classified according to the data they store. We have the following types in Gwbasic: Variable type Type declaration tag Example 1. Integer % J%, KK%, ICT% 2. Single ! X!, A7!, DIST! 3. Double # XJ23#, AREA# 4. String $ TITLE$, A5B$ 5. Note: String variables in Gwbasic are initialized to the null character “ “. The other variables are initialized to 0.
  • 15. 2. VARIABLES - 3 VARIABLE DECLARATION 1. Each variable must be assigned a type. 2. In general, however, it is not necessary to worry about variable type declaration in a program. Gwbasic adopts an implicit declaration of variables: variable names which end with the $ tag are declared string variables; variable names which do not end in any tag character are declared variable names of type SINGLE. 3. Explicit variable type declaration can be accomplished using either the type declaration tags (%.!,#,$) or the DEFtype statements.
  • 16. 2. VARIABLES - 4 EXAMPLES – EXPLICIT VARIABLE TYPE DECLARATION 1. Using the tag characters – A%, ITEM$, Y!, BBC# 2. Using the DEFtype statements – put these statements at the beginning of the program. DEFINT B-F, L-M, P This means that all variable names which begin with the letters B to F, L to M, and P are to be treated as integer variables, that is, the values they store are integer constants. DEFSNG, DEFDBL, DEFSTR statements for single, double, and string variables respectively follow the same syntax. Note: Tag characters override DEFtype statements.
  • 17. 2. VARIABLES - 5 SUBSCRIPTED VARIABLES The purpose is to use the same variable name to refer to a collection of data or numbers. Example: X(I), I = 1, 10 A(K , L ), K = 1,10 , L = 1, 25 Here , X is a one-dimensional array while A is a two- dimensional array. The dimensions or sizes of the arrays are communicated to the computer by using the DIM statement: 10 DIM X(10), A(10,25) Note:Put DIM statements at the beginning of the program.
  • 18. 3. OPERATIONS - 1 1. 1. Hierarchy of operations: list is of descending priority 2. Operation Symbol Example Exponentiation ^ 2^15, X^5, 5.12^(1/3) Multiplication, division *, / X*Y, A/2.35 Integer division 32, 92 Remainder in integer MOD 8 MOD 3 division Addition,subtraction +, - 6.7 +89.3 – 5.7
  • 19. 3. OPERATIONS - 2 2. Arithmetic operations are carried out LEFT to RIGHT. 3. Use parentheses whenever their use will help clarify the order of the operations that must be carried out. Inner parentheses are calculated first. Examples 3.6*89.2+6^3-8.7+2.3-1.9 ((2.8-3.5*6)/3.9)-(2.7/3.8+43.3) 4. Algebraic expressions are constructed using the numeric constants,variables and the arithmetic operations discussed above. Built-in mathematical functions in Gwbasic enlarge the kind of algebraic expressions we can employ in a program.
  • 20. BUILT-IN FUNCTIONS - 1 FUNCTION SYNTAX 1. Sine SIN(X) , X in radians 2. Cosine COS(X) 3. Tangent TAN(X) 4. Arc tangent ATN(X) 5. Square root SQR(X) , X >= 0 6. Exponential EXP(X) 7. Natural logarithm LOG(X) , X > 0
  • 21. BUILT-IN FUNCTIONS - 2 FUNCTION SYNTAX 8. Absolute value ABS(X) 9. Greatest integer INT(X) less than or equal to X 10. Remove decimal FIX(X) part of a number 11. Remove the number SGN(X) but keep its sign
  • 22. BUILT-IN FUNCTIONS - 3 FUNCTION SYNTAX 12. Convert X to integer constant CINT(X) 13. Convert X to single precision CSNG(X) constant 14. Convert X to double precision CDBL(X) constant
  • 23. 4. RULES By this we mean the specific procedures that we must use in order to correctly translate our code into a language the computer can understand. We have seen several of these rules. Other rules relating to the various constructs of Gwbasic may be found in the appropriate sections of the manual you downloaded from the internet.
  • 24. 5. STRUCTURE The structure for the various commands will be discussed when we get to them. However,the structure or layout of a Gwbasic program should look like the one below: 10 ‘Program documentation 20 ‘Main program - dimension, type and user-defined function statements 30 ‘Subroutines 40 ‘Data statements 50 ‘End statement
  • 25. INPUT/OUTPUT STATEMENTS - 1 The purpose of these statements is to receive data for computer processing and to output the results generated by the program. Input statements 1. INPUT - gets input data from keyboard. 100 INPUT X,Y, Z, AY$ 20 INPUT “IFLAG=“; IFLAG 2. READ and DATA statements come together. 50 READ X, T, N$, H ‘ 100 DATA 10.3, 25.6, “argon”, 234.1
  • 26. INPUT/OUTPUT STATEMENTS - 2 Output statements 1. PRINT - prints output to the screen. 100 PRINT A 50 PRINT TITLE$ 350 PRINT TAB(5);X;TAB(15);Y 2. PRINT USING - for formatting output 120 PRINT USING “##.###”;A 70 PRINT USING “A= ##.### J=###”;A,J 3. LPRINT - as above, but print is transferred to the line printer for a hardcopy. 4. LPRINT USING - as in no. 3 above.
  • 27. CONTROL STATEMENTS - 1 There are four control statements in Gwbasic: FOR- NEXT, GOTO, IF-THEN, and IF-THEN-ELSE. 1. FOR-NEXT - for repetitive calculations. Syntax line # FOR X = X1 TO X2 [STEP X3] line # statement 1 ‘ line # statement n line # NEXT X Note: The default value of the increment X3 is 1 if the optional bracketed expression is omitted.
  • 28. CONTROL STATEMENTS - 2 Example : FOR-NEXT statement 120 FOR J = 1 TO 50 130 K = 3*J+1 140 PRINT “J =“;J;TAB(12);”K =“;K 150 NEXT J ------------------------------------------------------------------- 20 SUM = 0. : KF%= 12 : KL% = 32 : KDEL% = 5 30 FOR K% = KF% TO KL% STEP KDEL% 40 SUM = SUM + 2.87*CSNG(K%)^3 50 NEXT K%
  • 29. CONTROL STATEMENTS - 3 Example: nested FOR-NEXT statements 10 DIM A(50), B(50,20), C(50) ‘ 40 FOR N = 1 TO 30 STEP 3 50 X = A(N)^2 + 3.87 60 FOR L = 1 TO 10 70 B(N, L) = A(N)*C(L) *X + COS(X)/LOG(X-1.05) 80 NEXT L 90 NEXT N ‘
  • 30. CONTROL STATEMENTS - 4 2. GOTO statement - for unconditional transfer of control Syntax line # GOTO line # Example 120 GOTO 230 70 GOTO 10
  • 31. CONTROL STATEMENTS - 5 3. IF-THEN statement Relational operators Symbol Equal = Less than < Greater than > Less than or equal to <= Greater than or equal to >= These operators are used in the argument of the IF statement to determine the flow of control.
  • 32. CONTROL STATEMENTS - 6 Compound relational operators: AND , OR Simple relational expression - involves a single relational operator: A > 12, B<= 3. Complex relational expression - involves several simple relational expressions joined by the relational operators AND and OR. Examples: (A>8) AND (C<2) This is true if both expressions are true; false otherwise. (A>8) OR (C<2) This is true provided one or the other of the two expressions is true; false otherwise.
  • 33. More in the next part…..