introduction to qbasic program concepts. readings b as per module 7 study book b “getting...

42
Introduction to Qbasic Introduction to Qbasic Program Concepts Program Concepts

Upload: elizabeth-stafford

Post on 11-Jan-2016

252 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Introduction to QbasicIntroduction to Qbasic

Program ConceptsProgram Concepts

Page 2: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

ReadingsReadings

as per Module 7 Study Bookas per Module 7 Study Book ““Getting Started” p 4 - 15 Getting Started” p 4 - 15

Qbasic with an Introduction to Qbasic with an Introduction to Visual Basic by SchneiderVisual Basic by Schneider

““Program Development Cycle” p 28 Program Development Cycle” p 28 - 38 - 38 Qbasic with an Introduction Qbasic with an Introduction to Visual Basic by Schneiderto Visual Basic by Schneider

Page 3: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

This lectureThis lecture

Computer programsComputer programs development cycledevelopment cycle program planningprogram planning planning toolsplanning tools variablesvariables

• rules for namingrules for naming• assigning valuesassigning values

Page 4: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Programming Languages:Programming Languages:

What is a program?What is a program?It is softwareIt is softwareA detailed set of instructions A detailed set of instructions to execute a specific taskto execute a specific taskperforms tasks in the IPOS performs tasks in the IPOS cyclecycle

Page 5: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

• 1957 FORTRAN • 1958 ALGOL • 1960 LISP • 1960 COBOL • 1962 APL • 1962 SIMULA • 1964 BASIC • 1964 PL/I • 1966 ISWIM • 1970 Prolog • 1972 C • 1975 Pascal • 1975 Scheme • 1977 OPS5

• 1978 CSP • 1978 FP• 1980 dBASE II • 1983 Smalltalk-80 • 1983 Ada • 1983 Parlog • 1984 Standard ML • 1986 C++ • 1986 CLP(R) • 1986 Eiffel • 1988 CLOS • 1988 Mathematica • 1988 Oberon • 1990 Haskell

Page 6: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Main Programming Main Programming LanguagesLanguages

BasicBasic CobolCobol C, CC, C++++

FortranFortran PascalPascal ADAADA JAVAJAVA HTMLHTML

•According to Sammet, over 200 programming languages were developed between1952 and 1972, but she considered only about 13 of them to be significant.

Page 7: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Write a program - Write a program - comparison of languagescomparison of languages

Program to compute gross amount Program to compute gross amount due on an invoicedue on an invoice

multiply unit price by quantity of multiply unit price by quantity of the purchase giving the gross the purchase giving the gross amountamount

Page 8: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

* compute net amount due* compute net amount due

IF discount-code = 0IF discount-code = 0

move gross-amount to net-amount -duemove gross-amount to net-amount -due

ELSEELSE

multiply .02 by gross-amountmultiply .02 by gross-amount

giving discount-amountgiving discount-amount

subtract discount-amount from gross-subtract discount-amount from gross-amountamount

giving net-amount-duegiving net-amount-due

* print net amount due* print net amount due

move net-amount-due to net-amount-due-outmove net-amount-due to net-amount-due-out

write report-line-out from detail-linewrite report-line-out from detail-line

after advancing 2 linesafter advancing 2 lines

COBOL

Page 9: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

