21
QBasic and QBasic and Programming Programming Presentation Presentation Prepared by: Obusan, Janssen Roselle T. Opiana, Christian Joseph I.

Computer programming k 12

Embed Size (px)

Citation preview

Page 1: Computer programming k 12

QBasic and QBasic and Programming Programming PresentationPresentation

Prepared by:Obusan, Janssen Roselle T.

Opiana, Christian Joseph I.

Page 2: Computer programming k 12

QBasic

It all started back in 1963 when John Goerge Kemeny and Tom Kurtzas got together at Dartmouth College.

It is an interpreter which reads every line, translates it and lets the computer execute it.

NOTE: BASIC stands for Beginner’s All Purpose Instruction Code.

Page 3: Computer programming k 12

RulesRules and Its and Its FeatureFeature

QBasic programs are executed in the order which they are written.

Every statement should have at

least one QBasic command.

All commands have to be written using the Syntax Rules. Syntax is the grammar of

writing.

It is a user friendly

language.

It is widely known and accepted

programming language.

It is one of the most flexible languages, as

modification can easily be done.

Language is easy since the

variables can be named easily

and uses simple English phrases.

Page 4: Computer programming k 12

DataData(A collection of facts and figures that is entered into the (A collection of facts and figures that is entered into the

computer.)computer.)

CONSTANTCONSTANT

(Data whose values do not change)

Numeric Constant(numbers – negative or positive – used for mathematics)

e.g. 100

Alphanumeric Constant/String(numbers of alphabets written within double quoutes)

e.g. “computer”

VARIABLEVARIABLE

(Data whose values can change fue to some calculation)

Numeric Variable(numbers that are constant for arithmetic)

e.g. A = 50

Alphanumeric Variable(variable that holds an Alphanumeric constant)

e.g. Name$ = “Akanksha”

Page 5: Computer programming k 12

Modes Modes (QBasic can be made to translate your instructions in two (QBasic can be made to translate your instructions in two

modes.)modes.)

Direct

Mode

Program

Mode

Accepts single line instructions from the user and the output is viewed as soon as the key is pressed.

This mode is used to types a program which is stored in the memory. They have line numbers. We have to give the command to get the output.

Note: Every programming language has its own SYNTAX (rules) and COMMANDS.

Page 6: Computer programming k 12

Keywords and their FunctionsKeywords and their Functions

LISTUsed to list

the programs on the screen.

RUNUsed to

execute the program.

LLISTUsed to list the program

as a hardcopy.

LPRINTUsed to get the output of the

program on the hard copy.

NEWUsed to clear the

memory of a existing program.

Page 7: Computer programming k 12

Keywords and their FunctionsKeywords and their Functions

SYSTEMUsed to take you back to dos prompt.

PRINT & CLSPrint is used to

display on screen.CLS is used to

clear the screen.

RMEUsed to show the position of the mistake.

SAVEUsed to save the program.

LOADUsed to load the

program from the disk to the memory.

Page 8: Computer programming k 12

QBasic CommandsQBasic Commands

CLS

This command is used to clear the screen.

PRINT

This command is used to display the output on the screen.

REM

It stands for ‘remark’. It makes the program

more understandable to the reader.

LET

It assigns a value to a variable in a program.

NOTE: A numeric data should be assigned to a numeric variable and aplhanumeric data to an alphanumeric variable.

Page 9: Computer programming k 12

QBasic CommandsQBasic Commands

END

This command is usually given at the end of the program.

INPUT

It allows the user to enter a value for the variable while running the program.

DELETE

To delete a line number in a program.

Page 10: Computer programming k 12

QBasic Reminders!QBasic Reminders!

A program consists of a line

number.

It contains keywords like:

PRINT, END etc.

Each program line begins with

positive number.

Run is used to execute a program.

It is possible to overwrite a statement but if you want to write a new program, use the

NEW command.

To exit the QBasic program, SYSTEM command is used.

NO TWO LINES

SHOULD HAVE SAME NUMBER.

Page 11: Computer programming k 12

When the PRINT command, When the PRINT command, you can also print you can also print NUMBERS to the screen. NUMBERS to the screen. Delete the current Delete the current program (unless you program (unless you already have) and write already have) and write the following:the following:

PRINT 512 (or ?512)PRINT 512 (or ?512)

<press enter><press enter>

Press F5 to run the Press F5 to run the program. The program program. The program outputs: outputs:

512512

COMMANDSCOMMANDS

There are also special There are also special functions called functions called “COMMANDS” (also “COMMANDS” (also called called “INSTRUCTIONS”). A “INSTRUCTIONS”). A “COMMAND” tells the “COMMAND” tells the QBASIC interpreter to QBASIC interpreter to do something.do something.

