1.64k likes | 4.46k Views
Introduction to Qbasic. Program Concepts. Readings. as per Module 7 Study Book “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic by Schneider “Program Development Cycle” p 28 - 38 Qbasic with an Introduction to Visual Basic by Schneider. This lecture.
E N D
Introduction to Qbasic Program Concepts
Readings • as per Module 7 Study Book • “Getting Started” p 4 - 15 Qbasic with an Introduction to Visual Basic by Schneider • “Program Development Cycle” p 28 - 38 Qbasic with an Introduction to Visual Basic by Schneider
This lecture • Computer programs • development cycle • program planning • planning tools • variables • rules for naming • assigning values
Programming Languages: What is a program? It is software A detailed set of instructions to execute a specific task performs tasks in the IPOS cycle
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
Basic Cobol C, C++ Fortran Pascal ADA JAVA HTML According to Sammet, over 200 programming languages were developed between1952 and 1972, but she considered only about 13 of them to be significant. Main Programming Languages
Write a program - comparison of languages • Program to compute gross amount due on an invoice • multiply unit price by quantity of the purchase giving the gross amount
COBOL * compute net amount due IF discount-code = 0 move gross-amount to net-amount -due ELSE multiply .02 by gross-amount giving discount-amount subtract discount-amount from gross-amount giving net-amount-due * print net amount due move net-amount-due to net-amount-due-out write report-line-out from detail-line after advancing 2 lines
C /* Compute gross amount due gross = price * qty-purch; /* compute net amount due if disc_code = 0 net=gross; else { disc_amt = .02 * gross net=gross-disc_amt } /* Print net amount due printf{“The net amount due is %d/n”, net};
C Compute gross amount due gross = price *qty C compute gross net amount due IF (code = 0 ) then net = gross ELSE disc = .02 * gross net = gross - disc ENDIF C Print net amount due WRITE (CRTOUT.*) “The net amt due is $”,net FORTRAN
REM compute gross amt due gross.amount = unit.price * quantity.purch REM compute net amount due IF discount.code = 0 THEN net.amount.due = gross.amount ELSE discount = .02* gross.amount net.amount.due = gross.amount - discount ENDIF REM print net amt due PRINT USING “the net amt due is$##,###.##”;net.amount.due BASIC
COBOL C FORTRAN BASIC
Accessing Qbasic • Qbasic is part of DOS 5.0 or later • Windows 3.11 • double click the Qbasic icon in Windows • double click MSDOS icon in Windows; at the DOS prompt type “Qbasic” i.e. c:\qbasic • Windows 95 • on master disc/CD-ROM • others\oldmsdos\qbasic.exe
Later Versions of Windows • Windows 98 • …tools\oldmsdos\qbasic.exe • You can also download it from the Internet at http://members.xoom.com/ white_acid/basic/compiler/ qbasic.zip
In the labs • K Block • start; programs; dos applications; quickbasic • Z Block • shortcut
Important keys • ALT + enter to maximise screen • Ctrl + break to stop a continuously looping program
Qbasic Window • Menu Bar - drop down menus for functions File Edit View Search Run Debug Options Help • Title Bar - name of program currently being accessed; until initially saved is “Untitled” ------------------------ Untitled ------------------------- • View Window - window where program is written • Immediate Window - used for debugging • Status Bar - information on program
Menus • access to drop down menus by: • using mouse • pressing ALT key highlights shortcut keys e.g. F, E, V etc. to menus; highlighted letters in menu are shortcuts • ESC key to return to View Screen • become familiar with contents of menus
Output Process Input Program Development Cycle • determine outputs - what is the question? • determineinputs - what is the user required to enter/ data available? • determineprocess - algorithm / mathematical formulas algorithm - step by step solution to the problem
Steps in Planning the program • 5 steps in the planning process • ????
Program Planning • Analysis - define the program • Design - plan the solution; consider all ‘what if scenarios’ • Code - translate into (QBasic) language • Test and Debug • DOCUMENTATION!!!!!
Programming Tools • Flowcharts • Pseudocode • Top-down charts
Flow charts • represents the steps in the algorithm in a graphical manner
Your turn • Draw a flow chart that will take an angle entered in degrees, convert it to radians and calculate the sin, cos and tan of the angle. • The syntax for sin cos and tan are not necessary. A flow chart is a description of the process and does not necessarily contain any “code”
Pseudocode • Uses English like phrases with some Qbasic terms to outline the program • assign grades: enter exam mark if exam >=50 then grade is pass else grade is fail print grade end
Top - Down Chart • Hierarchy chart • show overall structure of program • show organisation of program but omit the specific processing • describe what each module does and how modules relate • used for larger programs - Assignment 5 • may combine top down charts and flow charts
Payrate = 6.25 hours = 25 grosspay = payrate * hours PRINT grosspay END A general solution?
Variables • Quantities referred to by symbolic names • make general solutions • Variable name: is the name of a storage location in primary memory where Qbasic stores the value of the variable • value can change during program execution
X = 0.5 y = 10 z = x + y total = z + x y = total x = 10 x = x+y Assignment of variables
Variable names • may only contain letters, digits and full stop • may not contain a blank space • must start with a letter and may be up to 40 characters • may NOT be a reserved word e.g let, print • generally given a value of 0 initially but...
A 4sale Test1 Rumplestiltskin %Interest Gross Pay Grosspay GroSSPay Valid invalid valid valid invalid invalid valid valid Valid names
Your turn • Draw a flowchart that take two times in hours, minutes and seconds and will calculate the total time in hours minutes and seconds e.g 2 hr, 15 min & 12 sec + 1 hr 10 min and 5 sec = 3 hrs 25 min and 17 sec
Key points • how to access Qbasic • menu system • save and retrieve a program • program development cycle • software development cycle • programming tools • flowchart; pseudocode; top down charts
The End • If you wish for an intro to spreadsheets, please stay
ADA • ADA: Named by Augusta Ada Byron, Countess of Lovelace, a mathematician in the 1800 who wrote the first computer program. ADA is based on Pascal and is supported to the US Department of Defence and requires its use on all US government military projects. The language is portable allowing transfer between computers.
Pascal • Pascal: Developed in Switzerland in 1968, named after Blaise Pascal who developed one of the earliest calculating machines. Developed for teaching programming and was one of the first programming languages where the instructions in the language were designed to encourage programmers to follow a structured program. New development ‘Turbo Pascal’ by Borland Corporation.
Fortran • Fortran: FORmular TRANslator developed by IBM in 1957. Designed to be used to scientists, engineers and mathematicians; considered to be the first high level language; noted for its capability to easily express and efficiently calculate mathematical equations.
C • C: Developed in 1972 by Dennis Ritchie at Bell Laboratories; originally designed as a programming language for writing systems software but now general purpose language; very powerful; UNIX operating system is written in C.
Cobol • Cobol: COmmon Business Orientated Language. Key person in development was Admiral Grace Hopper in 1960. Development was backed by US Department of Defence. COBOL instructions are arranged in sentences and grouped into paragraphs; produces lengthy program code; very good for processing large files and simple business calculations.
BASIC • Basic: Beginner’s All-purpose Symbolic Instruction Code. Developed by John Kenneny and Thomas Kurtz in 1964. Designed to be simple interactive programming language for college students. Other versions include Microsoft Quickbasic, GWbasic, Qbasic etc
Java • Similar to c and c++ • developed for multimedia on Web • creates small program called applets which are downloaded and run on your browser • safe from virsus • simple robust and portable • object orientated • developed by Sun MicroSystems • JavaScript simplier version developed by Netscape
HTML • Hyper Text Markup Language • not strictly a programming language but does have specific syntax rules • used for WWW - formating language to layout web pages with text graphics video and sound