You are on page 1of 41

Lesson 10

Introduction to Programming
Topics to be discussed:
1. Programming languages
2. Program development life cycle
3. Algorithms and data structures
4. Flow charts
5. Web design using Hypertext Mark up language (HTML)
6. Practical knowledge of BASIC and HTML programming languages

Objectives
By the end of this lesson, the student should be able to:
1. Explain programming language
2. Identify the categories of programming languages
3. Describe the features of particular Programming language
4. Explain common terminologies associated with programming
5. State the basic steps involved in the development of a computer program
6. Explain the concepts of algorithm
7. Explain the concepts of flow chat

Introduction
This lesson is an introduction to computer programming, the process of writing instructions that
direct the computer to carry out a specific task.
Basic concepts of computer programming include problem statements, algorithms, coding,
control structures, testing, and documentation.

Additional lesson topics include characteristics of computer programming languages and brief
descriptions of todays most popular programming languages.

(1) Programming Languages


A programming language is a standardized communication technique for expressing instructions
to a computer. Like human languages, each has its own syntax and grammar.

Programming language enable a programmer to precisely specify what data a computer will act
upon, how these data will be stored/transmitted, and precisely what actions to take under various
circumstances.

There are different types of programming languages that can be used to create programs, but
regardless of what language you use, these instructions are translated into machine language that
can be understood by computers.

We can therefore define a programming language as a standardized communication technique for


expressing instructions to a computer.

Categories of Programming Languages


High level Programming language is a programming language that is more user
friendly, to some extent platform independent, and abstract from low level computer
processor operations such as memory accesses. A programming statement may be
translated into one or several machine instructions by a compiler.

Examples are Lava, C, C++, Basic, Fortran.

Low level Assembly Language


Assembly languages are similar to machine languages, but they are much easier to
program in because they allow a programmer to substitute names for numbers.

Each assembly instruction is translated into one machine instruction by an assembler program.

Examples of Low level Programming languages:


Machine language
Assembly language

Programming Language Characteristics


Programming languages have characteristics that describe how they work and provide
information about the types of computing task for which they are appropriate.

For example, C++ can be described as high level, object oriented, complied language.

When you need to select a language to use for a program, it is useful to understand some of the
general characteristics of programming language.

Some of the general characteristics of programming languages include:


Procedural
Declarative
Scripting language
Low level
High level
Compiled
Interpreted
Object oriented

Procedural
Languages with procedural characteristics create programs composed of a series of statements
that tell the computer how to perform the process for specific task.

Languages with procedural characteristics are called procedural languages.

For example, the BASIC programming language has procedural characteristics.

Procedural languages are well suited for programs that follow a step by step algorithm.

Programs created with procedural languages have a starting point and an ending point.

Declarative
A declarative language lets a programmer write a program by specifying a set of statement and
rules that define the conditions for resolving a problem.

Declarative languages are useful for programs that manipulate ideas and concepts, rather than
numbers.
A program created with a declarative language describes what the problem is.

For example, the Prolog language has the declarative characteristic.

Scripting Languages
A scripting language defines a task in the form of a script. Scripts require a host application to
run and cannot be run as a standalone application.
For example, you use HTML tags to specify a scrip for how to display a Web page. This script is
interpreted by a Web browser. The Web brewer is the host application without it, the HRML
script cannot run.

Low Level
A low level language requires a programmer to write instructions for the lowest level of
computer system that is, for specific hardware elements such as the processor, and RAM
locations.

High Level
A high level language allows a programmer to use instructions that are more like human
language.
For example, BASIC language is a high level language.

Compiled
A compiler translates a program written in a high level language into low level instruction
before the program is executed.

When you use a compiled language, you must compile your program to produce executable
program code.

Interpreted
An interpreted language uses an interpreter instead of a compiler to create code that the computer
can execute.

Object - Oriented
Object oriented languages are based on an approach to programming that uses objects.
(2) Program Development Life Cycle
A computer program is a set of detailed, step by step instructions that tell a computer how to
solve a problem or carry out a task.

