The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

Let's Log In Computer Science Book 8 Revised (2078).indd

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by PHILOMATH Contextualizing Mathematics, 2021-07-14 10:11:04

Let's Log In Computer Science Book 8 Revised (2078).indd

Let's Log In Computer Science Book 8 Revised (2078).indd

Vedanta Let’s Log in Computer Science | Book 8

Adding Text

Follow the steps below to add text:

Step 1 : Create a new file or open an existing image file.

Step 2 : Click on Type tool from Tools panel or simply press “T”.
The Type tool is activated.

Step 3 : Various Options related with text appear in the Options
Bar.

Set the font family Set the font size Set the text colour

Step 4 : Options bar of Type Tool
Step 5 :
Choose the font, text size, and color of your choice.
Step 6 : Click and drag anywhere in the workspace (new image or
existing image) window to create a text box.
A new text layer will be added to your image.

Text Box over the image Text layer

Step 7 : Type the required text.

201 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Moving Text

Step 1 : Select the text layer.
Step 2 : Select the Move tool or press on V.
Step 3 : Click and drag the text to the required location.

Edit the Text

Step 1 : Double-click on the layer icon of the required text.

or,

Step 2 : Select the type tool and click on the text. The text is
highlighted.

Step 3 : Now, you can modify the text, text size, and color

Selection Tools

Selection tool is one of the widely used tool in Photoshop while manipulating
or designing images. Selection tools are used to isolate different part of an
image so that we can work only on that particular area without affecting the
rest of the image.

202Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Marquee Tool

Marquee tool is a basic selection tool
available in Photoshop. It allows the
user to make rectangular or elliptical
selection of a certain part of an image.
It also provides 1pixel rows and columns
selection.

Follow the steps below to select a part of an image using Marquee tool:
Step 1 : Open a required image file.
Step 2 : Select either Rectangular or Elliptical selection tool.

Step 3 : Click and drag over the area of the image you want to
select.

Note: Hold down shift button while dragging to constrain the marquee to square or
circle. You can cut, copy, or apply some other effects on the selected portion of the
image.

203 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Lasso Tool

Lasso Tool allows the user to draw freehand
selections around objects. Beside the
standard Lasso tool, Photoshop provides
two other types of Lasso tool: Polygonal
Lasso Tool and Magnetic Lasso Tool.

Follow the steps below to select a part of an image using Lasso tool:
Step 1 : Open a required image file.
Step 2 : Select the Lasso Tool.

Step 3 : Click and drag to draw a freehand selection border over a
desired part of the image.

Step 4 : Release the mouse button.

Note: Press Ctrl+D to deselect the image.

204Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Cropping Images

Cropping images is one of the most basic, but important, photo editing
features available in Photoshop. Cropping feature allows you to remove
unwanted outer parts of image.
In Photoshop, you can crop your images using either crop tool or selection
tool. Follow the steps below to crop an image:
Step 1 : Open the required image.

Step 2 : Original Image before cropping

Step 3 : Select the Crop tool from Tools panel or press on C to
Step 4 : activate Crop tool.
Select the area of the image that you want to preserve.
Click on Image Menu > Crop or Press Enter.

Cropping After Cropping

205 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Painting Tools

Photoshop provides several tools for painting and editing image color.
The Brush tool and the Pencil tool work like traditional drawing tools by
applying color with brush strokes. The Gradient tool, Fill command, and
Paint Bucket tool apply color to large areas.

Paint with the Brush Tool or Pencil Tool

The Brush tool and the Pencil tool paint the current foreground color on an
image. The Brush tool creates soft strokes of color. The Pencil tool creates
hard-edged lines. Follow the steps below to paint with Brush tool.

Step 1 : Create a new image document.
Step 2 : Choose a foreground color.
Step 3 : Select either the Brush tool or Pencil Tool
from Tools panel.
Step 4 : Choose a brush from
the Brush Presets
Step 5 : picker.
Set tool option for
Step 6 : mode, opacity, and so
on, in the options bar.
Do one or more of the
following:

Drag in the image
to paint.
To draw a straight
line, click on a
starting point in
the image. Then,
hold down Shift
and click on an
ending point.

206Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

When using the Brush tool as an airbrush, hold down
the mouse button without dragging to build up color.

Drawing Tools

The drawing tools (the Pen and Shape tools) let you create and edit shapes.
The drawing tools provide an easy way to create buttons, navigation bars
and other items.

Draw a Custom Shape

