1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
-
Upload
stuart-taylor -
Category
Documents
-
view
246 -
download
6
Transcript of 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
1© 2000 John Urrutia. All rights reserved.
Qbasic
Constructing Qbasic Programs
2© 2000 John Urrutia. All rights reserved.
Program DevelopmentProblem definition – statement
Who – The person, group, organization
What – The record, file, system, data
When – The timeframe
Where – The location
Why – The business reason
3© 2000 John Urrutia. All rights reserved.
Program DevelopmentProblem definition -
decompositionData
Input – what are the data sources.Output – what are the data sinks.
ProcessDetailed description of how the Input is
manipulated into Output.
4© 2000 John Urrutia. All rights reserved.
Program DevelopmentProgram design – Algorithm
Sequence – linear execution of instructions
Selection – Identify a processing pathBinaryCase
Iteration – repetitive execution of instructions
5© 2000 John Urrutia. All rights reserved.
Program DevelopmentProgram design – Flowcharts
A graphical representation of the problem definition
Process
Decision TerminationManual
Screen
6© 2000 John Urrutia. All rights reserved.
Program DevelopmentProgram design – Pseudocode
An English-like representation of the problem definition
IF the meat is green Thenmove it to the waste bucket
Else
move it to the good bucket
7© 2000 John Urrutia. All rights reserved.
Program DevelopmentImplementation – coding
The syntactical exercise of converting the program design into a specific programming language.
8© 2000 John Urrutia. All rights reserved.
Program DevelopmentV&V –Verification & Validation
Specification errors
Syntax errors
Logic errors
9© 2000 John Urrutia. All rights reserved.
Program DevelopmentDocumentation
Program - internal
User - external
10© 2000 John Urrutia. All rights reserved.
B. A. S. I. C.Beginners
All-purpose
Symbolic
Instruction
Code
QBasic – QuickBASIC
11© 2000 John Urrutia. All rights reserved.
Qbasic Character SetLetters:
a-z and A-Z
Digits:0-9
Blank:the space character ( )
Special characters:+ - * / \ = < > . , ’ ” ( ) : ; ^ _ $ # ? ! % &
12© 2000 John Urrutia. All rights reserved.
Qbasic KeywordsA keyword has a predefined meaning
within Qbasic.Examples:
LET END REM PRINT
13© 2000 John Urrutia. All rights reserved.
Qbasic Data TypesAll data in Qbasic is identified by a
data typeNumbers
% – Integer -32,768 to 32,767 & – Long integer
-2,147,483,648 to 2,147,483,647
! – Single precision 7 digit (1038)
# – Double precision 15 digit (10308)
14© 2000 John Urrutia. All rights reserved.
Qbasic Data TypesStrings:
Any set of characters enclosed in double quotation marks.
“ ”Maximum of 14,656 Characters
15© 2000 John Urrutia. All rights reserved.
Constants & VariablesConstants
“literal” values that cannot be changed
No label
VariablesValue can be changed
Referenced by a label
16© 2000 John Urrutia. All rights reserved.
LabelsA name assigned to represent a
variable.Must start with a letter
Should be meaningful.
Can have periods imbedded.
Should carry the data type.
17© 2000 John Urrutia. All rights reserved.
The LET statementAssigns a value to a variable.
Can be Explicit or Implicit
LET variable.Name = value
LET my.nbr! = 0
LET my.str$ = “This is my string”
LET tot! = tot! + purchases! + taxes!
18© 2000 John Urrutia. All rights reserved.
The PRINT statementWrites information to the terminal.
PRINT output-list
PRINT X$
PRINT 5 + 7
PRINT “Hello World”
PRINT (prints a blank line)
19© 2000 John Urrutia. All rights reserved.
The END statementEND terminates execution
Closes any open files.
Not required but highly recommended.
20© 2000 John Urrutia. All rights reserved.
The CLS statementCLear Screen
Erases all characters from the terminal
Places cursor at position 0,0 (top left corner)
21© 2000 John Urrutia. All rights reserved.
The REM statementThe REM ark statement
Treats everything to the right as a comment.
‘ – Is short hand for the REM
22© 2000 John Urrutia. All rights reserved.
SPACE$(), SPC() and TAB()SPACE$(n)
Returns a string of n spaces
SPC(n) – skips n spaces
TAB(n) – specifies an exact column
23© 2000 John Urrutia. All rights reserved.
The PRINT USING statementWrites formatted data to the teminal
PRINT USING “format-string” ; output-list
The format-string specifiesNumeric edited data formats
String formats
Literal data
24© 2000 John Urrutia. All rights reserved.
USING format charactersStrings
\n\ – first n +2 characters in the string
! – first character in the string
& – no formatting
_ – print character not format
25© 2000 John Urrutia. All rights reserved.
USING format charactersNumbers
# – number digit
. – decimal point
, – thousands separator
+ – sign of number
- – trailing minus sign
$ $$ – fixed / floating dollar sign