Programmers do not sit down and start writing code right away when trying to make a computer
program. Instead, they follow an organized plan or methodology that breaks the process into a
series of tasks.

This organized plan or methodology is what termed program development life cycle.

The program development life cycle involves the following basic steps:
Problem Definition/Problem statement
Problem Analysis
Algorithm design and representation
Actual coding
Testing and debugging
Complete documentation and operator procedures ready for implementation.

In order to understand the basic steps in the program developmental life cycle, let us define a
single problem that we will solve step by step as we discuss the problem solving
methodologies.

Problem Definition
Problems that you might try to solve using a computer often begin as questions. So a
programmer is usually given a task in the form of a problem.

Before a program can be designed to solve a particular problem, the problem must be well and
clearly defined first in terms of its input and output requirements.
Computer programming requires us to define the problem first, before we even try to create a
solution.

Let us now define our example problem:


Create a program that will determine the number of times a name occurs in a list.

Problem Analysis
This step involves breaking up the problem into smaller and simpler sub problems.

Example Problem:
Determine the number of times a name occurs in a list.

Input to the Program


List of names, name to look for

Output of the Program


The number of times the name occurs in a list.

Algorithm Design and Representation


In computer programming, it is normally required to express our solution in step by step
manner.

An algorithm is a clear and unambiguous specification of the steps needed to solve a problem.

The algorithm may be in either:


Human language
Flow chart
Psendocode

The human language can be English

Flow chart is a graphical representation.

The pseudocode, which is cross between human language and programming language

Now for our example problem, how do we express our solution as an algorithm?

Expressing our solution through Human language:


1. Get the list of names
2. Get the name to look for, lets call this key name
3. Compare the key name to each of the names in the list
4. If the key name is the same with a name in the list, add 1 to the count
5. If all the names have been compared, output the result.

Actual Coding
After constructing the algorithm, it is now possible to create the source code.
Using the algorithm as basis, the source code can now be written using the chosen programming
language.
Coding is the process of using a computer language to express an algorithm.

A person who codes or writes computer programs is called a Computer Programmer.

Testing and Debugging


A computer program must be tested to ensure that it works correctly. Testing often consist of
entering test data to see if the program produces correct results.

As you are coding a program, you must test each section of your code to make sure it works
correctly. This process is referred to as debugging because the process gets the bugs out so
they dont cause errors when you use the program.

Program Documentation
As you are coding, you should also write documentation as a permanent record that explains how
your program works.
Program documentation explains how a program work and how to use it.

Features of Programming languages


The features to be looked at include but are not limited to the following:
Data types
Constants and variables
Expressions and assignments
Operators and precedence
Input / Output statements
Built in functions
Sequential and conditional execution
Looping constructs
Single dimensional arrays
Nested Loops
The features will be explained in terms of QBASIC, questions will be limited to QBASIC.

Every programming language consist some basic elements of features which are required to
make a program.

The elements required to construct a QBASIC program consists of a set of characters, keywords,
constants, variables, operators and expressions.

Data Types
Every variable used in the program has a data type. The table below shows the different types of
variables available in QBASIC:

Data Types Suffix


Single precision !
Integer %
Double precision #
Long integer &
String $

The first 4 types are used to store numbers.


The single precision and double precision types store floating point number. (i.e.
45.68474, 3838.9443)
The integer and long integer types store integers, or numbers without decimal points
(i.e. 40, 2, 345678)
The string type store characters, letter, texts, sentences (i.e: Hello)
If no suffix is assigned, a variable is automatically classified by QBASIC as single
precision.

Constants and Variables


Variables enable your program to remember values from one program statement to the next.

When you ran a QBASIC program, the statements of the program are stored in main memory.

The data for the program can also be stored in main memory.

The data for the program also can be stored in main memory.

A variable in QBasic is a small amount of computer memory that has been given a name.

A variable is like a small box that holds a value. The value in the variable can change (that is why it is
called a variable)

