Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
330 views

Planning The Computer Program

The document discusses planning computer programs by first understanding the problem manually, ensuring the program logic and sequence are correct. It defines an algorithm as a step-by-step process to solve a problem, and must be precise, finite, non-repeating, and produce the desired results. Algorithms can be represented as programs, flowcharts, or pseudocode. It provides examples of bonus calculation and student result processing algorithms to illustrate the concepts.

Uploaded by

AHMED, FAYSAL
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
330 views

Planning The Computer Program

The document discusses planning computer programs by first understanding the problem manually, ensuring the program logic and sequence are correct. It defines an algorithm as a step-by-step process to solve a problem, and must be precise, finite, non-repeating, and produce the desired results. Algorithms can be represented as programs, flowcharts, or pseudocode. It provides examples of bonus calculation and student result processing algorithms to illustrate the concepts.

Uploaded by

AHMED, FAYSAL
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

Planning the Computer Program

12/07/21 1
Purpose of Program Planning
A programmer cannot write the
instructions to be followed by a computer
unless the programmer knows how to
solve the problem manually.

 To ensure that the program instructions


are appropriate for the problem and in the
correct sequence.

12/07/21 2
Algorithm

 The term algorithm is often used to refer


to the logic of a program.

 It is a step by step description of how to


arrive at the solution of the given
problem.

 It may be formally defined as a sequence


of instructions.
12/07/21 3
Characteristics of Algorithm
A sequence of instructions must process the
following characteristics:

 Each and every instruction should be precise and


unambiguous.
 Each instructions should be such that it can be
performed in a finite time.
 One or more instructions should not be repeated
infinitely. This ensure that the algorithm will
ultimately terminate.
 After performing the instructions, that is after the
algorithm terminates, the desired results must be
obtained.
12/07/21 4
Representation Of Algorithms

 There are various ways in which an algorithm can


be represented. Programmers normally use one or
more of the following ways to represent their
algorithms:

• As programs
• As flowcharts
• As pseudocodes

12/07/21 5
Sample Algorithms

 Example 1:
50 students in a class appeared in their final
examination. Their mark sheets have been given
to you. The division column of the mark sheet
contains the division (First, Second, Third or Fail)
obtained by the student. Write an algorithm to
calculate and print the total number of students
who passed in First division.

12/07/21 6
Sample Algorithms
Solution of Example-1:

Step 1:
Initialize Total_First_Division and
Total_Marksheets_Checked to zero.
Step 2:
Take the mark sheet of the next student.
Step 3:
Check the division column of the mark sheet
to see if it is FIRST. If no, go to Step 5.

12/07/21 7
Sample Algorithms
Step 4:
Add 1 to Total_First_Division.
Step 5:
Add 1 to Total_Marksheets_Checked.
Step 6:
Is Total_Marksheets_Checked=50?
It no, go to Step 2.
Step 7:
Print Total_First_Division.
Step 8:
Stop.

12/07/21 8
Sample Algorithms
 Example 2:
There are 100 employees in an organization. The
organization wants to distribute annual bonus to
the employees based on their performance. The
performance of the employees is recorded in their
annual appraisal forms. Every employee’s
appraisal form contains his basic salary and the
grade for his/her performance during the year.
The grade is of three categories – ‘A’ for
outstanding, ‘B’ for good and ‘C’ for average
performance.

12/07/21 9
Sample Algorithms
 Example 2 (Continued):
It has been decided that the bonus of an
employee will be 100% of the basic salary for
outstanding performance, 70% of the basic salary
for good performance, 40% of the basic salary for
average performance and zero for all other cases.
Write an algorithm to calculate and print the total
bonus amount to be distributed by the
organization.

12/07/21 10
Sample Algorithms
Solution of Example-2:

 Step 1:
Initialize Total_Bonus and
Total_Employees_Checked to zero.
 Step 2:
Initialize Bonus and Basic_Salary to
zero.
 Step 3:
Take the appraisal form of next
employee.
12/07/21 11
Sample Algorithms
 Step 4:
Read the employee’s Basic_Salary and
Grade.
 Step 5:
If Grade = A, then
Bonus = Basic_Salary. Goto Step 8.
 Step 6:
If Grade = B, then
Bonus = Basic_Salary x 0.7
Go to Step 8.
12/07/21 12
Sample Algorithms
 Step 7:
If Grade = C, then
Bonus = Basic_Salary x 0.4
 Step 8:
Add Bonus to Total_Bonus.
 Step 9:
Add 1 to the Total_Employees_Checked.

12/07/21 13
Sample Algorithms
 Step 10:
If Total_Employees_Checked < 100,
then go to Step 2.
 Step 11:
Print Total_Bonus.
 Step 12:
Stop.

12/07/21 14
Sample Algorithms
 Example-3 for Practice:
A student appears in an examination which
consists of total 10 subjects. The roll number of
the student, his/her name and the marks
obtained by him/her in various subjects are
supplied as input data. Write an algorithm to
calculate the average marks obtained by the
student in this examination and to print it along
with his/her roll number and name.

12/07/21 15
Sample Algorithms
 Example-4 for Practice:
For the examination of the previous example we
want to make a list of only those students who
have passed (obtained 30% or more marks) in
the examination. In the end we also want to print
out the total number of students who have
passed. If the input data of all students is
terminated by a trailer record which has sentinel
value of 999999 for Roll no, write an algorithm to
do this task.

12/07/21 16

You might also like