BASIC programming language presentation.pptx

ChineduFrancisNjeman 26 views 12 slides Sep 20, 2024
Slide 1
Slide 1 of 12
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12

About This Presentation

BASIC program note for year 8


Slide Content

BASIC PROGRAMMING BASIC statements.

Lesson Objectives: At the end of the lesson, I should be able to: 1. List key statements of BASIC and their functions. 2. List some BASIC library functions. 3. Write simple BASIC programs .

Identify the differences between the two pictures

BASIC Statements A statement is a set of instructions written by using keywords or commands of QBASIC. Every programming language uses keywords as a statement with certain syntax. The keywords have specific meaning in the QBASIC programming. The statements are the first stored in the memory and executed only when the RUN command is given.

Key Statements of BASIC LET Statement – The LET statement is used to assign a numeric or string value to a variable. For example: LET X = 12 LET AREA = *RADIUS^2 LET STR$ = FIRST$ + LAST$ INPUT Statement – It is used to enter numeric or string data into a computer during program execution. E.g : INPUT A, B, C INPUT N$, M$, Factor

Example:   10 CLS 20 INPUT “First Number”; A 30 INPUT “Second Number”; B 40 LET Sum = A+B 50 PRINT “The Sum is ”; S END

PRINT Statement – PRINT statement provides output on the screen. It prints the values of the expression on the screen. If the expression list is blank, no characters are printed. Example: PRINT A, B, C PRINT “I Like Writing Programs” REMARK Statement – It is a BASIC declaration statement that allows explanatory remarks to be inserted in a program. Example: REM To print a message STOP and END Statement – The STOP statement is used to terminate the execution (of a program) at any point in the program. The END statement indicates the actual end of a program. Example: 10 REM END Statement 20 PRINT “Morning” 30 END

GOTO Statement - This statement transfers program control from the line number that contains the statement to the specified number after the GOTO statement. The format is: 10 REM GOTO Statement 20 GOTO 40 30 PRINT “Morning” Others include: DATA statement IF-THEN Statement IF-THEN-ELSE Statement FOR NEXT Statement

BASIC Library Functions These functions provides quick and easy way to carry out mathematical operations, to manipulate string data and to perform certain logical operations. Example : Functions Application Description SQR LET Y = SQR (x) Returns the square root to y=√x ABS LET Y = ABS (x) Returns the absolute value of x, Y=(x) SIN LET Y = SIN (x) Returns sine of x LOG LET Y = LOG (x) Returns the logarithm of x UCASE$ LET Y& = UCASE (X$) Returns upper case of X$ LCASE$ LET Y& = LCASE (X$) Returns lower case of X$

SAMPLE PROGRAM The following are examples of sample programs. Sample 1: To find the average of four numbers Solution : 10 REM Program to find Average of four numbers given 20 INPUT A, B, C, D 30 LET SUM = A + B + C + D 40 LET AVERAGE = Sum/4 50 PRINT Average 60 END

Sample 2: a program to calculate area/perimeter Solution : 10 REM Program to calculate area and perimeter 20 PRINT “Rectangle Calculator” 30 PRINT “_____________” 40 PRINT “Enter length” 50 INPUT length 60 PRINT “Enter width” 70 INPUT width 80 LET area = length * width 90 LET perimeer = 2 * (length + width) 100 PRINT “Area: ”; area 110 PRINT “Perimeter: ”; perimeter 120 END

Sample 3: Program to evaluate the roots of a quadratic equation. Solution 10 REM Roots of a Quadratic Equation 20 PRINT “a = ”, 30 INPUT a 40 PRINT “b = ”, 50 INPUT b 60 PRINT “c = ”, 70 INPUT c 80 LET Root = SQR (b^2 – 4*a*c) 90 LET x 1 = (-b + root)/(2*a) 100 LET x 2 = (-b – root)/(2*a) 110 PRINT “x 1 = ”, x 1 ; TAB (20); “x 2 = ”, x 2 120 END
Tags