A constant in QBASIC is a variable whose value does not change during the execution of a program.

Expressions and assignments


An expression is a correct combination of numbers, operators, parenthesis, and variables.

When the operation in the combination is arithmetic, it is called arithmetic expression.


Example: 32.128 19.6 + 3.2

When the operator in the combination is logical, it is called logical expression.


Example: FLOUR > = 4 AND SUGAR > = 2.
Storing or entering information into the computer is done by using the LET STATEMENT or the
assignment statement.

The assignment statement allows the programmer to enter data or information into the computer
be the execution (RUN) of the program.
Example: LET AGE % = 30 or AGE % = 30
Operators and precedence
Operators are symbols that indicate the type of operation QBASIC has to perform on the data or
on the values of variables.

There are four types of operators in QBASIC.


They are:
Arithmetic Operators
Relational Operators
Logical Operators
String Operators

Operator Precedence answers the question, which operator is done first?

Arithmetic operators have each been given a priority. When there is a choice, do the highest
priority operation first.

The priorities of operations are given in the table.


The highest priority is 1 and lowest is 4

Priority of Arithmetic Operators


Operator Meaning Priority
^ Power 1
- Negation 2
* Multiply 3
/ Divide 3
+ Addition 4
subtraction 4

Input / Output Statement


In QBASIC the INPUT statement gets data from the computer keyboard.

In programming, output means data that the program sends outside itself to some device. For us,
output mostly will go to the computer monitor.

QBASIC uses the INPUT statement to input data from the keyboard into the program.

The INPUT statement is used to get data from the keyboard. It will:
Print a question mark ? to the screen.
Wait until the user has typed in a value
Get the value when the user hits the enter
Put the value in the variable.

In QBASIC, the PRINT statement is use to output data from the program to the screen.

Built in functions
A function in QBASIC is a readymade program or user made (small) program which helps to
perform a specific task.

QBASIC supports two types of functions:


User define function
Built- in function
A user define function is created by a user or programmer whenever the user needs to perform a
certain task that cannot be performed by using Built in functions.

A built in function is ready made programs that accept data and return a value. These
functions are written by the developer of QBASIC at the time of development of QBASIC.

The two commonly used built in functions:


String functions / manipulators (e.g LEN, RIGHT $, MID $, etc)
Mathematical functions (ABS, INT, MOD etc)

Sequential and Conditional Execution


Control Statements are statements that control the program statements.

Without the control statements, the flow of execution program statement is sequential, ie from
one statement to the next.

There are two types of control statements.


Decision Making / Conditional statement
Loop Statements

Decision making or conditional execution involves two types of statements:


If then else statement
Select ..case statement

The if else statement is used to express conditional expressions. If the given condition is true
then it will execute the statements; otherwise it will execute the optional statements.
The Select Case statement is a special multi way decision maker that tests whether an expression
matches one of the numbers of constant values, and executes accordingly.

Looping Constructs
Looping Statements involves:
For Loop
While Loop
Do Loop
Go to Loop (breaking statement)

The For Loop is the most commonly used statement in QBASIC. This loop consists of three
expressions. The first expression is used to initialize the index value, the second to check
whether or not the loop is to be continued again and the third to change the index value for
further iteration.

The While Loop is used when we are not certain that the loop will be executed. The execution
loops only when the initial condition is true.

The Do Loop, is used when we want to execute first before checking the condition.

The Go to statement is used to alter the program execution sequence by transferring control to
some other part of the program.
Single dimensional arrays
A list of quantities can be given one variable name using only one subscript and such a variable
is called a single subscripted variable.

A single subscripted variable is also called as single dimensional array or variable.

For example, a set of five numbers say (19, 17, 11, 3, -5) can be represented in an array as x (5).
Where x is an array name and 5 is subscript of index.

Nested Loops

(3) Algorithms and Data Structures


An algorithm is a set of steps for carrying out a task.

An algorithm is an abstract idea, but it can be written down and it can be implemented.
The algorithm is written down, or expressed, as instructions in solving a problem.
An important characteristic of a correctly formulated algorithm is that by carefully following the
steps, you are guaranteed to accomplish the task for which the algorithm was designed.

