introduction to qbasic

Download Introduction to QBasic

Post on 31-Oct-2014

611 views

Category:

Documents

29 download

Embed Size (px)

DESCRIPTION

History of Basic.History of QBasic.Flowchart Programming.Beginner QBasic commands.

TRANSCRIPT

Programming WHY?

To make a computer useful.

BASIC Programming WHY?to give students a simple programming language that was easy-to-learn

History of BASICBASIC was invented at Dartmouth College in 1964 by John Kemeny and Thomas Kurtz

The official languages at that time were, Fortran and Algol used only by professionals.Thomas Kurtz / John Kemeny

History of QbasicQuick Beginner All Purpose Symbolic Instruction Code

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.

Terms* 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.

Course Notes

Terms* STATEMENT A FUNCTION procedure. Tells the computer what action to take. * VARIABLE A name for a value stored in the computers memory. It may be numbers or characters. Variable types: $ String, % Integer, & Long, ! Single, # Double, ## _FLOAT

Course Notes

Terms* 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.

Course Notes

TEXTBOOK TERMS* 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

Course Notes

COURSE WORKFLOWLECTURE 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.

LABS ARE GRADED

Course Notes

Programming ProcessThe process of developing a computer program to solve a specific problem involves the following steps : Step : 1 : Problem Definition Step : 2 : Program Design Step : 3 : Program Coding Step : 4 : Program Execution Step : 5 : Program Testing and Debugging REPEAT STEP 5 Step : 6 : Program Documentation

Structure of a Qbasic Program 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.

Sample Qbasic ProgramREM MY FIRST QBASIC PROGRAM CLS PRINT WELCOME TO QBASIC PROGRAMMING PRINT This is my first QBasic program END

Using Qbasic EditorStart a Qbasic session. REM MY FIRST QBASIC PROGRAM CLS PRINT 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(:).

CLS StatementCLS 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 graphicsCLS 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.

PRINT StatementPRINT : 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] [{; | ,}]

END StatementEND Statement: Ends a program, procedure, block, or user-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.

RND VariableRND Statement: Generates a pseudo-random number between 0 and 1. Pseudo-random because it allows starts in the same place. Syntax : RNDCLS PRINT RND vs. CLS DO PRINT RND SLEEP 2 CLS LOOP CLS DO PRINT 15 * RND SLEEP 2 CLS LOOP

vs.

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).Standard 16 colors 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

COLOR StatementCLS COLOR 2 PRINT Welcome to Qbasic END

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

CLS LOCATE 10,40 PRINT X MARKS THE SPOT END

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.

DOLOOP StatementDOLOOP 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 DOWHILE or UNTIL LOOP DOLOOPEntry Entry DO

DO

FalseLOOP

DO Loop Continuation Condition

TrueLOOP

Exit

Exit

DOLOOP StatementDOLOOP

REM Press Ctrl|Break to end CLS DO COLOR 15*RND vs. PRINT Welcome SLEEP 2 CLS LOOP END

DO UNTILLOOP CLS A=0 DO UNTIL A = 10 A = A + 10 COLOR 15*RND PRINT Welcome PRINT A SLEEP 2 CLS LOOP CLS PRINT Program complete END

THE REST OF CLASS PRERIOD1) COPY Qbasic to your stick 2) Read Chapters 1 and 2 3) Work through exercises 4) Know the KEYWORDS at chapter end 5) Complete Labs 1 and 2 for grading SAVE labs to your stick

CHECK OUT THIS WEBSITE http://www.qbasicstation.com/