You can draw custom shapes by using shapes from the Custom Shape Tool
from the Tools bar. Follow the steps below to draw a custom shape:

Step 1 : Create a new file (press Ctrl + N).

Step 2 : Select the Custom Shape Tool .

The option bar for Custom Shape Tool appears.

Step 3 : Click on the Shape drop-
Step 4 : down button of the option
bar. Select the required
shape.
Drag in your image to
draw the shape.

207 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

POINTS TO REMEMBER

Computer Graphics includes everything that is presented through
images developed or designed using different graphical software.
Some popular image editing softwares include Adobe Photoshop, GIMP,
Adobe Illustrator, CorelDraw, Paint.net, etc.
Different commonly used image formats are JPG, GIF, PNG, BMP, TIF,
and PDF.
Type tool is used to add text on to your image file.
Different selection tools available in Photoshop are Marquee Tool, Lasso
Tool, and Magic Wand Tool.
Marquee tool allows rectangular or elliptical selection of a part of an
image.
Lasso tool allows freehand selections around objects.
The Brush tool creates soft strokes of color.
The Pencil tool creates hard-edged lines.
The drawing tools let you create and edit shapes.
Image size refers to the length and width of a digital image, also called
pixel dimensions.
Resolution refers to the number of pixels in an image.  
Cropping feature allows the user to remove unwanted outer parts of
image.

208Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Exercise

1. Answer the following questions:
a) Define Computer Graphics.
b) Mention the list of Graphical software.
c) Explain any one selection tool available in Photoshop.
d) Differentiate between Painting and Drawing tool.
e) Write down the steps to crop an image in Photoshop.

2. Give full forms of the following abbreviations:

a) JPEG b) BMP c) PNG
f) GIMP
d) PDF e) GIF

g) TIF h) Pixel

3. Tick (√) the correct options:

a) Which is not the image editing software?

(i) MS-Excel (ii) Paint.net

(iii) Google Drawing (iv) Adobe Photoshop

b) Which one of the following is not an image format?

(i) GIF (ii) PNG

(iii) JPG (iv) PPTX

c) Which one of the following tools is not available in Tools panel of Photoshop?

(i) Lasso Tool (ii) Crop Tool

(iii) Type Tool (iv) Copy Tool

209 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

d) The ……….. tool creates hard-edged lines.

(i) Blur (ii) Type

(iii) Brush (iv) Pencil

e) The ……….. tool creates soft strokes of color.

(i) Type (ii) Brush

(iii) Pencil (iv) Crop

4. Write down the keyboard shortcuts to accomplish the following tasks in
Adobe Photoshop:

a) To deselect the selection
b) To create a new image file.
c) To activate Crop tool
d) To activate Type tool

5. Match the following: Group “B”
Group “A”

a) Coral Draw (i) Image Format

b) TIF (ii) Variety of controls

c) Palettes (iii) Smallest element of a picture

d) Resolution (iv) Graphics Editor

e) Pixel (v) Number of Pixels

210Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Lab Activities

1. Open any image file in Photoshop and change its width to 600 pixels and
height 800 pixels.

2. Create a new picture that is about 500 pixels wide, 400 pixels high, and has
a resolution of 72 pixels/inch. Create a fancy space background there. Use
the Paint Bucket tool to fill the background layer with the color you want the
space to have on it. Use the Brush tool to paint the stars and stuff.

3. Create a collage of “7 wonders of the world.” Also write their names.

4. Search few jpg file in your computer. Open any one of them and save the
same file in PNG format.

5. Open any graphic file and demonstrate the uses of different selection tools.

6. Open any one JPG file. Remove some unwanted portion using Crop tool and
save it in GIF format.

7. Run MS-Paint. Create a graphic file and save in BMP format. Open the same
file in Photoshop and save it in JPG format.

211 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Lesson

13

Computer Program

A computer program is a set of instructions given to the computer to perform
a particular task. It is written in a programming language such QBASIC, C,
C++, etc given by the users that are translated into machine level language
to obtain desired result.

Computer Programming

Computer programming is the process of designing, writing, testing,
debugging, and maintaining the source code written in a particular computer
language.

Programmer

A programmer is a person who is involved in the different processes of
computer programming.

Programming Language

It is a coded or artificial language used to write instructions that a computer
can understand to do what the user wants.
A programming language is therefore a practical way for us (humans) to
give instructions to a computer.

212Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Types of Programming Language

Machine Language

