SlideShare a Scribd company logo
1 of 21
QBasic andQBasic and
ProgrammingProgramming
PresentationPresentation
Prepared by:
Obusan, Janssen Roselle T.
Opiana, Christian Joseph I.
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.
RulesRules and Itsand 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.
DataData
(A collection of facts and figures that is entered into the computer.)(A collection of facts and figures that is entered into the 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”
ModesModes
(QBasic can be made to translate your instructions in two modes.)(QBasic can be made to translate your instructions in two modes.)
Direct
Mode
Progra
m 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.
Keywords and their FunctionsKeywords and their Functions
LIST
Used to list the
programs on the
screen.
RUN
Used to execute
the program.
LLIST
Used to list the
program as a
hardcopy.
LPRINT
Used to get the
output of the program
on the hard copy.
NEW
Used to clear the
memory of a existing
program.
Keywords and their FunctionsKeywords and their Functions
SYSTEM
Used to take
you back to dos
prompt.
PRINT & CLS
Print is used to
display on screen.
CLS is used to clear
the screen.
RME
Used to show the
position of the
mistake.
SAVE
Used to save the
program.
LOAD
Used to load the
program from the
disk to the memory.
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.
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.
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.
When the PRINT command,When the PRINT command,
you can also print NUMBERSyou can also print NUMBERS
to the screen. Delete theto the screen. Delete the
current program (unless youcurrent program (unless you
already have) and write thealready have) and write the
following:following:
PRINT 512 (or ?512)PRINT 512 (or ?512)
<press enter><press enter>
Press F5 to run the program.Press F5 to run the program.
The program outputs:The program outputs:
512512
COMMANDSCOMMANDS
There are also specialThere are also special
functions calledfunctions called
“COMMANDS” (also“COMMANDS” (also
calledcalled
“INSTRUCTIONS”). A“INSTRUCTIONS”). A
“COMMAND” tells the“COMMAND” tells the
QBASIC interpreter to doQBASIC interpreter to do
something.something.
The PRINT commandThe PRINT command
tells the QBASICtells the QBASIC
interpreter to printinterpreter to print
something on the screen.something on the screen.
In this case, theIn this case, the
interpreter printedinterpreter printed
“HELLO WORLD!”.“HELLO WORLD!”.
TIP: Instead of typing
PRINT, you can enter a
question mark. For
example:
?“HELLO WORLD!”
EXPRESSIONSEXPRESSIONS
An expression is something the interpreterAn expression is something the interpreter
calculates (or evaluates). Such as:calculates (or evaluates). 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)
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+478
OUTPUT
512+478
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=
ACTIVITY(Continuation)ACTIVITY(Continuation)
2. EXPRESS IN INTEGER OR DECIMAL2. 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
RETRIEVING KEYBOARDRETRIEVING 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$
To receive a number, use aTo receive a number, use a
non-string variable.non-string variable.
INPUT numberINPUT number
PRINT numberPRINT number
If you enter text instead of aIf you enter text instead of a
number, the QBASICnumber, the QBASIC
interpreter displays an errorinterpreter displays an error
message (“Redo frommessage (“Redo from
start”).start”).
RETRIEVING KEYBOARDRETRIEVING 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 num
PRINT text$
PRINT num
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=5
IF X=5 THEN PRINT “ X equals
5”
Since X does equal 5 in this
case, the program outputs:
X equals 5
EXPRESSION SIGNS
You 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=16
IF(X>5) THEN PRINT “X is
greater than 5”
THE IF AND THEN COMMANDSTHE IF AND THEN COMMANDS
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:
CLS
X=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
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.
Prepared by:Prepared by:
Obusan, Janssen Roselle T.Obusan, Janssen Roselle T.
Opiana, Christian Joseph I.Opiana, Christian Joseph I.

More Related Content

What's hot

Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingNeeru Mittal
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languagesVarun Garg
 
Basic Computer Programming
Basic Computer ProgrammingBasic Computer Programming
Basic Computer ProgrammingAllen de Castro
 
2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problemFrankie Jones
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming conceptssalmankhan570
 
