introduction to qbasic
Post on 31-Oct-2014
1.087 Views
Preview:
DESCRIPTION
TRANSCRIPT
To make a computer useful.
Programming – WHY?
BASIC Programming – WHY?to give students a simple programming language that was easy-to-learn
BASIC was invented at Dartmouth College in 1964 by John Kemeny and Thomas Kurtz
History of BASIC
The official languages at that time were, Fortran and Algol used only by
professionals.
Thomas Kurtz / John Kemeny
Qbasic as a replacement for BASIC, BASICA & GWBASIC is a user friendly, includes : * full screen syntax checking editor * multifile & multi window editing * No compiling step * Full debuging facilities * pull down menues, simple but powerfull menu structure can be selected by using either Key Board or Mouse.
History of Qbasic Quick Beginner All Purpose Symbolic Instruction Code
* ALGORITHM - An algorithm is a step-by-step list of directions that need to be followed to solve a problem.
* SYNTAX – The rules that govern the structure of source code.
* INTERPRETER - An interpreter reads the source code one instruction or line at a time, converts this line into machine code and executes it.
* COMPILER - A compiler reads the whole source code and translates it into a complete machine code program to perform the required tasks which is output as a new file.
Terms
Course Notes
* STATEMENT – A ‘FUNCTION’ procedure. Tells the computer what action to take.
* VARIABLE – A name for a value stored in the computer’s memory. It may be numbers or characters.Variable types: $ String, % Integer, & Long, ! Single, # Double, ## _FLOAT
Terms
Course Notes
* FLOWCHART - A flowchart is a type of diagram that represents an algorithm or process, showing the steps as boxes of various kinds, and their order by connecting these with arrows.
Terms
Course Notes
* GLOSSARY - A glossary is a list of words and what they mean. They are usually found at the end of a book or report that uses hard or special words to read.
* INDEX – An index is a system used to make finding information easier.
* APPENDIX – Contains ASCII CODES
TEXTBOOK TERMS
Course Notes
LECTURE – Introduce programming commands. Discuss examples. (May not cover all new commands in lecture – Follow your workbook)
TEXTBOOK – Read assigned chapters and work through exercises. Learn addition commands. Practice writing programs. Try and learn.
LABS –Write programs based on previous and new commands. Demonstrate to instructor.
COURSE WORKFLOW
Course Notes
LABS ARE GRADED
The process of developing a computer program to solve a specific problem involves the following steps :
Step : 1 : Problem DefinitionStep : 2 : Program DesignStep : 3 : Program CodingStep : 4 : Program ExecutionStep : 5 : Program Testing and DebuggingREPEAT STEP 5Step : 6 : Program Documentation
Programming Process
Qbasic editor is a full screen , context sensitive, syntax sensitive self – correcting tool for writing programs.
Using the editor is one of the simplest tasks. Qbasic is DOS based. All file and folder names
can only be 8 characters long and some symbols are restricted from use. Only use characters and numbers in your file names.
Structure of a Qbasic Program
REM MY FIRST QBASIC PROGRAMCLSPRINT “WELCOME TO QBASIC PROGRAMMING”PRINT “This is my first QBasic program ”END
Sample Qbasic Program
Start a Qbasic session.
Using Qbasic Editor
Qb.exe
REM MY FIRST QBASIC PROGRAMCLSPRINT “WELCOME TO QBASIC PROGRAMMING”PRINT “This is my first QBasic program ”END
REM VariableREM Statement : Allows explanatory remarks to be inserted in a program.
Syntax : REM text or ‘ text
* Remarks are ignored when the program runs unless they contain meta commands, which control the allocation of dimensional arrays. – ADVANCED PROGRAMMING
* A remark can be inserted on a line after an executable statement if it is preceded by the single-quote (') form of REM or if REM is preceded by a colon(:).
Qb.exe
CLS Statement : Clears the screen.
Syntax : CLS [{0 | 1 | 2}]
CLS : Clears either the text or graphics viewport
CLS 0: Clears the screen of all text and graphics
CLS 1: Clears the graphics viewport or the entire screen if no graphics viewport has been set
CLS 2: Clears the text viewport leaving the bottom line unchanged.
CLS Statement
Qb.exe
PRINT : PRINT writes data to the screen or to a file. Must be within quotations (“text”).
LPRINT: prints data on the printer LPT1.
Syntax: PRINT [#filenumber%,] [expressionlist][{; | ,}] LPRINT [expressionlist] [{; | ,}]
PRINT Statement
Qb.exe
END Statement: Ends a program, procedure, block, oruser-defined data type.
Syntax : END [{DEF | FUNCTION | IF | SELECT | SUB | TYPE}]
If no argument is supplied, END ends the program and closes all files.Used if want to stop the running of your program, even though there are more lines of commands. The END command will trick QBasic into thinking that there are no more lines to run and it will return you to the editor, this is applicable mainly in debugging.
END Statement
Qb.exe
RND VariableRND Statement: Generates a pseudo-random number between 0 and 1. Pseudo-random because it allows starts in the same place.
Syntax : RND
Qb.exe
CLSDOPRINT 15 * RNDSLEEP 2CLSLOOP
CLSDOPRINT RNDSLEEP 2CLSLOOP
vs.vs.
CLSPRINT RND
COLOR StatementSyntax: COLOR (foreground, background)Depends on screen modes (see p. 164)Default SCREEN MODE 0 - Text only: Color affects
text (foreground) and text line (background).
0 8
1 9
2 10
3 11
4 12
5 13
6 14
7 15
Standard 16 colors
COLOR StatementCLSCOLOR 2PRINT “Welcome to Qbasic”END
Qb.exe
LOCATE StatementLOCATE Statement: To set the cursor text cursor location, cursor visibility, and/or cursor size and height.Syntax: LOCATE [row][, [column][, [cursor][, [start][,[stop]]]]]
Any of the parameters may be omitted, and any that are take on the respective previous setting. To change only one setting, the appropriate number of preceding commas must be included in the syntax. The default settings are: LOCATE 1, 1, 1, 16, 15
The CLS statement will cause the row and column parameters to return to the default, (1, 1), with exception to the overriding settings made by VIEW PRINT.
LOCATE can be used to position the cursor at any location on the screen so that text characters can be displayed at that location using the PRINT statement. The row number ranges from 1 to 40 or 80, depending on the screen WIDTH. The column number ranges from 1 to 25, 30, 43, 50 or 60, depending on the screen height set by WIDTH:
LOCATE StatementOUTPUT SCREEN: 25 rows (lines) x 80 columns (printing positions)
CLS Statement clears screen and positions cursor at Location 1 ,1
CLSLOCATE 10,40PRINT “X MARKS THE SPOTEND
Qb.exe
SLEEP StatementSLEEP Statement: A control flow statement that suspends execution of the program.
Syntax : SLEEP [seconds]
If argument [seconds] is omitted program will suspend until a key is pressed or an enable event occurs.
If argument is used, program will suspend until seconds elapse, a key is pressed or an enable event occurs – whichever comes first.
Qb.exe
DO…LOOP StatementDO…LOOP Statement: A control flow statement that repeats a block of statements while a condition is true or until a condition becomes true.
Syntax 1: DO [{WHILE|UNTIL} boolean expression}] [statement block] LOOP
Syntax 2 : DO [statement block] LOOP [{WHILE|UNTIL} boolean expression}]
Basic Program Loop Structure
Entry
DO
LOOP
Exit
DO…LOOPEntry
DO LoopContinuation
Condition
TrueLOOP
False
Exit
DO…WHILE or UNTIL LOOP
DO
DO…LOOP Statement
vs.
REM Press Ctrl|Break to endCLSDOCOLOR 15*RNDPRINT “Welcome”SLEEP 2CLSLOOPEND
DO…LOOPCLSA = 0DO UNTIL A = 10A = A + 10COLOR 15*RNDPRINT “Welcome”PRINT ASLEEP 2CLSLOOPCLSPRINT “Program complete”END
DO UNTIL…LOOP
Qb.exe
CHECK OUT THIS WEBSITEhttp://www.qbasicstation.com/
1) COPY Qbasic to your ‘stick’2) Read Chapters 1 and 23) Work through exercises4) Know the KEYWORDS at chapter end5) Complete Labs 1 and 2 for grading
SAVE labs to your ‘stick’
THE REST OF CLASS PRERIOD
top related