Basic programming civic nd1
Basic programming civic nd1
CONCEPT OF PROGRAMMING
A program is a set of instructions that tells the computer what to do. Computer
programming (often shortened to programming or coding), is the process of
writing, testing, debugging/troubleshooting and maintaining act of instructions
(source code) for solving a problem with the computer. A source code is written in
an acceptable computer programming language. The code may be a modification
of an existing source or something completely new.
The purpose of programming is to create a program that exhibits a certain
described behavior (customization). The process of writing source code requires
expertise in many different subjects, including knowledge of the application
domain. Alternatively, Programming is the craft of transforming requirements into
something that a computer can execute. Problem solving on computer is a task of
1
expressing the solution to the problem in terms of simple concepts, operations and
computer code (program) to obtain the results. To achieve this aim, you may
proceed as follows.
1. First, understand the problem clearly: - Decide what you want to be calculated
by the computer. What will be the input data required? (if any). This is the problem
formulation.
2. Write the steps of computation that are necessary to arrive at the solution. This is
setting up the algorithm.
3. Prepare a flowchart corresponding to the algorithm.
4. Develop the computer program. Test and run it on the computer.
There is an ongoing debate on the extent to which the writing of programs is an art,
a craft or an
engineering discipline. Good programming is generally considered to be the
measured application art, craft and engineering, with the goal of producing an
efficient and maintainable software (program) solution. The discipline differs from
many other technical professions in that programmers generally do not need to be
licensed or pass any standardized (or governmentally regulated) certification tests
in order to call themselves “programmers” or even “software engineers”.
Concept of Algorithm
An algorithm is a set of instructions to obtain the solution of a given problem or
this is broadly referring to the systematic steps or procedures used to accomplish a
task. It can also be defined as a sequence of instructions, which are followed in
order to complete a task. Computer needs precise and well-defined instructions for
finding solution of problems. If there is any ambiguity, the computer will not yield
the right results. It is essential that all the stages of solution of a given problem be
specified in details, correctly and clearly moreover, the steps must also be
organized rightly so that a unique solution is obtained.
2
Algorithm may be set up for any type of problems, mathematical/scientific or
business. Normally
algorithms for mathematical and scientific problems involve mathematical
formulas. Algorithms for business problems are generally descriptive and have
little use of formula.
FUNCTION OF ALGORITHM
1. An algorithm is used to gives sense of direction to the steps of solving
problem.
2. It provides the step-by-step solution to a problem
3. It is used to prove that a problem has a solution.
Features of an Algorithm
1. It should be simple
2. It should be clear with no ambiguity
3. It should head to unique solution of the problem
4. It should involve a finite number of steps to arrive at a solution
5. It should have the capability to handle unexpected situation.
3
Divide the sum by three.
Write out the result.
Example2: find the average age of 30 students in a class.
Answer
Obtain the age of each student
Sum up the ages
Divide total age by 30
Record the average age.
Example3: X and Y are related by equation y=3x-7. calculate the value of Y, given
any value of X
Answer
Obtain the value of x
Multiple X by 3
Subtract 7
Write down the value of Y.
FLOWCHART
Flowchart is a representation of the algorithm using standard symbols. It can also
be defined as a diagrammatical representation of essential of symbols and arrows
of flows lines. It is graphical representation of an algorithm. Each symbols have a
new function. The Algorithm steps determine which symbol to use to represent it
in the flow each step is linked to another step by using the directional arrows.
4
Diamond: this is used for decision making.
USES OF FLOWCHARTS
1 It gives us an opportunity to see the entire system as a whole.
2 It makes us to examine all possible logical outcomes in any process.
3 It provides a tool for communicating i.e., a flowchart helps to explain the system
to others.
4 To provide insight into alternative solutions.
5 It allows us to see what will happen if we change the values of the variable in the
system.
5
6 Analysis: flowcharts help to clarify the logic of a system i.e.; the overall picture
of the organization can be seen.
7 Consistency: A flowchart is a consistent system of recording. It brightens at the
relationships between different parts of a system.
Flowchart example
1. Draw a flowchart of the program to calculate the number of two integers
start
Read n1, n2
Sum=n1+n2
Print sum
Stop
INTRODUCTION TO QBASIC
BASIC stands for Beginner’s All Purpose Symbolic Instruction Code. It was
invented in 1963, at Dartmouth College, by the mathematicians John
George Kemeny and Tom Kurtzas.
6
BASIC is an interpreter which means it reads every line, translates it and
lets the computer execute it before reading another. Each instruction starts
with a line number.
FEATURES OF QBASIC
1. It is a user-friendly language.
2. It is widely known and accepted programming language.
3. It is one of the most flexible languages, as modification can easily be
done in already existing program.
4. Language is easy since the variables can be named easily and uses
simple English phrases with mathematical expressions.
RULES OF QBASIC
Every programming language has a set of rules that have to be followed
while writing a program, following are some rules of QBASIC language:
1. All QBasic programs are made up of series of statements, which are
executed in the order in which they are written.
2. Every statement should have at least one QBasic command word.
The words that BASIC recognizes are called keywords.
3. All the command words have to be written using some standard rules,
which are called “Syntax Rules”. Syntax is the grammar of writing the
statement in a language. Syntax Errors are generated when improper
syntax is detected.
QBASIC DATA
Data is a collection of facts and figures that is entered into the computer
through the keyboard. Data is of two types:
7
e.g., “Computer”, “Operating System”
2. VARIABLE: Data whose value is not constant and may change due to
some calculation during the program execution. It is a location in the
computer’s memory, which stores the values. Depending on what value is
held, Variables are of two types:
(a) NUMERIC VARIABLE: The variable that holds a Numeric
Constant for arithmetic calculations (+, - ,*, / ) is called a
Numeric Variable. e.g. A = 50, here A is the Numeric Variable
QBASIC Operator
Operators in QBasic are used to perform different mathematical,
logical and comparison operations. There are three types of
operators in QBasic:
1. Arithmetic Operators:
A computer performs many arithmetic operations and calculations
with the help of arithmetic operators.
2. Relational Operators
These operators are used to compare two values using any of the
given relational operators. This can be called a QBasic comparison
operator.
3.LOGICAL OPERATORS
8
Logical operators in QBasic are used to perform logical operations on
numeric values. QBasic Logical operators are used to combine two or
more relational expressions and return a single value as TRUE or FALSE
in a decision. The logical operators are: AND, OR, NOT.
• Direct Mode
• Program Mode
1. Direct Mode: The accepts single line instructions from the user and
the output is viewed as soon as enter key is pressed. The instructions
are not stored in the memory. This mode can be used to do quick
calculation. They do not have line numbers. E.g. Print 3+4
Print “This is the Direct mode in QBasic”
2. Program Mode: The mode is used to type a program which is stored
in the memory. They have line numbers. We have to give the
command to get the output. e.g.
10 Print 3+4
20 End
RUN
Programs are built up with set of instructions or commands. Every
programming language has its own SYNTAX (rules) and COMMANDS.
COMMAND/KEYWORDS IN QBASIC AND THEIR FUNCTIONS:
QBASIC COMMANDS
Print 80 * 8
5. INPUT: This statement allows the user to enter a value for the
variable while running the program. A question mark (?) appears on
the output screen waiting for the user to enter a relevant data and
then press enter key. Once the Return key or Enter key is pressed
the data is stored in the variable. SYNTAX : INPUT < VARIABLE >
11
Print with Semi-Colon (;) Semi-colon placed after the message to be
displayed, leaves no space between two messages.
e.g. Print “This is an example”;” of
QBASIC REMINDER
RUNNING A PROGRAM
RUN is the command used to execute the program and get the output on
the screen.
12
13