/* Compute gross amount due/* Compute gross amount due

gross = price * qty-purch;gross = price * qty-purch;

/* compute net amount due/* compute net amount due

if disc_code = 0if disc_code = 0

net=gross;net=gross;

elseelse

{{

disc_amt = .02 * grossdisc_amt = .02 * gross

net=gross-disc_amtnet=gross-disc_amt

}}

/* Print net amount due/* Print net amount due

printf{“The net amount due is %d/n”, net};printf{“The net amount due is %d/n”, net};

C

Page 10: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

CC Compute gross amount dueCompute gross amount due

gross = price *qtygross = price *qty

CC compute gross net amount duecompute gross net amount due

IF (code = 0 ) thenIF (code = 0 ) then

net = grossnet = gross

ELSEELSE

disc = .02 * grossdisc = .02 * gross

net = gross - discnet = gross - disc

ENDIFENDIF

C Print net amount dueC Print net amount due

WRITE (CRTOUT.*) “The net amt due is $”,netWRITE (CRTOUT.*) “The net amt due is $”,net

FORTRAN

Page 11: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

REM compute gross amt dueREM compute gross amt due

gross.amount = unit.price * quantity.purchgross.amount = unit.price * quantity.purch

REM compute net amount dueREM compute net amount due

IF discount.code = 0 THENIF discount.code = 0 THEN

net.amount.due = gross.amountnet.amount.due = gross.amount

ELSE ELSE

discount = .02* gross.amountdiscount = .02* gross.amount

net.amount.due = gross.amount - discountnet.amount.due = gross.amount - discount

ENDIFENDIF

REM print net amt dueREM print net amt due

PRINT USING “the net amt due PRINT USING “the net amt due is$##,###.##”;net.amount.dueis$##,###.##”;net.amount.due

BASIC

Page 12: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

COBOLC

FORTRAN

BASIC

Page 13: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Accessing Qbasic Accessing Qbasic

Qbasic is part of DOS 5.0 or later Qbasic is part of DOS 5.0 or later Windows 3.11Windows 3.11

• double click the Qbasic icon in Windowsdouble click the Qbasic icon in Windows• double click MSDOS icon in Windows; at double click MSDOS icon in Windows; at

the DOS prompt type “Qbasic” i.e. c:\the DOS prompt type “Qbasic” i.e. c:\qbasicqbasic

Windows 95Windows 95• on master disc/CD-ROMon master disc/CD-ROM• others\oldmsdos\qbasic.exe others\oldmsdos\qbasic.exe

Page 14: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Later Versions of WindowsLater Versions of Windows

Windows 98 Windows 98 • ……tools\oldmsdos\qbasic.exetools\oldmsdos\qbasic.exe

You can also download it from the You can also download it from the Internet atInternet at

http://members.xoom.com/

white_acid/basic/compiler/

qbasic.zip

Page 15: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Qbasic.pif

In the labsIn the labs

K BlockK Block• start; programs; dos applications; start; programs; dos applications;

quickbasicquickbasic Z BlockZ Block

• shortcut shortcut

Page 16: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Important keysImportant keys

ALT + enter to maximise screenALT + enter to maximise screen Ctrl + break to stop a continuously Ctrl + break to stop a continuously

looping programlooping program

Page 17: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Qbasic WindowQbasic Window Menu Bar Menu Bar - drop down menus for functions- drop down menus for functions

File Edit View Search Run Debug Options HelpFile Edit View Search Run Debug Options Help Title Bar Title Bar - name of program currently - name of program currently

being accessed; until initially saved is being accessed; until initially saved is “Untitled”“Untitled”------------------------ Untitled ------------------------------------------------- Untitled -------------------------

View Window View Window - window where program is - window where program is writtenwritten

Immediate Window Immediate Window - used for debugging- used for debugging Status Bar Status Bar - information on program- information on program

Page 18: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

MenusMenus

access to drop down menus by:access to drop down menus by:• using mouseusing mouse• pressing ALT key highlights shortcut pressing ALT key highlights shortcut

keys e.g. F, E, V etc. to menus; keys e.g. F, E, V etc. to menus; highlighted letters in menu are shortcutshighlighted letters in menu are shortcuts

ESC key to return to View ScreenESC key to return to View Screen become familiar with contents of become familiar with contents of

menusmenus

Page 19: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Program Development Program Development CycleCycle

determine determine outputs outputs - what is the - what is the question?question?

determinedetermine inputs inputs - what is the user - what is the user required to enter/ data available?required to enter/ data available?

determinedetermine processprocess - algorithm / - algorithm / mathematical formulasmathematical formulas

algorithm - step by step solution to the algorithm - step by step solution to the problemproblem

Input Process Output

Page 20: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Steps in Planning the Steps in Planning the programprogram

5 steps in the planning process5 steps in the planning process ????????

Page 21: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Program PlanningProgram Planning

Analysis Analysis - define the program- define the program DesignDesign - plan the solution; - plan the solution;

consider all ‘what if scenarios’consider all ‘what if scenarios’ CodeCode - translate into (QBasic) - translate into (QBasic)

languagelanguage Test and DebugTest and Debug DOCUMENTATION!!!!!DOCUMENTATION!!!!!

Page 22: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Programming ToolsProgramming Tools

FlowchartsFlowcharts PseudocodePseudocode Top-down chartsTop-down charts

Page 23: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Flow chartsFlow charts

represents the steps in represents the steps in the algorithm in a the algorithm in a graphical graphical mannermanner

E N D

p rin t g rossp ay

g rossp ay = p ayra te * h ou rs

h ou rs = 2 5

p ayra te = 6 .2 5

S ta rt

Page 24: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Your turnYour turn

Draw a flow chart that will take an Draw a flow chart that will take an angle entered in degrees, convert angle entered in degrees, convert it to radians and calculate the sin, it to radians and calculate the sin, cos and tan of the angle. cos and tan of the angle. • The syntax for sin cos and tan are The syntax for sin cos and tan are

not necessary. A flow chart is a not necessary. A flow chart is a description of the process and does description of the process and does not necessarily contain any “code”not necessarily contain any “code”

Page 25: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

PseudocodePseudocode

Uses English like phrases with some Uses English like phrases with some Qbasic terms to outline the programQbasic terms to outline the program

assign grades:assign grades:enter exam markenter exam mark

if exam >=50 then grade is passif exam >=50 then grade is pass

else grade is failelse grade is fail

print gradeprint grade

endend

Page 26: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Top - Down ChartTop - Down Chart Hierarchy chartHierarchy chart show overall structure of programshow overall structure of program show organisation of program but omit show organisation of program but omit

the specific processingthe specific processing describe what each module does and describe what each module does and

how modules relatehow modules relate used for larger programs - Assignment 5used for larger programs - Assignment 5 may combine top down charts and flow may combine top down charts and flow

chartscharts

Page 27: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

A general solution?A general solution?

E N D

p rin t g rossp ay

g rossp ay = p ayra te * h ou rs

h ou rs = 2 5

p ayra te = 6 .2 5

S ta rt Payrate = 6.25Payrate = 6.25

hours = 25hours = 25

grosspay = payrate * grosspay = payrate * hourshours

PRINT grosspayPRINT grosspay

ENDEND

Page 28: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

VariablesVariables

QuantitiesQuantities referred to by symbolic referred to by symbolic namesnames

make general solutionsmake general solutions Variable name:Variable name: is the name of a is the name of a

storage location in primary memory storage location in primary memory where Qbasic stores the value of the where Qbasic stores the value of the variablevariable

value can change during program value can change during program executionexecution

Page 29: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Assignment of variablesAssignment of variables

X = 0.5X = 0.5

y = 10y = 10

z = x + yz = x + y

total = z + total = z + xx

y = totaly = total

x = 10x = 10

x = x+yx = x+y

x y z total0.5

1010.5

11

11

10

21

Page 30: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Variable namesVariable names

may only contain letters, digits and full may only contain letters, digits and full stopstop

may not contain a blank spacemay not contain a blank space must must startstart with a letter and may be up with a letter and may be up

to 40 characters to 40 characters may may NOT NOT be a be a reserved wordreserved word e.g let, e.g let,

printprint generally given a value of 0 initially generally given a value of 0 initially

but...but...

Page 31: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Valid namesValid names

AA

4sale4sale

Test1Test1

RumplestiltskinRumplestiltskin

%Interest%Interest

Gross PayGross Pay

GrosspayGrosspay

GroSSPayGroSSPay

ValidValid

invalid invalid

validvalid

validvalid

invalidinvalid

invalidinvalid

validvalid

validvalid

Page 32: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Your turnYour turn

Draw a flowchart that take two Draw a flowchart that take two times in hours, minutes and times in hours, minutes and seconds and will calculate the total seconds and will calculate the total time in hours minutes and seconds time in hours minutes and seconds e.g 2 hr, 15 min & 12 sec + 1 hr 10 e.g 2 hr, 15 min & 12 sec + 1 hr 10 min and 5 sec = 3 hrs 25 min and min and 5 sec = 3 hrs 25 min and 17 sec17 sec

Page 33: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

Key pointsKey points

how to access Qbasichow to access Qbasic menu systemmenu system save and retrieve a programsave and retrieve a program program development cycleprogram development cycle software development cyclesoftware development cycle programming toolsprogramming tools

• flowchart; pseudocode; top down chartsflowchart; pseudocode; top down charts

Page 34: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

The EndThe End If you wish for an intro to If you wish for an intro to

spreadsheets, please stayspreadsheets, please stay

Page 35: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

ADAADA

ADA: ADA: Named by Augusta Ada Byron, Named by Augusta Ada Byron, Countess of Lovelace, a mathematician Countess of Lovelace, a mathematician in the 1800 who wrote the first in the 1800 who wrote the first computer program. ADA is based on computer program. ADA is based on Pascal and is supported to the US Pascal and is supported to the US Department of Defence and requires its Department of Defence and requires its use on all US government military use on all US government military projects. The language is portable projects. The language is portable allowing transfer between computers.allowing transfer between computers.

Page 36: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

PascalPascal

Pascal:Pascal: Developed in Switzerland in Developed in Switzerland in 1968, named after Blaise Pascal who 1968, named after Blaise Pascal who developed one of the earliest calculating developed one of the earliest calculating machines. Developed for teaching machines. Developed for teaching programming and was one of the first programming and was one of the first programming languages where the programming languages where the instructions in the language were designed instructions in the language were designed to encourage programmers to follow a to encourage programmers to follow a structured program. New development structured program. New development ‘Turbo Pascal’ by Borland Corporation.‘Turbo Pascal’ by Borland Corporation.

Page 37: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

FortranFortran

Fortran: Fortran: FORmular TRANslator FORmular TRANslator developed by IBM in 1957. Designed to developed by IBM in 1957. Designed to be used to scientists, engineers and be used to scientists, engineers and mathematicians; considered to be the mathematicians; considered to be the first high level language; noted for its first high level language; noted for its capability to easily express and capability to easily express and efficiently calculate mathematical efficiently calculate mathematical equations.equations.

Page 38: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

CC

C: C: Developed in 1972 by Dennis Developed in 1972 by Dennis Ritchie at Bell Laboratories; originally Ritchie at Bell Laboratories; originally designed as a programming language designed as a programming language for writing systems software but now for writing systems software but now general purpose language; very general purpose language; very powerful; UNIX operating system is powerful; UNIX operating system is written in C.written in C.

Page 39: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

CobolCobol

Cobol:Cobol: COmmon Business Orientated COmmon Business Orientated Language. Key person in development Language. Key person in development was Admiral Grace Hopper in 1960. was Admiral Grace Hopper in 1960. Development was backed by US Development was backed by US Department of Defence. COBOL Department of Defence. COBOL instructions are arranged in sentences instructions are arranged in sentences and grouped into paragraphs; produces and grouped into paragraphs; produces lengthy program code; very good for lengthy program code; very good for processing large files and simple processing large files and simple business calculations.business calculations.

Page 40: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

BASICBASIC

Basic:Basic: Beginner’s All-purpose Symbolic Beginner’s All-purpose Symbolic Instruction Code. Developed by John Instruction Code. Developed by John Kenneny and Thomas Kurtz in 1964. Kenneny and Thomas Kurtz in 1964. Designed to be simple interactive Designed to be simple interactive programming language for college programming language for college students. Other versions include students. Other versions include Microsoft Quickbasic, GWbasic, Qbasic Microsoft Quickbasic, GWbasic, Qbasic etcetc

Page 41: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

JavaJava Similar to c and cSimilar to c and c++++

developed for multimedia on Webdeveloped for multimedia on Web• creates small program called applets which creates small program called applets which

are downloaded and run on your browserare downloaded and run on your browser• safe from virsussafe from virsus

simple robust and portablesimple robust and portable object orientatedobject orientated developed by Sun MicroSystemsdeveloped by Sun MicroSystems

• JavaScript simplier version developed by JavaScript simplier version developed by NetscapeNetscape

Page 42: Introduction to Qbasic Program Concepts. Readings b as per Module 7 Study Book b “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic

HTMLHTML

Hyper Text Markup LanguageHyper Text Markup Language not strictly a programming not strictly a programming

language but does have specific language but does have specific syntax rulessyntax rules

used for WWW - formating used for WWW - formating language to layout web pages with language to layout web pages with text graphics video and soundtext graphics video and sound