1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

25
1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs

Transcript of 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

Page 1: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

1© 2000 John Urrutia. All rights reserved.

Qbasic

Constructing Qbasic Programs

Page 2: 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

Page 3: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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.

Page 4: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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

Page 5: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

5© 2000 John Urrutia. All rights reserved.

Program DevelopmentProgram design – Flowcharts

A graphical representation of the problem definition

Process

Decision TerminationManual

Screen

Page 6: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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

Page 7: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

7© 2000 John Urrutia. All rights reserved.

Program DevelopmentImplementation – coding

The syntactical exercise of converting the program design into a specific programming language.

Page 8: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

8© 2000 John Urrutia. All rights reserved.

Program DevelopmentV&V –Verification & Validation

Specification errors

Syntax errors

Logic errors

Page 9: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

9© 2000 John Urrutia. All rights reserved.

Program DevelopmentDocumentation

Program - internal

User - external

Page 10: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

10© 2000 John Urrutia. All rights reserved.

B. A. S. I. C.Beginners

All-purpose

Symbolic

Instruction

Code

QBasic – QuickBASIC

Page 11: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

11© 2000 John Urrutia. All rights reserved.

Qbasic Character SetLetters:

a-z and A-Z

Digits:0-9

Blank:the space character ( )

Special characters:+ - * / \ = < > . , ’ ” ( ) : ; ^ _ $ # ? ! % &

Page 12: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

12© 2000 John Urrutia. All rights reserved.

Qbasic KeywordsA keyword has a predefined meaning

within Qbasic.Examples:

LET END REM PRINT

Page 13: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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)

Page 14: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

14© 2000 John Urrutia. All rights reserved.

Qbasic Data TypesStrings:

Any set of characters enclosed in double quotation marks.

“ ”Maximum of 14,656 Characters

Page 15: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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

Page 16: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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.

Page 17: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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!

Page 18: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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)

Page 19: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

19© 2000 John Urrutia. All rights reserved.

The END statementEND terminates execution

Closes any open files.

Not required but highly recommended.

Page 20: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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)

Page 21: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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

Page 22: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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

Page 23: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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

Page 24: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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

Page 25: 1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.

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