Flowcharts and Programming QBASIC
Flowcharts and Programming QBASIC
QBASIC
(Based on B.Ed. Curriculum)
Click2Solution.com
1.General Concept
1.1 Program and Programming
Program – A collection of sequential instructions
given to computer to carry out certain task.
Programming – The work of writing a set of
sequential instructions is called programming.
Programmer – The person who writes a set of
instructions to a computer.
1.General Concept
1.2 Programming language
A language used for expressing a set of
computer instructions.
A language medium between the computer and
the user in order to understand each other.
Responsible for the human – computer system
communication.
Consists of necessary symbols, characters and
grammar rules.
1.2 Programming language
Many computer language e.g., C, C++,
FORTRAN, PASCAL, COBOL, LISP,
BASIC, ALGOL etc.
BASIC – Beginners All Purpose Symbolic
Instruction Code.
GW-BASIC, BASICA, TURBO BASIC,
QBASIC are different versions of the
BASIC programming language.
1.3 Categories of Programming
Language
Programming
Languages
START
:
:
:
:
STOP
General symbols used in Flowchart
Input / Output (Parallelogram)
This indicates input or output of necessary information. In
this instructions of QBASIC like INPUT, READ, PRINT
etc. are used.
Read the
Phone No.
General symbols used in Flowchart
Flow Directions or Flow Lines
This is used to indicate the flow of program or
direction of the sequence of instruction. Generally
the direction are top to bottom or left to right.
A
General symbols used in Flowchart
Decision (Diamond)
This is used to indicate the decision stage from which the
flow of program has to branch to one between the two
choices. All the decisions processed here must produce
results in "Yes" or "No". This result depends on the test that
is performed inside this decision box. In this instructions of
the QBASIC like IF… … THEN etc. are used.
Alternate
Yes
Is There a
Dialtone ?
Standard
No
General symbols used in Flowchart
Example: Make an algorithm and then a flowchart in detail as far as possible, for the
tasks performed, while making a phone call.
One of the possible algorithms might look like this:
Yes
Is the phone No
Ringing?
Yes No
Has the phone No Has the bell
been picked? Stopped?
Yes Yes
Talk with other end
STOP
Manual Process into Programming
Flowchart START
STOP
Manual Process into Programming
Flowchart START
No Stop Students?
No
STOP
Manual Process into Programming
Flowchart
1. Develop an Algorithm to
add three numbers and Read N1, N2, N3
convert it into
Flowchart.
SUM = N1 + N2 + N3
2. Develop an Algorithm to
read two numbers and Read N1, N2
print the bigger number.
Convert it into
Flowchart. NO
Is N1 > N2?
NO Print N2
Stop
STOP
Examples – Algorithm & Flowchart
START
3. Develop an Algorithm
to find the biggest of
the three given Read N1, N2,
N3
numbers and convert
it into Flowchart.
NO
Read three numbers N1, N2 and
N3 Is N1 > N2?
Is N1 > N2
YES Is N1 > N3
YES
YES Print N1
NO Print N3
NO NO
NO Is N2 > N3
YES Print N2 Is N1 > N3? Is N2 > N3?
No Print N3
Stop
YES YES
STOP
START
Examples – Algorithm
Read N1, N2, N3
& Flowchart
3. Develop an Algorithm to find HNo = N1
the biggest of the three given
numbers and convert it into
Flowchart. [Alternate solution]
YES
Is N2 > HNo?
Read three numbers N1, N2 and N3
HNo = N1 NO HNo = N2
Is N2 > HNo
YES
YES Store N2 to HNo Is N3 > HNo?
Is N3 > HNo
YES Store N3 to HNo NO
HNo = N3
Print HNo
Stop
PRINT HNo
STOP
Examples – Algorithm & Flowchart
4. Develop an Algorithm START
Flowchart.
SUM = N1 + N2 + …+N10
Initialize SUM = 0
Read the numbers N1, N2, …, N10
SUM = N1+N2+ … + N10 Write SUM
Write SUM
Stop
STOP
Examples – Algorithm START
FOR number
4. Develop an Algorithm to 1 to 10
Stop
STOP
Examples – Algorithm & Flowchart
START
A
NO
A
Flowchart Exercise
Using standard flowcharting symbols draw a flowchart to convert
a temperature in degree Celsius into degree Fahrenheit.
Draw a flowchart to find the greatest number among ten numbers
and display the greatest number.
Draw a flowchart to find the square and cube of the given number
and display the result.
Draw a flowchart to find the middle number among three numbers
and display it.
Write algorithm and flowchart to find the volume of a box with
given Length, Breadth and Height and display the input and the
results.
1.6 Algorithm and Flowcharts
Advantages of Flowchart:
Representing algorithm by flowchart and then converting
it to computer program is easier and accurate than writing
the program directly.
Flowchart is an important aid in the development of
programming algorithm.
Flowchart is easier to understand than the program
Flowcharts are independent of any programming
languages. Hence, the algorithm given by a flowchart can
be translated in to more than one programming language.
2. Introduction to QBASIC
QBASIC Programs are the advanced new form of BASIC
(Beginners All Purpose Symbolic Instruction Code)
BASIC programming language was jointly developed by
John G. Kemney and Tomas E. Kurtz in 1963-1964 in
Dartmouth college, New Hampshire, USA .
The instructions used in this language is very much
similar to English. Hence it is used to teach Computer
Programming to students in schools.
2. Introduction to QBASIC
2.1 Features of QBASIC
Very simple structured programming language.
Easy to follow logic, user friendly, high level programming
language.
Divided into modules within a program.
First language for any beginning programmer.
Instruction are very much similar to English e.g., READ, LET,
INPUT, GOTO, PRINT etc.
Easy to find syntax errors due to its own smart editor.
Easy to us since it has pull down menu.
Mouse also can be used in its latest versions.
2.1 Features of QBASIC
Numeric
Constant whose value is numeric e.g.,
899.50, -25.46, 97 etc. are Numeric Constant.
Among these those with decimal is called
Numeric Real Constant, e.g. 899.50, -25.46
etc. And those with integer only are called
Numeric Integer Constant, e.g., 97, -568, 0
etc.
3.2 Constants
String
A group of letters or numbers or both, which are
enclosed by a pair of " " (quotation marks), is called
String. E.g., "ABCD"; "Ramesh"; "10 Downing Street"
etc. The variable used to store these strings is called
String Variable. The name of string variable starts
with character and should ends with $ sign. E.g., LET
A$ = "Saturday"; LET CITY$ = "Kathmandu"; LET
Adress$ = "10 Downing Street"; LET TEL1$ =
"654345" etc. Constant whose value is a string e.g.,
899.50, -25.46, 97 etc. are Numeric Constant
3. Elements of QBASIC Programming
Language
3.3 Variables
Simply defined, variable is a name, which can contain a value.
Programming involves giving values to these names and
presenting them in some form to the user.
A variable has a type, which is defined by the kind of value it
holds.
If the variable holds a number, it may be of integer, floating
decimal, long integer, or imaginary.
If the variable holds symbols or text, it may be a character
variable or a string variable. These are terms you will become
accustomed to as you continue programming.
3.3 Variables
cost#
cost&
The Data Type can be Integer, Long integer, Single precision, Double
precision or String.
The first string variable EXP1 is a variable length string variable ( can store
0 to 32767 characters).
The second variable EXP2 is a fixed length string variable, in which
STRING * 4 indicates that it can hold only maximum of 4 characters.
Using DIM AS statement
Example:
CLS
X% = 25
Y% = 9
Sum% = X% + Y%
Print “Total is “; Sum%
END
+ Addition A + B OR 10 + 5
- Subtraction C – D OR 30 – 23
* Multiplication P * Q or 12 * 5
/ Division R / S OR 35 / 7
No. QBASIC
(i) x+y+z
(ii) L*B
(iii) x/y
(iv) P*Q/S
(v) 3 * x^2 + y
3.4 Operators
Relational operators (=, >, <, >=, <=, <>)
used to compare two or more values. Using this we can compare
value/s of variable/s with a constant. In QBASIC the following relational
operators can be used.
Example:
(ii) If FNAME$ = "RAM" and MNAME$ = "KRISHNA" then we can join them
as FNAME$ + " " + MNAME$, whose value becomes "RAM KRISHNA".
Conditions Outcome
I II I OR II
True True True
True False True
False True True
False False False
• If both the conditions I and II are true or either is true, the outcome
becomes true.
• Only when both the conditions are false the outcome also becomes
false.
3.4 Operators – NOT
Condition Outcome
I NOT I
True False
False True
A$ = "FILE": B$ = "NAME"
PRINT A$ + B$
PRINT "NEW " + A$ + B$
Output:
FILENAME
NEW FILENAME
3.5 Expression - String expression
Strings can be compared using the following relational operators: <>, =, <,
>, <=, and >=
Note that these are the same relational operators used with numbers.
String comparisons are made by taking corresponding characters from each
string and comparing their ASCII codes.
The following are examples of true string expressions:
"AA" < "AB"
"FILENAME" = "FILE"+"NAME"
"X&" > "X#"
"CL " > "CL"
"kg" > "KG"
"SMYTH" < "SMYTHE"
B$ < "9/12/78" 'where B$ = "8/12/85"
String comparisons can be used to test string values or to alphabetize
strings.
All string constants used in comparison expressions must be enclosed in
quotation marks.
3.6 Statements
Keyword in any programming language that instructs the computer
to carryout the actions that we want is called commands.
In QBASIC or any programming language it is necessary to learn its
keywords, before embarking on writing programs.
A collection of commands used in the lines of a program is called
statements.
When the program is executed, the statements inside are executed
one after another in a controlled sequence.
Like all programming language, QBASIC also has its own grammar
and vocabulary.
They are used to check the syntax of commands and statements in
a program when it is executed.
It gives message about the validity of commands and statements
based on this.
3.6 Statements
According to the programming tasks, statement can
be generally grouped into four categories.
1. Assignment Statement
2. Declaration Statement
3. Input / Output Statement
4. Control Statement
Besides these, others commands not inside above
classifications are:
file system commands,
string manipulation commands,
mathematical calculation,
procedure definition commands and
commands used in calling other procedures.
3.6 Statements – 1. Assignment Statement
A statement used to assign value of a variable is
called Assignment Statement. e.g.,
LET A = 25
B = 17
LET C = A* B
LET Y = C
a. CONST PI = 3.141593
b. DIM A(4,4)
c. REM This program gives the sum of integers
d. SWAP a%, b%
In this way up to the end, the values of Cost are accumulated in the variable Amount.
This accumulator can be used in mathematical calculations in program.
Some Important concepts used in programming.
IF 25 <= 26 THEN
PRINT "Qbasic is fun!"
ENDIF
IF 6 > 9 THEN
PRINT "Black and Gold Dance this Friday!"
ENDIF
Exercises
60. What would the output of the following program be?
number1% = 100
number2% = 97
IF number1% < number2% THEN
PRINT "Halloween is on Friday"
ENDIF
61. What would the output of the following program be?
IF "a" < "b" THEN
PRINT "Now we are testing strings."
ENDIF