Intro to programming and how to start that career
Intro to programming and how to start that careerIntro to programming and how to start that career
Intro to programming and how to start that careerTarek Alabd
 
Curriculum guide ICT 7
Curriculum guide ICT 7Curriculum guide ICT 7
Curriculum guide ICT 7Annie Elloren
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & LanguagesGaditek
 
Using Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart SymbolsUsing Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart SymbolsAr Kyu Dee
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
 
Introduction to Basic Computer Concepts Presentation
Introduction to Basic Computer Concepts PresentationIntroduction to Basic Computer Concepts Presentation
Introduction to Basic Computer Concepts PresentationAna Tan
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentationfazli khaliq
 
Keyboard and-proper-finger-positioning
Keyboard and-proper-finger-positioningKeyboard and-proper-finger-positioning
Keyboard and-proper-finger-positioningJaleto Sunkemo
 

What's hot (20)

Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Basic Computer Programming
Basic Computer ProgrammingBasic Computer Programming
Basic Computer Programming
 
2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
 
Intro to programming and how to start that career
Intro to programming and how to start that careerIntro to programming and how to start that career
Intro to programming and how to start that career
 
Curriculum guide ICT 7
Curriculum guide ICT 7Curriculum guide ICT 7
Curriculum guide ICT 7
 
History of programming
History of programmingHistory of programming
History of programming
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Qbasic Tutorial
Qbasic TutorialQbasic Tutorial
Qbasic Tutorial
 
Using Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart SymbolsUsing Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart Symbols
 
Rubric
RubricRubric
Rubric
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Introduction to Basic Computer Concepts Presentation
Introduction to Basic Computer Concepts PresentationIntroduction to Basic Computer Concepts Presentation
Introduction to Basic Computer Concepts Presentation
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentation
 
Keyboard and-proper-finger-positioning
Keyboard and-proper-finger-positioningKeyboard and-proper-finger-positioning
Keyboard and-proper-finger-positioning
 

Viewers also liked

K-12 Module in TLE - ICT Grade 9 [All Gradings]
K-12 Module in TLE - ICT Grade 9 [All Gradings]K-12 Module in TLE - ICT Grade 9 [All Gradings]
K-12 Module in TLE - ICT Grade 9 [All Gradings]Daniel Manaog
 
Self Review Framework The ICT Technicians View
Self Review Framework The ICT Technicians ViewSelf Review Framework The ICT Technicians View
Self Review Framework The ICT Technicians ViewRussell Dyas
 
A national framework for ICT Quality in VET
A national framework for ICT Quality in VETA national framework for ICT Quality in VET
A national framework for ICT Quality in VETAnthony Fisher Camilleri
 
Computer Hardware-servicing-learning-module
Computer Hardware-servicing-learning-moduleComputer Hardware-servicing-learning-module
Computer Hardware-servicing-learning-moduleBogs De Castro
 
Computer Hardware Servicing Learning Module v.2.0
Computer Hardware Servicing Learning Module v.2.0Computer Hardware Servicing Learning Module v.2.0
Computer Hardware Servicing Learning Module v.2.0Bogs De Castro
 
K-12 Module in TLE - ICT Grade 10 [All Gradings]
K-12 Module in TLE - ICT  Grade 10 [All Gradings]K-12 Module in TLE - ICT  Grade 10 [All Gradings]
K-12 Module in TLE - ICT Grade 10 [All Gradings]Daniel Manaog
 
Core Values and Related Values in the DepEd Framework of Values Education
Core Values and Related Values in the DepEd Framework of Values EducationCore Values and Related Values in the DepEd Framework of Values Education
Core Values and Related Values in the DepEd Framework of Values EducationRamil Gallardo
 

Viewers also liked (9)

K-12 Module in TLE - ICT Grade 9 [All Gradings]
K-12 Module in TLE - ICT Grade 9 [All Gradings]K-12 Module in TLE - ICT Grade 9 [All Gradings]
K-12 Module in TLE - ICT Grade 9 [All Gradings]
 
Self Review Framework The ICT Technicians View
Self Review Framework The ICT Technicians ViewSelf Review Framework The ICT Technicians View
Self Review Framework The ICT Technicians View
 