An algorithm for a computer program is typically first written in a format that is not specific to a
particular computer or programming language.

The algorithm is translated into instructions written in a computer programming language so the
algorithm can be implemented by a computer.

The concept of algorithm can be summarized as:


They are a sequence of steps
They are set of instructions (method) which if faithfully followed will produce a solution
to a given problem.

Techniques for Representing Algorithm


You can express an algorithm in several different ways including:
o Structured English
o Psendocode
o Flow charts
o Object definition

Structured English is a subset of the English language with a limited selection of sentence
structures that reflect processing activities.

Psendocode is a notational system for algorithms that has been described as a mixture of
English and your favorite programming language.

Flow Chart is a graphical representation of the way a computer should progress from one
instruction to the next when it performs a task.

Object definition
Another way to express an algorithm is to define the objects that the computer must
manipulate, and then specify the method for manipulating each object.

Algorithm Building Blocks


All problems can be solved by employing any one of the following building blocks or
then combinations:
o Sequences
o Conditionals
o Loops

Sequences
A sequence of instructions that are executed in the precise order they are written in:
o Statement block 1
o Statement block 2
o Statement block 3

Conditionals
Select between alternate courses of action depending upon the evaluation of a condition.

Loops
Loop through a set of statements as long as a condition is true.
(4) Flow Chart
A flow chart is a graphical representation of the way a computer should progress from
one instruction to the next when it performs a task.

Flow chart concept


Flow charting is one method of pictorially representing a procedural (step by step)
solution to a problem before you actually start to write the computer instructions required
to produce the desired result.

Factors to consider in constructing flowcharts


o Think through the problem solution step-by-step
o Analyze the specifications in terms of
1. The required input
2. The output desired
3. The operations and procedures required to produce the output
o Clarify the problem by having a narrative definition of the problem definition
o Develop a flow chart showing the logic, steps, and sequence of steps you want the
computer to execute in order to solve the problem.

Flow Chart Symbols


Flow chart symbols are graphic symbols used to specify arithmetic operations and relational
condition
Key to Flow Chart Symbols

Start or end

Input or output

Decision

Calculation

Connector

Flow line

Terminologies Associated with Programming


High level language: A computer language that allows a programmer to write instructions
using human like language.

Machine Language / Code: A low level language written in binary code that the computer can
execute directly.

Source Code: Computer instructions written in a high level language.

Boolean Expression:
Class: In object oriented programming, a group with specific characteristics, to which an object
belongs.

Comment:

Compiler: Software that translates the program written in a high level language into

Debugging: The process of testing a section of code and correcting errors

Event driven language: A computer language that helps programmers create programs that
continually check for, and respond to, program events.

Syntax: Specifications for the sequence and punctuation of command words, parameters and
switches.

Syntax error: An error that results when an instruction does not follow the syntax rules, or
grammar, of the programming language.

Run time error: An error that occurs when a computer program is run.

Coding: The process of using a computer language to express an algorithm.

OOP: Object oriented languages, Programming languages that focus on the manipulation of
objects rather than on the generation of procedure based code.

(5) Web design using Hypertext Markup Language (HTML)

Objectives Cont.
8. Explain the term HTML
9. State the basic structure for HTML tags
10. Explain and use basic HTML tags
11. Explain some best practices in website development.
12. Create, format and insert text into tables using HTML
13. Create an ordered an unordered list
14. Insert images and hyperlinks

The Web provides opportunities for publishing tasks ranging from a single page to an
entire Web site.

A single Web page is simple to create and can publish useful information such as your
resume or a publicity flyer for your school.

Another use for a single Web page is to provide a list of links to sites information on a
particular topic.

A Web site includes a series of Web pages and has its own domain name.

Business and organizations of all sizes create Web sites to provide information to
customers and to sell products.

Basic Web pages contain text, graphics, and links.

