01 - Introduction To Programming
01 - Introduction To Programming
PROGRAMMING }
INTRODUCTION
• A computer program is a sequential set of instructions written in a
computer language that is used to direct the computer to perform a
specific task of computation. (Chaudhuri, 2021)
• Set of instructions must be such that the tasks will usually be performed
sequentially unless directed otherwise.
• Each instruction in the set will express a unit of work that a computer
language can support.
• In general, high level languages, also known as 3GLs, support one human
activity at a time.
• The objective of programming is to solve problems using computers
quickly and accurately.
FLOWCHARTING AND ALGORITHMS
Step 1. Take the rice to be cooked. Step 8. Light the burner on the stove.
Step 2. Procure the container. Step 9. IF THE RICE IS BOILED
Step 3. Procure the water. THEN GOTO STEP 12
Step 4. Wash the rice in the water. ELSE GOTO STEP 10
Step 5. Put the rice into the container. ENDIF
Step 6. Pour water into the container. Step 10. Heat the container.
Step 7. IF WATER LEVEL = 1 INCH ABOVE THE RICE Step 11. Go to step 9.
THEN GOTO STEP 8 Step 12. Turn off the flame.
ELSE GOTO STEP 6 Step 13. Move the container off the stove.
ENDIF Step 14. Distribute the cooked rice.
Step 15. STOP.
FLOWCHARTING AND ALGORITHMS
• Task Analysis. From the concept of determining the average of two given numbers, we know
that the given numbers must be added together to obtain the sum first; the sum is then
divided by 2 to obtain the average. The flowchart for Problem 1.2 illustrates this idea.
EXERCISE
• Problem 1.3. Construct a flowchart to show how to obtain the volume of
a rectangular box.
• Task Analysis. We know that the formula to determine the volume of a rectangular box is
Volume = Length × Breadth × Height. To determine the volume of a rectangular box, we
need to know the length, breadth, and height of the box. When these values are multiplied
together, the product represents the desired volume.
EXERCISE
• Problem 1.4. Construct a flowchart to show how to obtain the daily wage
of a worker on the basis of the hours worked during the day.
• Task Analysis. The daily wage depends on two factors: the hours worked and hourly rate of
pay. When the hours worked is multiplied by the rate of pay, the product represents the wage
of the worker.
EXERCISE
• Problem 1.5. Construct a flowchart to show how to obtain the area of a
triangle on the basis of the base and height.
• Task Analysis. We know that the formula to find out the area of a triangle is
The inputs required to obtain the area of a triangle are its base and height.
We can then put the values in the above formula to obtain the area.
EXERCISE
• Problem 1.6. Develop a flowchart to show the steps in finding the simple
interest on a given amount at a given rate of interest.
• Task Analysis. Develop a flowchart to show the steps in finding the simple interest on a given
amount at a given rate of interest.
To determine the simple interest on a given amount, we need the principal amount (P), the rate of
interest (R), and the term in years (T). By putting the values in the formula above, we get the
desired simple interest.
EXERCISE
• Problem 1.7. If P amount of money is invested for N years at an annual
rate of interest I, the money grows to an amount T, where T is given by
T = P (1 + I/100)N. Draw a flowchart to show how T is determined
• Task Analysis. The solution to this problem is very simple, and it is similar to the preceding
one. The inputs required are the values for P, I, and N. The output T can then be obtained by
putting the values in the formula.
EXERCISE
• Problem 1.8. Construct a flowchart to show how a student’s registration
number and grades in 3 subjects, m1, m2, and m3, are displayed along
with the total average grade.
• Task Analysis. The data supplied as inputs are the registration number and grades obtained in
three subjects. The registration number contributes nothing to the process of deriving the
desired output; it just identifies the person about whom the total grade and the average grade
are obtained. The total grade can be obtained by taking the sum of the marks m1, m2,and m3,
and the average can be obtained by dividing the total by 3.
EXERCISE
• Problem 1.9. Draw a flowchart to show how to interchange the values of
two variables.
• Task Analysis. he task of interchanging the values of two variables implies that the values
contained by the variables are to be exchanged i.e., the data value contained by the first
variable should be contained by the second variable and that by the second variable should
be contained by the first variable.