Chapter # 1
Problem Solving
Chapter # 2
Chapter # 3
Control Structure
Chapter # 4
Arrays
Chapter # 5
Subprogram
and
Handling
Chapter # 6
Graphics in BASIC
Chapter # 7
Microsoft WORD
Designed by:
Muhammad Nadeem Khan
Johar Town Campus
File
Chapter # 1
Problem Solving
Q#1. What is Analysis Phase?
Ans: In this phase, a technique divide and conquer is used to solve big and complex
problem. In this phase, a problem is divided into smaller pieces, and each sub problem is
Solved independently and then solution of all sub problems is combined to get solution of
original problem. This process is also called top down design.
Example:
10 Cls
20 Input Enter Radius of circle, r
Enter r = 5
30 A= 3.14 * r * r
A= 3.14*5*5 => 78.5
40 Print Area = , A
Area = 78.5
50 end
Q#6. What is Algorithm?
Ans:
Algorithm was invented by a Mathematician Mohammad Bin Musa
Alkhawarizmi. It is a step by step procedure to solve a particular task.
Algorithm steps must be well defined clear and effective. Every algorithm must follow
these steps.
Get data (Input)
Perform Calculations (Processing)
Provide Result (Output)
Q#7. What is flow chart? What are different symbols of flow chart?
Ans: The graphical or pictorial representation of an algorithm is called flow chart. It
consists of many symbols.
Terminator symbol
It is oval shape which is used for start and stop of flow chart
Input/Output symbol
It is parallelogram shape which is used for taking input from
user or displaying output to user.
Processing symbol
It is rectangle shape which shows calculations or processing.
Decision symbol
It is diamond shape which is used for decision making.
Connector symbol
It is small circle shape which is used to connect flow from different sides.
Flow Lines
It is arrow shape which shows the direction of flow of the algorithm.
Chapter # 2
Data types, I/O statements
Q#1. What are modes of BASIC?
Ans: GW BASIC operates in two Modes
1. Direct Mode
2. Indirect Mode
Direct Mode:
InDirect Mode:
Example:
Character
Data Type
Example
Size in memory
$
%
!
#
String
Integer
Single precision
Double precision
Name$
Marks%
Avg!
Area#
String length
2 Byte
4 Byte
8 Byte
Chapter # 3
Control Structure
Q#1. What is control structure? What are its types?
Ans: Control structure is used to control the flow of execution of a program.
There are 3 types of control structure in BASIC.
1) Sequence control structure
2) Selection control structure
3) Repetition control structure
7
Sequence Control Structure:
In this structure, code is executed in the same order
in which it is written. No line is skipped. It is mostly used structure.
Syntax:
IF Condition THEN Statement
OR
IF Condition THEN Line number
Example:
70
80
100
9
FOR-NEXT Loop:
This loop is used to execute a set of statements for
specified number of times.
WHILE-WEND Loop:
This loop is used to execute set of statements until given
condition is true. When condition is false, loop terminates.
Example:
10
20
30
40
50
60
70
80
90
cls
REM this program prints asterisks
FOR I =1 to 5 step1
FOR J= 1 to J
Print *
Next J
PRINT
Next I
end
Chapter # 4
Arrays
Q#1. What is Array? What are its types?
Ans: An array is a collection of variables of same data type which are placed
contiguously (closely) to each other in memory.
Each array has a name and each array consist of elements which can be accessed
with the help of index value. Array is also called subscripted variable because it
store variables of same data type. We can access individual elements of array with
the help of subscript / index. By default index starts from zero. But it can be
started from 1 as well.
Types:
Array has two types
1-Dimensional Array (1-D)
2-Dimensional Array (2-D)
Syntax:
10
DIM arrayname (size)
Explanation:
DIM is key word used to declare array. Array name is valid
name similar to variable name. Size is the total number of elements which
are contained in array. It is a positive integer value.
Example:
DIM Marks (5)
Name of array is Marks and its size is 5.index from 0-4
Marks (0) Marks (1) Marks (2) Marks (3) Marks (4)
75
80
91
65
55
Syntax:
DIM arrayname (Row, Column)
Explanation:
DIM is key word used to declare array. Array name is valid
name similar to variable name. Row is the size of rows and Column is size
of columns contained in array. These are positive integer values. It has 2
indices Row 0-4 and Column 0-3
Example:
DIM Arr (5, 4)
Name of array is Arr and its size is 5x4=20 elements.
Arr(0, 0)
Arr(0, 1)
Arr(0,2)
Arr(0, 3)
10
Arr(1, 0)
33
Arr(1,1)
46
Arr(1, 2)
50
Arr(1, 3)
80
Arr(2, 0)
87
Arr(2, 1)
67
Arr(2, 2)
34
Arr(2, 3)
56
Arr(3, 0)
76
Arr(3, 1)
90
Arr(3, 2)
23
Arr(3, 3)
11
Arr(4, 0)
34
Arr(4, 1)
55
Arr(4, 2)
44
Arr(4, 3)
36
25
66
78
11
Syntax:
DIM subscripted var 1, subscripted var 2, subscripted var 3
Example:
DIM A (20), B (20), C (20)
DIM X (2, 3), Y (3, 5), Z (5, 7)
Array:
Subscripted variable (Array) is a variable which can store
multiple values of same data type.
Its value is used with the help of index/subscript.
Its elements occupy consecutive space in memory.
Ans:
10
11
12
13
CLS
DIM A(10)
SUM=0
FOR I =1 to 10 step 1
12
14
15
16
17
18
19
20
21
Chapter # 5
Subprogram and File Handling
Q#1. What is subprogram? What are its types?
Ans:
A main program is sub divided into small and manageable pieces which are called
subprogram.
It is a set of instructions which perform specific action/task. It can be reused any
number of times in a program. It is called by its name and it returns a value to the
position where it is called. It has two types.
Built-in functions
User defined functions
Built-in functions:
These are intrinsic functions which are developed by programmers
of BASIC language. These can be used by just writing their name (function call) and
providing parameters to these functions.
Example:
FIX (n), ABS(x), DATE$, LEFT$, VAL(X$) etc
User defined functions:
These are functions which are developed by user it self for
performing different tasks. Each function do specific task and return value.
These are also called procedures.
Example:
DEF FNX(Y) = (Y*Y + 1) / Y
13
Syntax:
FIX(x)
x is any fractional number.
Example:
PRINT FIX (-7.098)
OUTPUT:
-7
14
Ans:
Subroutine:
Function:
Q#7. What is file handling? What are necessary things for file handling?
Ans: Computer store textual data on files.
A file is a collection of related records.
File handling means to use GW BASIC to read data from or write data to a
text file.
For file handling we must know
1) Open existing file/Create new file.
2) Write data on file.
3) Read data from file.
4) Close file.
Chapter # 6
Graphics in BASIC
Q#1. What is SCREEN statement? Give syntax with example.
Ans:
This statement is used to select a screen mode appropriate for particular
Video hardware configuration. Mode numbers are from 0, 1, 2, 7, 8, 9, 10.
Syntax:
SCREEN [mode]
15
Example:
SCREEN 0 => text mode
SCREEN 1 => medium resolution color mode
SCREEN 2 => high resolution color mode
Syntax:
PALETTE [attribute, color]
Palette can be Even ( 0 ) or Odd ( 1 ).
Attribute is associated with actual display color.
This statement only works for the systems which are equipped with EGA.
Example:
Screen 1
Color 2,1
odd palette
Palette 2,4 magenta (2) is replaced with red(4).
16
x, y is a point center of circle or ellipse. Radius specify
radius of circle and color specify the color of circle and start and end
angle are radian measure for start and end of ellipse. Aspect describe ratio
of x-axis and y-axis.
Example:
CIRCLE (50,100), 10
CIRCLE (10, 40), 30, 1,, 1
Example:
COLOR 1,3,2
COLOR 2,1
COLOR 3,2
Chapter # 7
Microsoft WORD
Q#1. Write 5 features of MS Word.
Ans:
17
18
It provides information on document on bottom of the page.
Header and footer are used to insert following information on document.
i.
ii.
iii.
iv.
Page Numbers
Author Name
Full path
Current date and time etc.