The PRINT command The PRINT command tells the QBASIC tells the QBASIC interpreter to print interpreter to print something on the something on the screen. In this case, screen. In this case, the interpreter printed the interpreter printed “HELLO WORLD!”.“HELLO WORLD!”.

TIP: Instead of typing

PRINT, you can enter a

question mark. For

example:

?“HELLO WORLD!”

Page 12: Computer programming k 12

EXPRESSIONSEXPRESSIONS

An expression is something the An expression is something the interpreter calculates (or evaluates). interpreter calculates (or evaluates). Such as:Such as:

1+11+1 (returns 2)(returns 2)100-147100-147 (returns 53)(returns 53)3*343*34 (returns102)(returns102)80/480/4 (returns 20)(returns 20)(100*3)+56(100*3)+56 (returns 356)(returns 356)

Page 13: Computer programming k 12

If you pass an expression to the PRINT command, the value

returned (a number) is printed.

Clear the current program and then run the following:

PRINT 512+478

PROGRAM OUTPUT:990

if you enclose the expression with quotation marks, the expression becomes a string and isn’t evaluated. For example:

PRINT “512+478OUTPUT512+478

Page 14: Computer programming k 12

ACTIVITYACTIVITY

1.1. EVALUATE:EVALUATE:

A.A. 14/2-3*1=14/2-3*1=

B.B. 8*2/(5-1)=8*2/(5-1)=

C.C. 3+5^2*4=3+5^2*4=

D.D. 4+(3*2-1)^2/5=4+(3*2-1)^2/5=

Page 15: Computer programming k 12

ACTIVITY(Continuation)ACTIVITY(Continuation)

2. EXPRESS IN INTEGER OR DECIMAL 2. EXPRESS IN INTEGER OR DECIMAL FORMFORM

A.A.5.0D+7=5.0D+7=

B.B.-1.23D+03=-1.23D+03=

C.C.1.234D-04=1.234D-04=

D.D.4.26305D+084.26305D+08

Page 16: Computer programming k 12

RETRIEVING KEYBOARD RETRIEVING KEYBOARD INPUT FROM THE USERINPUT FROM THE USER

One way to receive input from the keyboard is with the INPUT command. The INPUT command allows the user to enter either a string or a number, which is then stored in a variable.INPUT data$PRINT data $

When is the program executed, the INPUT command displays a question mark, followed by a

blinking cursor. And when you enter text, the program stores that text into the variable data$, which

is printed to the screen.

TIP: if you place a string and a semi-colon between INPUT and the variable, the program will print the string.INPUT “ENTER SOME TEXT:”; data$

Page 17: Computer programming k 12

To receive a number, use To receive a number, use a non-string variable.a non-string variable.

INPUT numberINPUT number

PRINT numberPRINT number

If you enter text instead If you enter text instead of a number, the QBASIC of a number, the QBASIC interpreter displays an interpreter displays an error message (“Redo error message (“Redo from start”).from start”).

RETRIEVING KEYBOARD RETRIEVING KEYBOARD INPUT FROM THE USERINPUT FROM THE USER

Below is another example of the INPUT command:

PRINT “Enter some text:”INPUT text$

PRINT “Now enter a number:”

INPUT numPRINT text$PRINT num

Page 18: Computer programming k 12

THE IF AND THEN COMMANDS

The IF and THEN commands are used to compare an expression and then perform some task based on that expression.X=5IF X=5 THEN PRINT “ X equals 5”Since X does equal 5 in this case, the program outputs:

X equals 5

EXPRESSION SIGNSYou can also enter the following statements, instead of the equals sign:X<5 (x is less than 5)X>5 (x is greater than 5)Run the following: X=16IF(X>5) THEN PRINT “X is greater than 5”

Page 19: Computer programming k 12

THE IF AND THEN THE IF AND THEN COMMANDSCOMMANDS

You can also combine the signs like this:

x<=5 (x is less than or equal to 5)

X>=5 (x is greater than or equal to 5)

X<>5 (x does not equal to 5)

Run the following example:

CLSX=5

IF (X>=5) THEN PRINT “X is greater than equal to

5”IF (X<=5) THEN PRINT “X is less than or equal to 5”IF (X<>5) THEN PRINT “X

does not equal to 5”OUTPUT:

X is greater than or equal to 5

X is less than or equal to 5

Page 20: Computer programming k 12

ELSEELSE Using the ELSE command, you can

have the program perform a different action if the statement is

false.x=3

IF x=5 THEN PRINT “Yes” ELSE PRINT “No”

Since X doesn’t equal to 5, the output is:

No

END IF

END IF allows you to have multiple commands after the IF… THEN statement, but they must

start on the line after the IF statement. END IF should appear right after the list of commands.

Page 21: Computer programming k 12

Prepared by:Prepared by:Obusan, Janssen Roselle T.Obusan, Janssen Roselle T.Opiana, Christian Joseph I.Opiana, Christian Joseph I.