Machine language is the most basic (also
called low-level) computer language. It
is directly understood by the computer
as it uses binary (‘1’ and ‘0’) code which
a computer can run (execute) very fast
without using any language translator.
But it is very difficult to program using
machine language.

Advantages of Machine Language
It is directly understood by computer. So, no translator is required.
Programs written using machine language run fast.

Disadvantages of Machine Language
It is very difficult to write program in machine language because the
programmer has to know all the details of hardware.
It is difficult to debug the program.

Assembly Language

Machine language is difficult to write programs in as it requires knowing the
details of hardware. Assembly language was developed to make computer
programming easier. It uses letters and numbers (mnemonic codes) for
instructions. It is the second generation language.

Assembly Language

213 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Advantages of Assembly Language
It is easier to program than machine language.
It is easier to correct the errors.

Disadvantages of Assembly Language
It requires translator (assembler), so, it is little slow in execution.
It is machine dependent. It means a program written for one machine
might not run on other machines.

High Level Language

It is the third generation
programming language written
in simple English with some
mathematical notations such as
+,%, etc. It requires language
translator. QBASIC is one of the examples of high level language.

Language Processor

Language processor is a program that performs tasks, such as translating
and interpreting, required for processing a specified programming language.

Assembler

It translates the program written in assembly language into machine
language and vice versa.

Compiler

It translates the whole program into machine language at once.

Interpreter

It translates one statement at a time.

Note:
Computer languages themselves are language processor. We do not require any other software/
application as a language processor. For example, C is a compiler and QBASIC is an Interpreter.

214Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Exercise

1. Answer the following questions:
a) Define program and computer programming.
b) What is computer language? Give some examples.
c) Write down the advantages and disadvantages of machine language.
d) Write down the advantages and disadvantages of assembly language.
e) What is language processor? Mention its types.
f) Differentiate between interpreter and compiler.

2. State whether the following statements are true or false:
a) Computer language is a natural language.
b) Machine language is machine-dependent.
c) High level language takes less time in execution than
machine language.
d) Assembly language is a second generation language.
e) Machine language accepts only 0s and 1s.

3. Fill in the blanks:
a) ……………….. language does not require any translator.
b) ……………….. language uses mnemonics.
c) ……………….. is the easiest computer language.
d) ……………….. translates the program written in assembly language
into machine language.
e) ……………….. is an example of compiler.

215 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Lesson

14

Introduction

In previous class, you learned about the basic concept of program design
tools. A program is a set of instructions. It is written using a computer
language. When we build a house, we need to prepare a map (design) of our
house. Likewise, we also have to design our program before coding (writing
a program using a particular computer language).
There are several tools to design our programs. Algorithm, Flowchart, and
Pseudo code are the basic tools used to design our programs.

Algorithm

An algorithm is a sequence of procedures arranged in a specific order to
solve a problem. It is written in simple English with some mathematical
notation. Algorithm helps programmer to think logically and find out the
best way to solve a problem.

Persian scientist, astronomer and mathematician
Abdullah Muhammad bin Musa al-Khwarizmi
created the term “Algorithm” in the 9th Century.

A good algorithm should:

Simple, complete, and step-wise.
Helpful to understand problems.
Be clear and unambiguous.

216Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Examples:
Suppose you have to complete a program in which you have to prepare a cup
of milk-tea. Now, what will be your algorithm? A sample algorithm goes like
this:

Algorithm 1 : To make a cup of milk-tea

Step 1 : Start
Step 2 : Fill the cup with water (half cup)
Step 3 : Turn-on the stove/burner
Step 4 : Place utensil on the burner
Step 5 : Pour the water from the cup in the utensil
Step 6 : Put 2 spoons of sugar in the boiling water
Step 7 : Pour the milk into the boiling water
Step 8 : Put the tea leaves in the vessel of boiling milk and water
Step 9 : Let it boil for few more minutes
Step 10 : Turn the burner off
Step 11 : Pour the tea through the sieve into the cup
Step 12 : Serve the Tea
Step 13 : Stop

Algorithm 2 : To find the sum of any two numbers

Step 1 : Start
Step 2 : Ask first number and store as A
Step 3 : Ask second number and store as B
Step 4 : Add A and B and store as C
Step 5 : Display the value of C
Step 6 : Stop

217 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Algorithm 3 : To display the greater number from two numbers

Step 1 : Start
Step 2 : Ask first number and store as A
Step 3 : Ask second number and store as B
Step 4 : Is A > B ?

If yes, Display A
If No, Display B
Step 5 : Stop

Algorithm 4 : To display the first 5 natural numbers