A national framework for ICT Quality in VET
A national framework for ICT Quality in VETA national framework for ICT Quality in VET
A national framework for ICT Quality in VET
 
K to 12 pc hardware servicing teacher's guide
K to 12 pc hardware servicing teacher's guideK to 12 pc hardware servicing teacher's guide
K to 12 pc hardware servicing teacher's guide
 
K to 12 PC Hardware Servicing Learning Module
K to 12 PC Hardware Servicing Learning ModuleK to 12 PC Hardware Servicing Learning Module
K to 12 PC Hardware Servicing Learning Module
 
Computer Hardware-servicing-learning-module
Computer Hardware-servicing-learning-moduleComputer Hardware-servicing-learning-module
Computer Hardware-servicing-learning-module
 
Computer Hardware Servicing Learning Module v.2.0
Computer Hardware Servicing Learning Module v.2.0Computer Hardware Servicing Learning Module v.2.0
Computer Hardware Servicing Learning Module v.2.0
 
K-12 Module in TLE - ICT Grade 10 [All Gradings]
K-12 Module in TLE - ICT  Grade 10 [All Gradings]K-12 Module in TLE - ICT  Grade 10 [All Gradings]
K-12 Module in TLE - ICT Grade 10 [All Gradings]
 
Core Values and Related Values in the DepEd Framework of Values Education
Core Values and Related Values in the DepEd Framework of Values EducationCore Values and Related Values in the DepEd Framework of Values Education
Core Values and Related Values in the DepEd Framework of Values Education
 

Similar to Computer programming k 12

Introduction to Programming and QBasic Tutorial
Introduction to Programming and QBasic TutorialIntroduction to Programming and QBasic Tutorial
Introduction to Programming and QBasic Tutorialnhomz
 
Basic computer-programming-2
Basic computer-programming-2Basic computer-programming-2
Basic computer-programming-2lemonmichelangelo
 
QBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingQBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingGifty Belle Manaois
 
QBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingQBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingGifty Belle Manaois
 
COMPUTER PROGRAMMING
COMPUTER PROGRAMMINGCOMPUTER PROGRAMMING
COMPUTER PROGRAMMINGarisamae1114
 
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1ILearn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1Ilivecoding.tv
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language ProgrammingNiropam Das
 
Map reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICSMap reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICSArchana Gopinath
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programmingDamian T. Gordon
 
Algorithm Design and Problem Solving [Autosaved].pptx
Algorithm Design and Problem Solving [Autosaved].pptxAlgorithm Design and Problem Solving [Autosaved].pptx
Algorithm Design and Problem Solving [Autosaved].pptxKaavyaGaur1
 

Similar to Computer programming k 12 (20)

Qbasic tutorial
Qbasic tutorialQbasic tutorial
Qbasic tutorial
 
Introduction to Programming and QBasic Tutorial
Introduction to Programming and QBasic TutorialIntroduction to Programming and QBasic Tutorial
Introduction to Programming and QBasic Tutorial
 
The Knowledge of QBasic
The Knowledge of QBasicThe Knowledge of QBasic
The Knowledge of QBasic
 
Basic computer-programming-2
Basic computer-programming-2Basic computer-programming-2
Basic computer-programming-2
 
QBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingQBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern Programming
 
QBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingQBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern Programming
 
COMPUTER PROGRAMMING
COMPUTER PROGRAMMINGCOMPUTER PROGRAMMING
COMPUTER PROGRAMMING
 
programming.ppt
programming.pptprogramming.ppt
programming.ppt
 
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1ILearn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
 
Programming
ProgrammingProgramming
Programming
 
Qbasic program
Qbasic programQbasic program
Qbasic program
 
Qbasic
QbasicQbasic
Qbasic
 
Basic programming
Basic programmingBasic programming
Basic programming
 
Programming : QBASIC
Programming : QBASICProgramming : QBASIC
Programming : QBASIC
 
Qbasic
QbasicQbasic
Qbasic
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language Programming
 
Map reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICSMap reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICS
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programming
 