More sophisticated Web pages include animation, sound, and video.

Understanding the term HTML


HTML is the language used to design Web Pages.

It stands for Hyper Text Markup Language.

An HTML file or document has a HTM or HTML file extension.

Every Web page is stored as an HTML document


An HTML document contains special instructions that tell a Web browser how to display
the text, graphics and background of a Web page.

These instructions, called HTML tags, are inserted into the text of the document.

Writing HTML document entails using tag correctly to create your vision.

Basic Structure of HTML document


A basic HTML document has two parts:
o The head
o The body

The head of the document specifies a little that appears on the title bar of the Web
browser when the Web page is displayed.

The body of the document contains informational text, graphics, and links.

Every HTML document should begin with the tag < HTML> and end with the tag < /
HTML>.

The traditional way to create an HTML document is with a basic text editor such as the
Noted pad program included with Microsoft Windows.

Simply type the HTML tags and the text for your Web page, then save the file with an
HTM extension or HTML extension.

The basic structure of an HTML document is

< html >


< head >
< title > < / title >
< / head >
< Body >

< / Body >


< / html >
Basic HTML Tags
HTML Tags are instructions embedded into a text document.

These special instructions tell a web browser how to display the text, graphics and
background of a Web page.

Each tag appears as letters / words / short codes between angle brackets, < >.

Some HTML tags work in pairs. They are called Paired / Container Tags.

o Normally come in pairs like < b > and < / b >


o The first tag, eg. < b > , is start tag, the second tag, e.g. < / b >, is the end
tag.
o Paired tags are used to flank text to be affected eg. < i > In all < / i >
o A start tag and an end tag form are HTML element

Some HTML tags do not have a corresponding end tag. They are called Singular /
Empty Tags. For example, you only need a single < BR > tag to create a line
break.

The following are set of HTML tags that you can use to create HTML documents
for Web pages.

o < HTML > < / HTML >


State that the file is an HTML document. Opening tag begins the page,
closing tag ends the page. This tag is required.

o < HEAD > < / HEAD >


State that the enclosed text is the header of the page. Appears immediately
after the opening HTML tag. This tag is required.

o < TITLE > < / TITLE >


State that the enclosed text is the title of the page. Must appear within the
opening and closing HEAD tags. This tag is required.
o < BODY > < / BODY >
State that the enclosed material (all the text, images, and tags in the rest of
the document) is the body of the body tag. This tag is required.

o < H1 > < / H1>


State that the enclosed text is a heading.

o < BR >
Insert a line break. Can be used to control line spacing and break in lines.
o < UL > < /UL> , < OL > < / OL>
Indicates an unordered list (list items are preceded by bullets) or an
ordered list (list items are preceded by numbers or letter).

o < L1>
Indicates a list item. Precedes all items in unordered or ordered lists.

o < CENTER > < / CENTER >


Indicate that the enclosed text should be centered on the width of the page.

o <B></B>
Indicate that the enclosed text should appear bold face.

o <1></1>
Indicate that the enclosed text should appear italic.

o < A HREF = > < / A >


Indicates that the enclosed text is a hypertext link; the URL of the linked
material must appear within the quote marks after the equal sign.

o < IMG SCR =


Insert an in line image into the document. The URL of the image
appears within the quote marks following the SRC = attribute.

o < HR >
Insert a horizontal rule.

Best Practices In Website Designing


To avoid some of the mistakes, typically made by beginning Web page designers, use these tips:

o Plan your Web page so it fulfills its purpose


Determine the function of your Web page. Is its purpose to entertain, to persuade, to
inform, or to instruct?

o Design a template to unify your pages.


A design template is a set of specification for the location and format of all the elements
that you want to include on your Web pages.

o Follow basic rules for good Web page design

Basic design rules for the text, backgrounds, and graphics on your Web pages includes:
Text:
o For readability, use black type for large sections of text.
o Maintain narrow line widths. Text that stretches across the entire width of the screen is
more difficult to read than text in columns.
o Make sure you proofread your document for spelling errors.