Step 1 : Start
Step 2 : N=1
Step 3 : Display N
Step 4 : N = N + 1
Step 5 : Is N < = 10

If Yes, go to step 3
If No, go to step 6
Step 6 : Stop

Flowchart

Flowchart provides a visual representation of your program. It shows a
sequence of operations in a computer program diagrammatically. It uses
some standard symbols to represent the operations.

218Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Flowchart Symbols Description
Rounded Rectangle

Start/End block. Represents START and
END of the program.
Parallelogram

Input/output block. Represents input and
output of data.
Rectangle

Process block. Represents process,
formula or function.

Diamond Shape

Decision block. Represents any decision in
the program.

Circle

Connector. Used to link to segment of
flowchart.
Arrows

Flow lines. Used to show the direction of
flow of program.

Advantages of Using Flowchart

Effective Analysis : A problem can be analysed easily with
the help of a flowchart.

Proper Documentation : It provides a good program
documentation for future use.

Efficient Coding : It guides the programming what to
code to solve a specific problem.

219 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Examples:

Flowchart 1 : To add any two numbers

Start

Ask the 1st number as A

Ask the 2nd number as B

C=A+B

Display C

Stop

220Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Flowchart 2 : To find the greater number among two numbers

Start

Ask the 1st number as A

Ask the 2nd number as B

Is Yes
A> B ? Display A

No
Display B

Stop

221 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Flowchart 3 : To display the first 5 natural numbers

Start

N=1

Display N

N=N+1

Is Yes
N <= 5?

No

Stop

Pseudocode

Pseudocode (pronounced as SOO-doh-kohd) is an informal description
of program written in plain English. It is a “text-based” tool to design a
program. It is used for creating an outline or a draft of a program.
222Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Examples:

Pseudocode 1 : To check pass or fail:

If student’s mark is greater than or equal to 40
Print “Pass”

else
Print “Fail”

Pseudocode 2 : To calculate simple interest

Ask principal amount, rate, and time.

I = PTR
100

Display I

POINTS TO REMEMBER

An algorithm is a step-by-step procedures written in simple English to
solve a problem
A flowchart is a diagrammatic representation of a program.
A flowchart uses different standard symbols to show the flow of
program.
A pseudocode is an informal description of a program.

223 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Exercise

1. Tick (√) the correct options:

a) Used to link segment of a flowchart.

(i) Rectangle (ii) Circle (iii) Parallelogram (iv) Square

b) Step-by-step procedure of a program is …………………………. .

(i) Program Logic (ii) Decision (iii) Algorithm (iv) Flowchart

c) Diagrammatic representation of a program is …………………………. .

i) Algorithm (ii) Program Logic

(iii) Graphics (iv) Flowchart

d) Process block is …………………………. in shape.

i) rectangle ii) rounded rectangle iii) diamond iv) parallelogram

e) A parallelogram is used to show …………………………. in a flowchart.

i) input/output ii) direction iii) process iv) decision

2. State whether the following statements are true or false:
a) A rectangular box is used for input and output.
b) A pseudocode is a pictorial representation of a program.
c) A flowchart is written in a computer language.
d) Each flowchart can have more than one Start and Stop block.
e) Flow lines connect the parts of a flowchart.

3. Fill in the blanks:
a) A pseudocode is a .............. description of a program.
b) A flowchart is a ............... representation of a program.
c) A ......... is used to represent input and output steps in a flowchart.

224Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

d) The ............. symbol is used for decision-making.
e) ............. box is used to make decisions.

4. Write down the technical terms for the following:
a) A step-by-step solution to a problem.
b) A graphical representation of a program.
c) An informal description of a program.

5. Answer the following questions:

a) Define algorithm with an example.
b) What are the features of a good algorithm?
c) Define flowchart. What are the advantages of using flowchart?
d) Define Pseudocode with an example.

e) Draw a table to illustrate the various symbols of the flow chart with their
uses.

Flowchart Symbols Uses

Develop Yourself

1. Prepare algorithm, flowchart, and pseudocode for the following problems:
a) Find the difference and product of any two numbers.
b) Check whether a given number is odd or even.
c) Display the first 10 even numbers.

225 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Worksheet

1. Complete the crossword puzzle given below:

ACROSS DOWN

3 I show the direction of program. 1 If you have to make decision, use

5 I represent input or output. me.

8 Provide data to the program. 2 Use this structure if you want to
9 I am a rectangle in a flowchart. repeat a sequence of steps.

4 Diagrammatic representation of a

