Presentation is loading. Please wait.

Presentation is loading. Please wait.

INTRO TO COMPUTER PROGRAMMING (QBasic)

Similar presentations


Presentation on theme: "INTRO TO COMPUTER PROGRAMMING (QBasic)"— Presentation transcript:

1 INTRO TO COMPUTER PROGRAMMING (QBasic)
AJAYI, Olusola Olajide Department of Computer Science, Faculty of Science, Adekunle Ajasin University, Akungba-Akoko, Ondo State, Nigeria. / / /

2 COURSE CONTENTS Part 1: Introduction Part 2: The Art of Programming
Algorithm Pseudocode Part 2: The Art of Programming Part 3: Intro to QBasic Part 4: Making Statement in QBasic Part 5: Control Statements in QBasic Part 6: Array in QBasic Part 7: String Processing in QBasic Part 8: Functions and Subroutines in QBasic EXTRA/BONUS I: File in QBasic EXTRA/BONUS II: Graphics in QBasic

3 PROGRAMMING Programming is defined as an art of writing codes.
It simply implies the ability of a programmer to communicate with the computer system in a particular programming language. It can also be seen as a way by which the computer/programmer instructs the computer system to carry out a particular task. It is a transformational act that brings about changes in the status of task – e.g. manual task to computational one

4 TAXONOMY OF PROGRAMMING
PROGRAMMER: This is a person that indulges or that is an expert in writing computer codes. His major responsible is to write programs that performs a given or specified function. PROGRAM: This implies the written instruction which the computer takes in and act upon. PROGRAMMING LANGUAGE: This indicates the language of choice for which the programmer communicates with the computer machine. In other words, this points to the language with which he codes.

5 LANGUAGES HIGH LEVEL LANGUAGE (HLL): This is a language that is close to normal human English Language. It isn’t a languages the computer understands, rather it needs the help of an interpreter or a compiler before computer could understand it. Examples here includes QBasic (Quick – Beginners’ All Purpose Symbolic and Instruction Code), Fortran (FORmula TRANslator), Pascal, Java, C, C++, Python, Ada, Eiffel etc. LOW LEVEL LANGAUGE (LLL): This language is very much close to machine language. It needs little translator to real machine language. It is regarded as SYMBOLIC Language. A good and common example is the ASSEMBLY Language.

6 LANGUAGES cont’d MACHINE LANGUAGE (ML): This is the very language that the computer understands. It is called the language of 0s and 1s. For the purpose of this course, High Level Language shall be the language of usage and QBasic specifically the programming language of choice.

7 The Structure of QBasic
QBasic is a procedural language. Unlike object-oriented language, it has no standard structure according to programming style rule. Howbeit, it does have structure for programmers to follow.

8 Guide to QBasic Structure
Line Number: Programs in QBasic are easily written with line numbers for readability purpose. CLS: This means Clear Screen REM: Implies REMark – Comment. END: To signify the end of a program

9 Guide to QBasic Structure- Illustration
For example, the program below does nothing but shows the guide to QBasic Structure: 5 CLS 10 REM 15 END OR 2 CLS 4 REM 6 END

10 GARBAGE IN & OUT IN QBASIC
To feed/supply data unto the computer system using QBasic, we make use of any of the following two commands: INPUT statement READ&DATA statement To fetch/retrieve stored or inputted data from the computer system using QBasic, we make use of PRINT statement.

11 OUTPUT STATEMENTS These are statements that are used for fetch/retrieve/show to screen, inputted or stored data from the computer system. The major/basic output statement used in QBasic is called PRINT. Others will be treated under FILE.

12 OUTPUT STATEMENTS – Usage & Format
PRINT can be used in two ways: For outputting literals e.g. PRINT “I am a programmer” For outputting variables (values of an identifier) e.g. PRINT radius (where radius is a variable having a particular value that has previously been inputted /captured / stored)

13 OUTPUT STATEMENTS – Illustration I
5 CLS 10 REM 15 PRINT “I am a Programmer” 20 END Press F5 to RUN OR Click on RUN and click on START RUN well? Good! Save your work now!! Click on FILE, then click on SAVE. Remove the highlighting and save accordingly. Please ensure you preserve the .bas, it is the filename extension for QBasic, just as .doc is to MS-Word.

14 OUTPUT STATEMENTS – Illustration I cont’d
See the output below: RUN well? Good! Press any KEY to return to the Coding Screen. Save your work now!! Click on FILE, then click on SAVE. Remove the highlighting and save accordingly. Please ensure you preserve the .bas, it is the filename extension for QBasic, just as .doc is to MS-Word.

15 OUTPUT STATEMENTS – Illustration I cont’d
To save:

16 OUTPUT STATEMENTS – Illustration I cont’d
Filename Giving: Use the Arrow Key to remove the highlighting. Thereafter, use the left arrow key to move under the DOT, then use backspace to delete UNTITLED and put in/type in your own desired filename (e.g. programmer). See the next slide.

17 OUTPUT STATEMENTS – Illustration I cont’d
This is what you should now have: Click on OK or Press ENTER to complete the SAVE process.

