Download - Basic Computer Programming

Transcript

INTRODUCTION TO BASICCOMPUTER PROGRAMMING

Prepared by:Vic Allen Leonel De Castro

& Carlito Redoble

Program is a set of step-by-step instructions that tells or directs the computer what to do. It sequences the tasks a user wants to be done and produces the results or output needed.

The set rules or instructions that tells the computer what to perform is done through programming language. There are various types of programming language you can choose from.

A programmer is the person who designs a program. It converts problem solutions into instructions for the computer. The programmer designs the program, decides which of the programs or set of instructions to use and tests the program to see if it is working as designed.

Introduction to programming

Program life cycle The steps to follow in writing or creating

a program includes the following:

1. Identify the problem – this is the first

step. As it gives the desired output

requirements, you are to analyze the need to be able to come up

with a suitable programming solution.

1. Planning the solution

Two ways (these two are used only to plan the solution):

Draw flowchart – graphical representation of step-by-step instruction to be done in a program.

Write a pseudo code – list down the set of instructions to be used in the program

3. Coding the program – code the program with the use of a chosen programming language (in this presentation, we’ll use visual basic as our programming language.

3. Testing the program

Desk checking – mentally

traces/checs the logic of the

program to make sure that it is error free.

Translation – the programming language uses a translator to ensure that the programmer does not violate any language rules by the chosen programming language.

Debugging – detecting , locating and correcting bugs (error or mistake)

5. Documentation – contains a brief narrative procces undergone by the program, from the identification of the problem, planning the solution through flowcharting and psuedo code, coding of the program up to the testing result.

Levels of programming language

1. Machine Language or First Generation Programming Language – lowest level of programming.

2. Assemble Language or Second Generation Programming Language – considered as low level language uses Mnemonic codes ( abbreviations that easy to remember).

3. High Level Laguage or Third Generation Programming Language(3GL) – language is written in English like manner.

4. Very High Level Language or Fourth Generation Language (4GL)

5. Natural Language – fifth generation languages resemblance to English language.

Procedural and non-procedural languagesPROCEDURAL LANGUAGE

Programming language which are considered procedural uses a series of instructions or statements which are sequential from the beggining to the end.

Examples of procedural language are :

BASIC ( Beginners’s All-Purpose Symbolic Instruction Code)

COBOL ( Common Business Oriented Language)

PASCAL

FORTRAN ( Formula Translator )

C

PL1 ( Programming Language 1 )

Non-Procedural Languages These programming languages ate considered as

object-oriented programming languages. They are event-drivenwhich means that a programmer selects an event that needs to occur before the instruction or statement is exsicuted. Examples of events are click, double click, drag and drop , mouse over and other event .

Examples of non-procedural languages are :

VISUAL BASIC

C++

JAVA

DELPHI

Beginning Commands

There are also special functions called "commands" (also called "instructions"). A "command" tells the QBasic interpreter to do something. Ex: PRINT, CLS, and INPUT. I will also introduce you to variables.

PRINT

It simply PRINTs the words you specify to the screen. The syntax for PRINT is PRINT “ ” or ?“ ” . Put what you want to show up on the screen inside the quotes. Ex. PRINT "Hello World!“. Then the screen will print Hello World!

CLS

CLS stands for Clear Screen. It does what it stands for, it clears the entire screen. The syntax for this is, of course, CLS.

QBasic Tutorial

VARIABLES

Variables are used to store information in your computers memory. Think of them as storage boxes in your computer. They are almost ALWAYS used in a program. To declare a variable just do this: A(ex) = 10. A is now storing the word "hello". So when you PRINT A then 10 will be printed in the screen as an output. You can use any word,number, or letter as your variable.

INPUT

INPUT is also used to restore value in a variable. Ex. INPUT x, a question mark will be printed on the screen asking for a value. INPUT is also used to ask a printed question, ex. INPUT “number”;xThe screen will show, number?__ ,asking value for the x. You can also use comma instead of a semicolon.

Note: If you put a semicolon then a question mark appears after the prompt string. If you put a comma, then no question mark appears.

Expressions An expression is something the interpreter

calculates (or evaluates). Such as:

1 + 1 (addition)

100 - 47 (subtraction)

3 * 34 (multiplication)

80 / 4 (division)

Note: The computer will always follow the PMDAS pattern in calculating/solving expressions.

IF, THEN, ELSEIF AND THENThe IF and THEN commands are used to

compare an expression and then perform some task based on that expression

Example:

x = 5

IF x = 5 then PRINT “ x is equal to 5 ”

Since x is equal to 5, the program will print:

x is equal to 5

ELSE

Using the ELSE command, you can have the program perform a diffrent action if the statement is false.

Example:

x = 3

IF x = 5 THEN PRINT “Yes” ELSE PRINT “No”

Since x is not equal to 5, the output is:

No

END IF

END IF allows you to have multiple commands after the if . . . THEN statement, but they must start on the line after the IF statement . IF should appear right after the list commands.

Expression SignsYou can also enter the following statements, instead of the equals signs:

X < 5 (x is less than 5)

X > 5(x is greater than 5)

Run the Following :

X = 16

IF (X>5) THEN PRINT “ x is greater than 5 ” ELSE PRINT “x is lesser than 5”

Output :

X is greater than 5

You can also combines the signs like this:

X <= 5 (is less than or equal to 5)

X >= (x is greater than or equal to 5)

X <> 5 ( x does not equal 5)

YOU CAN COMBINE ALL

THIS KNOWLEDGE IN THIS

PRESENTATION USING

Qbasic..

Presented by:

Vic Allen

Leonel

De Castro

Carlito Redoble