program.

6 I am written in steps.

7 Use me if you have to connect
the segment of a flowchart.

2 1
56 3

4

7
8

9

226Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

2. A, B, C are the marks obtained by a student in Science, Math, and Science.
Refer the given flowchart and answer the questions.

Start a) Let’s assume that the user supplied
Read A,B,C 45, 50, and 75 as Nirmala’s marks.
Total = A+B+C Write down the steps to show how the
Percent = Total/3 program calculates her percentage.
Print Percent
.A..=....4..5..,..B..=....5..0..,..C..=...7..5............................

............................................................

............................................................

b) Students whose percent is above
80 will be awarded an achievement
badge. Fill the empty flowchart
elements with the suitable phrases.

c) Does Nirmala receive an achievement
badge or not?

Yes No

d) Examine the table below and fill in the
blanks with the required output.

Nitu English Math Science
Atul 55 65 75
Bhola 45 95 90
80 75 95

Total Percent Badge (Yes/No)
Nitu
Atul
Bhola

Stop e) Rashila scored 65 in English and 80 in
Math. What is the minimum marks she
should score in Science to receive the
achievement badge?

Ans:

227 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

3. The following empty flowchart gives the steps to prepare a cup of tea. The
phrases to be filled in the boxes are also given the. Complete the flowchart
by filling in the number of the corresponding phrase, inside each box. For
example, the number corresponding to the first box in the flowchart is 5.

5 1. Do you want milk?

Yes 2. Pour milk
No
3. Serve now

4. Add sugar

5. Start

6. Switch on the Gas
Stove

7. Boil the mixture

8. End

9. Pour the tea leaves

10. Place the bowl with
water on the Gas
Stove

11. Do you want sugar?

Yes
No

228Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Lesson

15

Introduction to QBASIC

You have used many software like MS-Paint, MS-Word, Adobe Photoshop,
Google Chrome, and many others to do different tasks in computer. They are
used to provide instructions to the computer to accomplish your tasks. Now,
it is the time to learn how to create such programs. This lesson provides you
the basic idea of writing a program.

QBASIC is a high level programming language. The full form of QBASIC
is Quick Beginner’s All-purpose Symbolic Instruction Code. It is simple and
easy to learn. QBASIC is an interpreter as it translates in the program
one statement at a time. In 1964, John G. Kemeny and Thomas E. Kurtz
designed the original BASIC language at Dartmouth College.

229 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Starting QBASIC

QBASIC may not be on your computer. At first, you need to have QBASIC
in your computer. It is freely available.

QBASIC

In Windows XP,

If you do not have QBASIC
in your computer, you can
download QBASIC from
https:// vedantapublication.
com.np/downloads and save
it in any location inside your
computer. For instance, we
have saved it in D: drive
with folder name QBASIC.

Go inside the folder D:\
QBASIC and double click on
the file QB.EXE.

Now, you see the QBASIC
window where you have to write QBASIC statements to make your
program.

In Windows 7, 8, or 10,

Since the QBASIC is an old programming language, you cannot directly
open this version of QBASIC like in Windows XP. You need to install an
emulator program like DOSBox.
Use the following steps to run QBASIC using DOSBox.
1. Download DOSBox from https://www.dosbox.com
2. Install DOSBox by simply double clicking on the

installation file.

230Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

3. After the installation of DOSBox, its shortcut icon appears on the
desktop.

4. Open the QBASIC folder and select the file QB.EXE.
5. Drag and drop on the icon of DOSBox on your desktop.

6. QBASIC opens inside DOSBox.

QB64

QB64 is developed with the same features of QBASIC to run in Windows
7, 8, or 10 without DOSBox. We can easily write, edit, debug, and execute
QBASIC program in QB64.
1. Download QB64 from https://www.qb64.org.
2. Unzip or extract the file.
3. Double click on QB64.exe to run QBASIC.

In this chapter, you learn programming using QB64 IDE (Integrated
Development Environment).

231 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Title Bar Vedanta Let’s Log in Computer Science | Book 8

Menu Bar
QBASIC Code

Status Bar Displays the status of code (Displays error message for any syntax error)

QBASIC IDE

Features of QBASIC

It is a user-friendly language.
It is simple and easy to learn.
Variables can be named easily and it uses simple English phrases with
mathematical expressions.
It capitalizes the reserved words automatically.
The syntaxes of the statements are checked automatically.

Your First Program

Run QBASIC and type the statements below.

PRINT “hello world”
END

232Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Running (executing) your program