Background:
o White or a very pace color makes a good background.
o Avoid gray and dont let your background color or graphic make it difficult to read the
text.

Graphics:
o Try not to use graphics files that exceed 30 KB because larger files take too long to
transfer, load, and appear on a Web page.
o Use graphics with gif, not bmp extensions.
o To include a large graphic, present it as a small thumbnail with a link to the larger
version of the graphic.
Creating Tables Using HTML
A table is a two dimensional matrix with rows and columns.
o Tables are made up of many parts, all inside one another.
o < tr > starts a new Table Row. Rows are ended with a closing < / tr >
o < td > means Table Data, but we will always call them table cells.

The basic HTML code for creating a table is:


< table >
< tr >
< td > < / td >
< / tr >
< / table >

Formatting Tables Using HTML


The table can be formatted in terms:
o Width
o Height
o Cell padding
o Cell spacing
o Border
o Alignment

The formatting is done by the use of table attributes. The table attributes are:

o Align
Just like most elements, whole tables, rows or cells can be aligned to center, left or right.

o Width
Is used to specify how wide the table is, either in pixels or in a percentage of the screen
width. For example, you could specify width = 400 or width = 80%. Try to keep the
widths under 750 pixels at most, so that it fits into the width of most peoples monitors.

o Cell padding
Is the space around anything in the td. i.e. the space around the text in each cell.

o Cell spacing is the space between cells.

The following HTML codes are used for the formatting:


o Width
< table width = 300 >

o Height
< table height = 300 >

o Cell padding
< table cell padding = 3 >

o Border
< table border = 3 >

Example of a table created using HTML


< table >
< table height = 300 width = 300
border = 2 cell padding = 3 >
< tr >
< td width = 210 > A < / td >
< td width = 45 > B < / td >
< td width = 45 > C < / td >
< /tr >
< / table >

Inserting Text into Table


To inset a text into the cells of the table, place the text in between the < td > < / td > tag.
For example, to insert the text My personal website. You are most welcome
< table >
< table height = 300 width = 300 border = 2 cell padding = 3 > < tr >
< td width = 210 > My personal website. You are most welcome < / td >
< / tr >
< / table >

Formatting Text Using HTML Code


The text in the Web page can be formatted in terms of:
o Heading
o Colour
o Font face
o Font size
o Alignment

The following HTML codes are used for the text formatting:

Heading
< h1 > Heading < / h1 >
< h2 > Heading < / h2 >
< h3 > Heading < / h3 >
< h4 > Heading < / h4 >
< h5 > Heading < / h5 >
< h6 > Heading < / h6 >

Colour
< font color = FFOOOO >

Font Size and face


< font size = 3 face = sans serif >

Alignment
< P align = center > Aligning text to the center < / p >

Example of text formatted using HTML


< html >
< head >
< title > Formatting Text < / title >
< / head >

< body >


< P align = center > Aligning text to the center < / P >

< font size = 3 > This line is shown in the normal font < / font > < br / >
< font size = +3 > Up 3 to change the font size to 6. < / font > < / 6r >

< font size = 3 face = sans serif > changing the font face < / font > < / br >

< / body >


< / html >

Preparing a List Using HTML


Lists are a great way of laying out information in web pages, because they are simple to read and
look good. Lots of people seem to think that the bullet points are little image, but in reality they
are all generated through some rather simple HTML code.

HTML Supports:
o Ordered list
o Unordered list

Unordered list
o Displays bulleted list of items
o Unordered list denoted by the tags < uL > < / uL >
o Each list item is marked with < li > item.
o Bullet type must be specified with type attribute
type = disc / circle / square

Unordered list example


< html >
< head >
< title > Bulletin < / title >
< / head >
< body >
< b > Electronic Media: < / b >
< ul type = circle >
< li > TV < / li >
< li > Radio < / li >
< / ul >
< / body >
< / html >