18 OUTPUT STATEMENTS – Illustration I cont’d
To start another/new program, click on FILE, then on NEW

19 OUTPUT STATEMENTS – Illustration I cont’d
You can start a new/fresh program codes now!

20 OUTPUT STATEMENTS – Illustration II
5 CLS 10 REM 15 INPUT radius 20 PRINT radius 25 PRINT radius * 2 30 END Press F5 to RUN OR Click on RUN and click on START.

21 OUTPUT STATEMENTS – Illustration II cont’d
You will first see something like this, prompting you to input/supply value for radius.

22 OUTPUT STATEMENTS – Illustration II cont’d
…do the inputting now…and press the ENTER key.

23 OUTPUT STATEMENTS – Illustration II cont’d
…the system responds thus: To go back to the coding screen, obey the instruction: ‘Press any key….’

24 Code in QBasic to output the literals:
Class Exercise I Code in QBasic to output the literals: BIO-DATA Quiz HE was born and brought up in Lagos. He hails from Kwara. He settles down in Ondo. Who is He?

25 5 CLS Solution I 10 REM 15 Print “BIO-DATA Quiz”
25 Print “He was born and brought up in Lagos.” 30 Print “He hails from Kwara.” 35 Print “He settles down in Ondo.” 40 Print 45 Print “Who is He?” 50 END

26 Solution I - Output

27 Class Exercise II Given two variables: birthyear and currentyear, input values for the two variables and compute your AGE by finding the difference of the two variables.

28 25 PRINT currentyear-birthyear 30 END
Solution II 5 CLS 10 REM 15 INPUT birthyear 20 INPUT currentyear 25 PRINT currentyear-birthyear 30 END

29 Solution II - Output

30 INPUT STATEMENTS These are statements that are used for feed/supply data unto the computer system. Two Types: Input Method Read & Data Method

31 INPUT STATEMENTS cont’d
INPUT Method This is used where the program given is a closed problem (e.g. values not specified). e.g. INPUT A OR INPUT “Enter value for A: ”, A Here the value of A is expected to be inputted.

32 INPUT STATEMENTS cont’d
Programming Example Code in QBasic to solve: Z = x2 + w y (ii) F = b2 4ac

33 INPUT STATEMENTS – Illustration I
Solutions 5 CLS 10 REM 15 INPUT “Enter value for X: ”, x 20 INPUT “Enter value for W: ”, w 25 INPUT “Enter value for Y: ”, y 30 Let Z = ((x*x) + (w/y)) 35 PRINT “The answer is: ”, Z 40 END

34 INPUT STATEMENTS – Illustration I - Output

35 INPUT STATEMENTS – Illustration II
Solutions 5 CLS 10 REM 15 INPUT “Enter value for A: ”, a 20 INPUT “Enter value for B: ”, b 25 INPUT “Enter value for C: ”, c 30 Let F = ((b^2) / (4*a*c)) 35 PRINT “The answer is: ”, F 40 END

36 INPUT STATEMENTS – Illustration II - Output

37 INPUT STATEMENTS cont’d
READ Method This is used where the program given is an open problem (e.g. values specified). e.g. READ A DATA 7 OR READ A, B, C DATA 7, 15, 87 Here there is no need using INPUT to enter the value of A because it is already given.

38 INPUT STATEMENTS cont’d
Programming Example Given: t = 15, u = 210, s = 14, r = 11 Code in QBasic to compute: V = t + (u – r) (ii) W = u + s3 t2 t2

39 INPUT STATEMENTS – Illustration I
Solutions 5 CLS 10 REM 15 READ t, u, r 20 DATA 15, 210, 11 30 Let V = (t + (u-r)) 35 PRINT “The answer is: ”, V 40 END

40 INPUT STATEMENTS – Illustration I - Output

41 INPUT STATEMENTS – Illustration II
Solutions 5 CLS 10 REM 15 READ u, s, t 20 DATA 210, 14, 15 30 Let W = ((u/(t^2)) + ((s^2)/(t^2))) 35 PRINT “The answer is: ”; W 40 END

42 INPUT STATEMENTS – Illustration II - Output
Did you notice any different in the outputs (this slide page 42 – using PRINT with Semicolon ; and the previous one, slide page 40 – using PRINT with Comma ,?

43 HOME TAKE 1 Using QBasic, code to output: ADEKUNLE AJASIN UNIVERSITY
AKUNGBA-AKOKO ONDO STATE NIGERIA This is AAUA – we are proud of our school.

44 HOME TAKE 2 Solve: Write a QBasic program that inputs your scores in ACC101, ACC103 and ACC105. Computes: Their Sums Their Average

45 Given: Temp = 32 – f + w 5 m Code in QBasic to compute for Temp.
HOME TAKE 3 Given: Temp = 32 – f + w 5 m Code in QBasic to compute for Temp.

46 …ALGORITHM… …PSEUDOCODE …PART 2…
NEXT LECTURES …ALGORITHM… …PSEUDOCODE …PART 2…


Download ppt "INTRO TO COMPUTER PROGRAMMING (QBasic)"

Similar presentations


Ads by Google