Press F5 button of your keyboard. Now, you see the output screen as below:

This is a sample program to display the words “hello world” on the output
screen.

Getting out

If you need to leave QBASIC, you can click on “File” on QBASIC’s menu and
then “Exit”.

Variable

While running your program you have to provide data for calculation.
Variable is a place where your data is stored for the purpose of processing
during run-time of your program. A variable allocates the space of computer’s
memory (RAM).

233 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Some rules for naming variables

Variable name must start with an alphabetic character.
You cannot use any keyword (reserved word) for variable name.
Variable allocates certain space of RAM based on the data type it holds.

So, think carefully while declaring the variable type.
Each variable name is followed by a symbol. The symbol refers to the

data type it might hold. For example, the $ (dollar) symbol is used in
string variable.

Few Examples

Variable Name Valid Invalid Reason

A1$ × Starts with alphabets and $ sign indicates
× the data type string.
1XYZ ×
PRINT First letter is numeric character
BC+
Keyword

Invalid symbol is used

Constants

A constant is an entity that does not change, whereas a variable is an entity
that may change.

Example
a=4

4
a
Since the location whose name is “a” can hold different values at different
times, a is known as a variable. As against this, “4 does not change; hence,
“4” is known as constant.

Types of Constants

Numeric Constant
It has only numbers from 0 to 9. For example: 45,456.35, -44, etc.

234Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

String Constant
It accepts both numbers and alphabets (alphanumeric values). Examples:
“Nepal”, “45.67”, “A45”, etc.

QBASIC Statements

A program is a set of instructions, which tells the computer what to do and
how to do it. These instructions within a program are called statements.
Each QBASIC statement contains a QBASIC keyword.

i) CLS statement

Purpose: To clear the display screen
Syntax:
CLS

Note: It is a good practice to start every program with CLS statement so that the
previously displayed content is erased before executing your new program.

ii) LET statement

Purpose: To assign a value to a variable.
Syntax:
[LET] variable=expression
Example:
LET A = 200
C$ = “SCHOOL”
Here, A is a numeric variable and the value 200 is assigned to A.
Similarly, C$ is a string variable and the value “SCHOOL” is
assigned to C$.

Note: In QBASIC, a value can be assigned to a variable without LET statement also.

235 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Example:
LET A=200
The above statement is equivalent to
A=200

iii) PRINT statement

Purpose: To display the output on the screen.
Syntax:
PRINT [expressionlist][{,|;}]

If all arguments are omitted, a blank line is printed.
If expressionlist is included, the values of the expressions are
printed on the screen.
The expressions in the list may be numeric or string expressions.
(String literals must be enclosed in quotation marks.)
The optional characters “,” and “;” are the separators.
Example:
N = 50
PRINT “I live in Kathmandu.”
PRINT 5;6
PRINT (3+2 + N) / 3

Note: You must enclose string constant with in double quotes (“”).
As a shortcut, use a question mark symbol (?) for PRINT.
Type this:

? “Programming is fun.”
and press <Enter>.

236Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Other Examples:
PRINT
A blank line is printed.

PRINT 2*8+5
Here the expression is 2*8+5 and the evaluated value of this
expression 21 (2*8+5=21) is printed.

PRINT “Nepal”
String literals “Nepal” enclosed in quotation marks is printed.

Similarly, the values of variables can be displayed in the following
ways.
INPUT “Type your name ”; N$
PRINT “Your name is ”;N$
INPUT “Type your roll number ”;r
PRINT “Your roll number is ”;r

Or you can write this statement.
PRINT “Your name is ”;N$; “ and your roll number is ”;r

Try these statements:
PRINT N$;r
PRINT N$,r

Now find the difference in the output using ; and , as a separator.

iv) INPUT statement

Purpose: To read input from the keyboard during program execution
and store it into a list of variables.

237 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Syntax:
INPUT[;][“promptstring”{;|,}]variablelist

variablelist is one or more variables separated by commas
promptstring, if used, is displayed on the screen to tell the user
of the program what to enter at the keyboard
the characters “;” and “,” are the separators

Example:
INPUT “Type First Number”;a
Here, a is a numeric variable.
“Type First Number” is a promptstring

Note: You can also ask more than one value from single INPUT statement.
INPUT “Type any two numbers:”; a, b
Here, comma (,) is used to separate the list of variables.
INPUT a, b
The above statement is also valid without promptstring.

v) END statement

You have already the END statement to terminate your program.