Ordered Lists:
Uses numbers, alphabets or roman numerals to list items
Ordered List is denoted by the tags < ol > - < / ol >
Each list item is marked with < li > item
Number type must be specified with type attribute
type = i / A / a / I
To alter the numbering sequence use start attribute
Start = 3 / d / ii / c

Ordered list example


< html >
< head >
< title > Bulletin < / title >
< / head >
< body >
< b > Electronic Media : < / b >
< ol type = A start = C >
< li > TV < / li >
< li > Radio < / li >
< / ol >
< / body >
< / html >

Inserting Hyperlinks And Images


A link is a connection from one web page to another.
o Anchor container tag, < a >, is used to create links.
o The href Attribute is needed to create the link
o href stands for Hypertext reference.

Format
< a href = url > Link text to display < / a >

HTML Links examples


< html >
< head >
< title > Links < \ title >
< \ head >
< body >

Welcome to SS online Website


< a href = http : // www.secondanyschool.online >
Visit our Website < / a >
< / body >
< / html >

Image As A Hyperlink
Format
< a href = page url >
< img src = image url >
</a>

Example
< a href = home htm >
< img border = 0 , src = logo. gif
width = 65 height = 38 >
</a>

Image to be inserted should be in the same folder together with the other files associated with the
website.

(6) Practical Knowledge of BASIC Programing Language


Introduction
BASIC (Beginners All purpose Symbolic Instruction Code) is one of the popular high
level programing language.
BASIC has become one of the most popular and widely uses programming language
because it is easy to use and available for almost every type of computer system.

BASIC is a high level, procedural language. Most versions of BASIC are interpreted
languages, although some versions provide compiling capabilities.

QBASI is one of the versions of BASIC.

o It uses English like words and mathematical symbols to write programs.


o The programs written in QBASIC need to be converted into machine codes.
o QBASIC provides working area to write programs and QBASIC has its own
interpreter.
o QBASIC Editor checks syntax errors and capitalizes QBASIC reserved words.
o In the QBASIC Editor, you can write, edit, run and debug programs.

Features of QBASIC
Some features of QBASIC are listed below:
o QBASIC does not use technical terminology (word) to write statements.
o QBASIC automatically checks syntax.
o QBASIC capitalizes the reserved words.
o QBASIC keeps the same variable name used in a program to identical form.
o QBASIC allows you to break lengthy programs into modules.
o QBASIC interprets a statement of a program at a time to CPU.

Loading / Opening the QBASIC Editor Screen


To start QBASIC follow these steps:
1. Click the start button
2. Point to All Programs and then Accessories
3. Select Command Prompt. It displays Command Prompt Window.
4. To move to the root directory, at DOS prompt type CDI and press Enter Key.
5. At C: \ > prompt, type CD QBASIC and press Enter Key.
6. At C: \ QBASIC > prompt, type qbasic and press Enter Key. It will display QBASIC
Welcome Screen
7. Press Esc Key to get QBASIC Editor Screen.
QBASIC Editor Screen
QBASIC Editor is the window where you write programs.

QBASIC Editor Screen has parts:


o Menu Bar
o Program Window
o Immediate Window
o Status Bar

Menu Bar: The Menu Bar consists of list of commands like:


o View
o File
o Search
o Run
o Debug
o Options
o Help
Program Window
This is the Upper window which is titled as Untitled and is the window where you write
programs. To see the output of the statement written in this window, press Shift + FS Key.

Immediate Window
This is the lower window which is titled as immediate and is the window where you test
commands, expressions, etc. As soon as you press Enter Key, it displays the output on the
screen. F6 function key is used to switch between Program window and Immediate Window.

Status Bar
The Status bar shows short cut keys and the location of the curser on the screen.
Running A Program
To see the output of the program, after entering a set of instructions in the program window, you
must run the program. To run (execute) a program,
Press (1) Shift + F5 key or
(2) Alt, R , S

Saving A Program
You need to save a program for the future use. To save a program, follow these steps:
1. Press ALT + F key
2. Highlight Save As Option
3. Press Enter key. It displays Save Dialog Box
4. Enter Filename in the File name text box
5. Press Enter key