Algorithm Design and Problem Solving [Autosaved].pptx
Algorithm Design and Problem Solving [Autosaved].pptxAlgorithm Design and Problem Solving [Autosaved].pptx
Algorithm Design and Problem Solving [Autosaved].pptx
 
A tutorial on C++ Programming
A tutorial on C++ ProgrammingA tutorial on C++ Programming
A tutorial on C++ Programming
 

Computer programming k 12

  • 1. QBasic andQBasic and ProgrammingProgramming PresentationPresentation Prepared by: Obusan, Janssen Roselle T. Opiana, Christian Joseph I.
  • 2. 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.
  • 3. RulesRules and Itsand 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.
  • 4. DataData (A collection of facts and figures that is entered into the computer.)(A collection of facts and figures that is entered into the 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”
  • 5. ModesModes (QBasic can be made to translate your instructions in two modes.)(QBasic can be made to translate your instructions in two modes.) Direct Mode Progra m 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.
  • 6. Keywords and their FunctionsKeywords and their Functions LIST Used to list the programs on the screen. RUN Used to execute the program. LLIST Used to list the program as a hardcopy. LPRINT Used to get the output of the program on the hard copy. NEW Used to clear the memory of a existing program.
  • 7. Keywords and their FunctionsKeywords and their Functions SYSTEM Used to take you back to dos prompt. PRINT & CLS Print is used to display on screen. CLS is used to clear the screen. RME Used to show the position of the mistake. SAVE Used to save the program. LOAD Used to load the program from the disk to the memory.
  • 8. 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.
  • 9. 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.
  • 10. 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.
  • 11. When the PRINT command,When the PRINT command, you can also print NUMBERSyou can also print NUMBERS to the screen. Delete theto the screen. Delete the current program (unless youcurrent program (unless you already have) and write thealready have) and write the following:following: PRINT 512 (or ?512)PRINT 512 (or ?512) <press enter><press enter> Press F5 to run the program.Press F5 to run the program. The program outputs:The program outputs: 512512 COMMANDSCOMMANDS There are also specialThere are also special functions calledfunctions called “COMMANDS” (also“COMMANDS” (also calledcalled “INSTRUCTIONS”). A“INSTRUCTIONS”). A “COMMAND” tells the“COMMAND” tells the QBASIC interpreter to doQBASIC interpreter to do something.something. The PRINT commandThe PRINT command tells the QBASICtells the QBASIC interpreter to printinterpreter to print something on the screen.something on the screen. In this case, theIn this case, the interpreter printedinterpreter printed “HELLO WORLD!”.“HELLO WORLD!”. TIP: Instead of typing PRINT, you can enter a question mark. For example: ?“HELLO WORLD!”
  • 12. EXPRESSIONSEXPRESSIONS An expression is something the interpreterAn expression is something the interpreter calculates (or evaluates). Such as:calculates (or evaluates). 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)
  • 13. 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+478 OUTPUT 512+478
  • 14. 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=
  • 15. ACTIVITY(Continuation)ACTIVITY(Continuation) 2. EXPRESS IN INTEGER OR DECIMAL2. 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
  • 16. RETRIEVING KEYBOARDRETRIEVING 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$
  • 17. To receive a number, use aTo receive a number, use a non-string variable.non-string variable. INPUT numberINPUT number PRINT numberPRINT number If you enter text instead of aIf you enter text instead of a number, the QBASICnumber, the QBASIC interpreter displays an errorinterpreter displays an error message (“Redo frommessage (“Redo from start”).start”). RETRIEVING KEYBOARDRETRIEVING 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 num PRINT text$ PRINT num
  • 18. 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=5 IF X=5 THEN PRINT “ X equals 5” Since X does equal 5 in this case, the program outputs: X equals 5 EXPRESSION SIGNS You 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=16 IF(X>5) THEN PRINT “X is greater than 5”
  • 19. THE IF AND THEN COMMANDSTHE IF AND THEN COMMANDS 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: CLS X=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
  • 20. 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.
  • 21. Prepared by:Prepared by: Obusan, Janssen Roselle T.Obusan, Janssen Roselle T. Opiana, Christian Joseph I.Opiana, Christian Joseph I.