Purpose: It is a declaration that ends a QBASIC program.
Syntax and Example:
END

Note: END statement is also used to terminate function, IF construct, sub procedure,
etc., which are covered in the next chapter.

238Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

vi) REM or ‘ statement [Comments]

Comments may be included in a QBASIC program to describe the
purpose or to clarify some portion of code in the program. In QBASIC, we
use REM or ‘ for comments.

Purpose: To write explanatory remarks (comments) to be inserted
in a program
Syntax:
REM remark or ‘ remark
Example:
REM to find the sum of two numbers
CLS
INPUT “Type any two numbers: “; a, b
PRINT “Sum = “; a + b
END

Bug and Debug

Bug : A problem or an error in a program is called bug.

Debug : Debug means to solve the problem or make the program bug
free.

Types of error or bug

a) Syntax Error
Syntax error is an error in the format of a statement in a computer

program that violates the rules of the programming. This type of error is
traced by the compiler or interpreter and provides the error message to the
programmer.

For e.g.
PRINT “NEPAL” – “Kathmandu”

239 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Here, according to the syntax of PRINT statement, the word NEPAL should
be enclosed in double quotes.

Displays the status of code (Displays
error message for any syntax error)

Error Message

b) Logical Error
A logical error is a bug in a program that causes it to operate incorrectly,

and gives the wrong output. It cannot be traced by the compiler or interpreter.
For e.g.
INPUT “Any two numbers “; a,b
c = a-b
PRINT “Sum = “;c
END
Here, the program has to calculate the sum but the output is their difference.
So, the program runs with incorrect output.

GOTO statement

Purpose: To forward the control of the program to the specified
location.

240Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Syntax:
GOTO {linelabel | linenumber}
linelabel or linenumber is the label of the line to execute next. This
line must be in the same procedure or subroutine as the GOTO
statement

Example:
CLS
PRINT “Kathmandu”
GOTO abc
PRINT “Birgunj”
abc:
PRINT “Biratnagar”
END

Output:
Kathmandu
Biratnagar
Here, abc is a linelabel. After displaying “Kathmandu”, the control is
transferred to “abc” and displayed “Biratnagar” bypassing the statement
PRINT “Birgunj”.

Conditional Statement Condition True

IF .. THEN … ELSE statement False Statement 1
Statement 1
Purpose: It is a control flow
statement that allows conditional
execution or branching, based on
the evaluation of an expression
that must be either true or false.

241 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

QBASIC Supports a Variety of IF Statement.

i) Single Line IF Statement

Purpose: It allows conditional execution based on the evaluation of
an expression that must be true.
Syntax:
IF booleanexpression THEN [statement]

booleanexpression is an expression that must return non-zero
(true) or zero (false)
statement consists of a task to be executed if the booleanexpression
returns true.

Example:
CLS
INPUT “Type your marks ”;m
IF m>=40 THEN PRINT “Pass”
END
Note: In the above program, if the booleanexpression m>=40 returns true, it
displays “Pass”. The program displays nothing if the value is less than 40.

ii) Single line IF … ELSE statement

Purpose: It allows conditional execution based on the evaluation of
an expression that must be either true or false.
Syntax:
IF booleanexpression THEN [statement1] ELSE [statement2]

Example:
CLS

INPUT “Type your marks ”;m

242Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

IF m>=40 THEN PRINT “Pass” ELSE PRINT “Fail”

END

Note: Statement1 is executed if the booleanexpression returns true; otherwise,
statement2 is executed.

iii) Multiline IF Statement

Purpose: To execute a block of statements based on the evaluation
of an expression that must be true.
Syntax:
IF booleanexpression THEN
[statementblock]
END IF

statementblock consists of any number of statements on one or
more lines.

Example:
CLS
INPUT “Type your marks ”;m
IF m>=40 THEN
PRINT “Pass”
PRINT “Congratulations”
END IF
END
Note: END IF terminates the multiline IF statement which is not required in
single line IF statement.

243 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

iv) Multiline IF … ELSE statement

Purpose: To execute a block of statements based on the evaluation
of an expression that must be either true or false.
Syntax:
IF booleanexpression THEN
[statementblock-1]
ELSE
[statementblock-2]
END IF

Example: Condition True
CLS
INPUT “Type your marks ”;m False Statement 1
IF m>=40 THEN Statement 1
PRINT “Pass”
PRINT “Congratulations”
ELSE
PRINT “Fail”
PRINT “Work hard”
END IF
END
(c) Looping Structure
Looping is the process of
repeating the execution of a
statement or a block of statements
guided by a condition. A loop
is terminated when the given
condition is satisfied.

244Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Example of using loop:

Example:
CLS
n=1
top:

PRINT “Nepal”
n=n+1
IF n <= 5 THEN GOTO top
END

Flowchart of the above program is: Memory table of dry run
Start n OP (Output)
1 Nepal
n=1 2 Nepal
3 Nepal
Print “Nepal” 4 Nepal
5 Nepal
n <= 5 ? Yes 6

No ? The output of the
above program is
Stop Nepal
Nepal
Nepal
Nepal
Nepal

Here the statement PRINT “Nepal” is executed 5 times till the condition
n<=5 is true.

245 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Few sample program in QBASIC

Program1 : To find the product of 34 and 89

REM Difference between 34 and 89
CLS
a = 34
b = 89
c=a*b
PRINT “Product is “;c
END

Program2 : To calculate Simple Interest

REM Calculate Simple Interest
CLS
INPUT “Type Principal Amount “; p
INPUT “Type Time “; t
INPUT “Type Rate “; r
i = p * t * r / 100
PRINT “Simple Interest = “; i
END

Program3 : To find area and volume

REM Calculate area and volume
CLS
INPUT “Type length, breadth & height of a room “; l, b, h
a=l*b
v=l*b*h
PRINT “Area = “; a
PRINT “Volume = “; v
END

246Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Program4 : To check odd or even

REM To check odd or even
CLS
INPUT “Type any number “; n
IF n MOD 2 = 0 THEN
PRINT “The number is even.”
ELSE
PRINT “The number is odd.”
END IF
END

Program5 : To display the first 10 natural numbers

REM To display 1,2,3,…10
CLS
N=1
top:

PRINT N;
N=N+1
IF N<=10 THEN GOTO top
END

247 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

Exercise

1. Answer the following questions:
a) Define QBASIC.
b) Write down the characteristics features of QBASIC.
c) Differentiate between variable and constant.
d) What are QBASIC statements? Explain with few examples.

2. Write down the QBASIC code for the following problems:

a) A rectangular box is 10m long, 3m wide and 2m tall. Write a program to
calculate its area and volume.

b) A man bought a laptop at Rs. 55,600 and sold it at Rs. 61,700. Write a
program to calculate his profit percentage.

c) Write a program that accepts a radius of a circle and displays its diameter
and circumference.

d) Write a program that asks the length of a table in feet and calculates its
equivalent length in inches [Hint: 1 feet = 12 inches].

e) Write a program that asks any two numbers and displays their sum,
difference and product.

f) Write a program that asks base and height of a triangle and calculates its
base × height
area [Hint: Area of triangle = 2 ]

g) Write a program that asks your marks in English, Nepali and Computer

Science, and calculates your total marks and percentage.

h) Write a program that asks any two numbers and displays the greater one.

i) Write a program that asks any two numbers and displays the difference
between greater and smaller number.

248Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

j) Write a program that asks your marks in computer science and checks
whether you pass or fail if the pass mark is 40.

k) Write a program that asks your age and tells whether you are eligible to
vote or not. [A person who is 18 years old or above is eligible to vote.]

l) Write a program to generate the series below:

i) 10, 9, 8, …. 1

ii) 5, 10, 15, 20 ….. 50

iii) 2, 4, 6, 8, 10, … up to 20th terms

3. Write down the output of the program below:
a) CLS
n=4
c=1
top:
PRINT n;
n=n+c
c=c+1
IF c <= 5 THEN GOTO top
END

b) CLS
r=3
p = 10
one:
PRINT r;
r=r+p
p=p-1
IF p >= 6 THEN GOTO one
END

249 Approved by Curriculum Development Centre, Sanothimi, Bhaktapur

Vedanta Let’s Log in Computer Science | Book 8

c) CLS
b=5
n=1
top:
PRINT b;
s=s+b
b=b+n
n=n+1
IF n <= 5 THEN GOTO top
PRINT s
END

4. Re-write the following program after correcting the bugs.
a) REM To find the smaller number
CLS
INPUT “Type any two numbers “; a; b
IF a < b THEN
PRINT b; “ is smaller”
ELSE
PRINT a; “ is smaller”
END

b) REM to display 5 4 3 2 1
CLS
a=5
top:
PRINT a;
a=a+1
IF a <= 1 THEN GOTO top
END IF
END

250Approved by Curriculum Development Centre, Sanothimi, Bhaktapur


Click to View FlipBook Version