NOTE: (1) File name should not be more than eight characters.

(2) QBASIC automatically adds an extension as BAS for the program file.

Clearing Program Window


To write a new program you need to remove the previous program from the Program Window.
To clear or remove the previous program, follow these steps:
o Press ALT Key
o Highlight New option and press Enter Key

Opening An Existing Program

To open an existing program in the Program Window, follow these steps:

o Press Alt Key


o Press F or Enter Key
o Highlight Open Command and press Enter Key
o Select a program file the list of files displayed in the Open Dialog Box and press Enter
Key.

Exiting QBASIC

To exit from the QBASIC, follow these steps.

a. Press ALT Key. It will activate menu.


b. Press F or Enter Key
c. Press X or Select Exit command under File menu and press Enter Key.

Programming in QBASIC

Every programming language consists of some basic elements which are required to
make a program.

The elements required to construct a QBASIC program consists of a set of :


o Characters
o Keywords
o Constants
o Variables
o Operators and
o Expressions

Character Set

A set of characters that are allowed to be used in QBASIC is known as the QBASIC character
set. The QBASIC character set consists of alphabets (both small and capital), numbers (0 to 9)
and special characters.
Keywords

Keywords are those words which have special meanings in QBASIC.

Keywords are formed by using character of QBASIC character set. Keywords are statements,
commands, functions (built in functions) and names of operators. The keywords are also called
Reserved Words.

Some reserved / keywords are:

CLS, REM, INPUT, LET, PRINT, FOR, DO, SELECT, MID$, ASDC, SQR, LEN, LEFT $,
TIME$ and INT.

Constants

Constants are the data or the values in a program that cannot be changed during the
program execution.

In QBASIC, these constants are grouped into two main categories.


a. String Constant
b. Numeric Constant
A String Constant is a letter, words, numbers, combination of letters with numbers or special
characters enclosed in double quotes. Mathematical operations cannot be performed on string
constants.

Examples of String Constants are:

B , APPLE , SYMBOL NO : 10205,

Welcome to QBASIC World!!!

Numeric Constant refers to a number. A number with or without decimal point is a numeric
constant.

Variable

A variable is a place in the computer memory which has a name and stores data temporarily.

Operators

Operators are symbols that indicate the type of operation QBASIC has to perform on data
or on the values of variables.

There are four types of operators in QBASIC.

They are:

o Arithmetic Operators
o Relational Operators
o Logical Operators
o String Operators
Expressions

An expression is the combination of operations, constants and variables that is evaluated to get a
result.

Level of Instructions In QBASIC

The following are the levels of instructions in QBASIC

Assign a value to a variable

Example size = 10

Evaluate an expression or Solve an equation


Example: Square Inch Price = Price / Square Inches

Ask for information (input) from the user


Example: Enter the Price of pizza

Display or print the results of calculation


Example; Display the Square Inch Price

Make decisions

Example: If the pizza is square, calculate square Inches by multiplying the size * size

Repeat some instructions

Example; Repeat the price calculations for as many pizzas as the user wants

Practical

1. Write a program to print the area of a circle, given the radius.


Solution
DEF fna(a) = 3.14 r r
INPUT Value of radius , r
PRINT the area of circle, fna(a)
END

2. Write a program to print the simple interest


Solution
CLS
pv = 5000
r = 12
t=2
Si = (pv r t) / 100
PRINT Si
END

3. Write a program to find cube value


Solution
CLS
INPUT the first value ; a
INPUT the second value; b
INPUT the third value ; c
x = (a + b + c)
PRINT x
END

4. Write a program to print maximum value and minimum number. Number should be
inputted through the keyboard.
Solution
CLS
DIM x (10)
INPUT any value ; x (i)
NEXT i
max = x (1)
min = x (1)
FOR i = 1 TO 10
IF max < x (i) THEN max = X (i)
IF min > x (i) THEN min = X (i)
NEXT i
PRINT the maximum value; max
PRINT the minimum value, min
END

You might also like