COM 113 Lecture 1

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 39

FEDERAL COLLEGE OF AGRICULTURAL PRODUCE

TECHNOLOGY, KANO
DEPARTMENT OF COMPUTER SCIENCE

COURSE TITLE:
INTRODUCTION TO PROGRAMMING
COURSE CODE: COM113
UNIT :- 4 CREDIT UNIT
Instructor: Anas Muhammad Sani
CONTACT: anasmsani22@fcapt.edu.ng

1 1
Lecture Overview

• Theory
• Practical
• ASSESSMENT
– Examination 60%
– Practical 20%
– Test 15%
– Attendance 05%
– Total 100%
Note: You must have at least 75% attendance.
1 2
Lecture Overview

• Introduction
• Program, Programming, and Programmer
• Features of a good Program
• System Development life cycle
• Algorithm
• Features of a good Algorithm
• Methods of representing Algorithm

1 3
INTRODUCTION TO PROGRAMMING

• A program is a set of instructions that tells the


computer what to do or in other words Computer
Program, set of instructions that directs a computer
to perform some processing function or
combination of functions.
• For the instructions to be carried out, a computer
must execute a program, that is, the computer reads
the program, and then follows the steps encoded in
the program in a precise order until completion.
1 4
INTRODUCTION TO PROGRAMMING

• A program can be executed many different times, with


each execution yielding a potentially different result
depending upon the options and data that the user gives
the computer.
• Programs are commonly referred to as software.
Software is essential to a computer because without
software, a computer can do nothing. All of the software
that we use to make our computers useful is created by
individuals known as programmers or software
developers.
1 5
INTRODUCTION TO PROGRAMMING

• A programmer, or software developer, is a


person with the training and skills necessary to
design, create, and test computer Programs
• Today you will find programmers working in
business, medicine, government, law
enforcement, agriculture, academics,
entertainment, and almost every other field.

1 6
INTRODUCTION TO PROGRAMMING
• Computer programming (often shortened to programming or
coding), is the process of writing, testing,
debugging/troubleshooting and maintaining of instructions
(source code) for solving a problem with the computer.
• Programming is the process of taking an algorithm and
encoding it into a notation, a programming language, so that
it can be executed by a computer.
• A source code is written in an acceptable computer
programming languages such as Basic, VB, C++, Java, and so
on. The code may be a modification of an existing source or
something completely new.

1 7
INTRODUCTION TO PROGRAMMING
• Computer programming is both an art and a science. It is an
art because every aspect of a program should be designed
with care and judgment. Listed below are a few of the things
that must be designed for any real-world computer program:
• The logical flow of the instructions
• The mathematical procedures
• The appearance of the screens
• The way information is presented to the user
• The program’s “user-friendliness”
• Manuals and other forms of written documentation
1 8
INTRODUCTION TO PROGRAMMING
• 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 expressing the
solution to the problem in terms of simple concepts,
operations and computer code (program) to obtain the
results.
1 9
INTRODUCTION TO PROGRAMMING
• 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 expressing the
solution to the problem in terms of simple concepts,
operations and computer code (program) to obtain the
results.
1 10
INTRODUCTION TO PROGRAMMING
• 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.
1 11
INTRODUCTION TO PROGRAMMING
• FEATURES OF A GOOD COMPUTER PROGRAM
• 1) Reliability 9) Efficiency
• 2) Meeting User’s Needs: 10) Usability
• 3) Error-Free Set of Instruction
• 4) Error-Resistant Operations
• 5) Maintainable Code
• 6) Portable Code
• 7) Readability
• 8) Storage Saving
1 12
INTRODUCTION TO PROGRAMMING
• SYSTEM DEVELOPMENT CYCLE
• Most IT projects work in cycles. First, the needs of the
computer users must be analyzed.

• Feasibility Study
• Design
• Programming
• Implementation

1 13
INTRODUCTION TO PROGRAMMING
• COMPUTER SCIENCE
• Computer science is the study of problems, problem-
solving, and the solutions that come out of the problem-
solving process.
• Given a problem, a computer scientist’s goal is to develop
an algorithm, a step-by-step list of instructions for solving
any instance of the problem that might arise.

1 14
INTRODUCTION TO PROGRAMMING
• ALGORITHM:
• An algorithm is a set of well-defined steps for performing
a task or solving a problem.

• Algorithms are finite processes that if followed will solve


the problem. Algorithms are solutions.

1 15
INTRODUCTION TO PROGRAMMING
• ALGORITHM:
• 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.

• the steps must also be organized rightly so that a unique


solution is obtained.

1 16
INTRODUCTION TO PROGRAMMING
• ALGORITHM (cont…)
• The term algorithm is now applied to many kinds of
problem solving that employ a mechanical sequence of
steps, as in setting up a computer program.

• As with algorithms used in arithmetic, algorithms for


computers can range from simple to highly complex.

1 17
INTRODUCTION TO PROGRAMMING
• ALGORITHM (cont…)
• 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.

1 18
INTRODUCTION TO PROGRAMMING
• ALGORITHM (cont…)
• METHODS OF REPRESENTING ALGORITHM
• The steps to the solutions are broken into series of logical
steps in English related form.
• There can’t be a solution if there is no recognized
problem.
• once a problem exists, one must take certain step in
order to get a desired solution. Three common methods
or design tools are Pseudocode, flowcharts and
hierarchy charts.
1 19
INTRODUCTION TO PROGRAMMING
• ALGORITHM (cont…)
• PSEUDOCODE
• A Pseudocode is the English-like representation of the
program logic.
• It does not make use of standard symbols like the
flowchart.
• It is a sequential step by step arrangement of the
instructions to be performed to accomplish a task.

1 20
INTRODUCTION TO PROGRAMMING
• ALGORITHM (cont…)
• PSEUDOCODE
• It is an informal and artificial language that helps
programmers develops algorithms.
• Pseudo code essentially is English with some defined
rules of structure and some keywords that make it
appear a bit like program code.

1 21
INTRODUCTION TO PROGRAMMING
• ALGORITHM (cont…)
• PSEUDOCODE
• Some guidelines for writing pseudo code are as follows.
• PSEUDOCODE GUIDELINES
• The keywords used for pseudo code in this document are:
1. For start and finish
BEGIN MAINPROGRAM, END MAINPROGRAM
2. For initialisation
INITIALISATION, END INITIALISATION

1 22
INTRODUCTION TO PROGRAMMING
• PSEUDOCODE
3. For subprogram
BEGIN SUBPROGRAM, END SUBPROGRAM
4. For selection
IF, THEN, ELSE, ENDIF
5. For multi-way selection
CASEWHERE, OTHERWISE, ENDCASE
6. For pre-test repetition
WHILE, ENDWHILE
7. For post-test repetition
REPEAT, UNTIL
1 23
INTRODUCTION TO PROGRAMMING
• PSEUDOCODE
• Note: All Keywords are written in capitals.
• Structural elements come in pairs, eg for every BEGIN
there is an END, for every IF there is an ENDIF, etc.
• Indenting is used to show structure in the algorithm.
• The names of subprograms are underlined.

1 24
INTRODUCTION TO PROGRAMMING
• FLOWCHART
• A flowchart is a pictorial representation of an Algorithm
or of the plan of solution of a problem. It indicates the
process of solution, the relevant operations and
computations, point of decision and other information
that are part of the solution.
• Special geometrical symbols are used to construct
flowcharts.

1 25
INTRODUCTION TO PROGRAMMING
Symbol Purpose Description
Used to indicate the flow of logic by
connecting symbols.

Flow line

Terminal(Stop/Start) Used to represent start and end of flowchart.

Input/output Used for input and output operation.

Used for arithmetic operations and data-


Proc+essing
manipulations.

Used to represent the operation in which


Decision
there are two alternatives, true and false.

On-page Connector Used to join different flow line

1 26
INTRODUCTION TO PROGRAMMING
• EXAMPLE 1
• Write a pseudo code for findings the area of a room.
• Solution:
• Step1.BEGIN PROCESS
• Step2.Input room length
• Step3.Input room width
• Step4.Multiply length by width to get area
• Step5.Print area
• Step6.END PROCESS

1 27
INTRODUCTION TO PROGRAMMING
• EXAMPLE 2
• Write a Pseudo code for finding the greatest of Three 3 numbers
represented as A, B, and C.
• Solution
• Step 1.BEGIN PROCESS
• Step 2.Input A, B, C
• Step 3.IF A>B THEN big = A
• Step 4.ELSE big = B
• Step 5.IF big >C THEN biggest = big
• Step 6.ELSE biggest = C
• Step 7.END IF
• Step 8.END PROCES
1 28
INTRODUCTION TO PROGRAMMING

•EXAMPLE 3
•Write an Algorithm to determine a student’s final grade
and indicate whether it is passing or failing.
•The final grade is calculated as the average of four marks. If
the average is above 50 then it is pass otherwise it is fail.

1 29
INTRODUCTION TO PROGRAMMING
• SOLUTION
• Step 1 BEGIN PROCESS
• Step 2 Input M1, M2, M3 and M4
• Step 3 Average = (M1 + M2 + M3 + M4)/4
• Step 4 IF (Average < 50) THEN
• Step 5 Prints “Fail”
• Step 6 ELSE
• Step 7 Print “Pass”
• Step 8 END IF
• Step 9 END PROCESS

1 30
INTRODUCTION TO PROGRAMMING
• EXAMPLE 4
• Develop an algorithm to obtain a book on computer from your school
library located on the fourth floor of the building. You are to proceed to the
library from your ground floor classroom.
• SOLUTION
• 1. Start from the classroom
• 2. Climb the stairs to the 4th floor and reach the library
• 3. Search a book on computer
• 4. If the book is found THEN
• 5. Have the book issued
• 6. ELSE
• 7. Return to your classroom
• 8. END IF
• 6. Stop.

1 31
INTRODUCTION TO PROGRAMMING
• EXAMPLE 5
• Develop an algorithm to find the average of four numbers stored in
variables A, B, C, D
• SOLUTION
• 1. START
• 2. Read values in variables A, B, C, D
• 3. Average = (A+B+C+D)/4.
• 4. Write Average
• 5. STOP.

1 32
INTRODUCTION TO PROGRAMMING
• EXAMPLE 6
• Develop and algorithm to find the average of four numbers stored in
variables A, B, C, D. When the value of variable A is zero, no averaging is
to be done.
• SOLUTION
• 1. START
• 2. Read values stored in variable A, B, C, and D
• 3. IF the value of A is Zero, THEN jump to step 6
• 4. Calculate the average of A, B, C, D and store the result in variable P.
• 5. Write the value of P
• 6. END IF
• 6. STOP.

1 33
INTRODUCTION TO PROGRAMMING
• Example 7
• Write a pseudo code that accept the age of an applicant and
determine if he eligible to vote or not, applicants are only eligible if
their age is 18 years and above.
• 1. BEGIN PROCESS
• 2. INPUT Age
• 3. IF Age >= 18 THEN
• 4. Status=”You can Vote”
• 5. ELSE
• 6. Status=”Sorry you cannot vote come back next when you are eighteen”
• 7. Print Status
• 8. END IF
• 9. END PROCESS

1 34
INTRODUCTION TO PROGRAMMING
• Example 8
• Write a pseudo code that gives a customer a bonus of N50 when the
recharge amount is N200 and above, the customer doesn’t get any bonus
amount recharge is below N200.
• 1. BEGIN PROCESS
• 2. INPUT Recharge Amount
• 3. IF Recharge Amount >= 200 THEN
• 4. Bonus=50
• 5. ELSE
• 6. Bonus=0
• 7. Balance= Recharge Amount +Bonus
• 8. Print Balance
• 8. END IF
• 9. END PROCESS

1 35
INTRODUCTION TO PROGRAMMING
• Example 8
• Alternatively
• 1. BEGIN PROCESS
• 2. INPUT Recharge Amount
• 3. IF Recharge Amount is above 200 THEN
• 4. Print “Bonus is 50”
• 5. ELSE
• 6. Print “No Bonus”
• 7. Balance= Recharge Amount + Bonus
• 8. Print Balance
• 9. END IF
• 10. END PROCESS

1 36
INTRODUCTION TO PROGRAMMING
• Example 9
• Develop an algorithm using pseudo code that prints numbers from
1 to 10
• 1. BEGIN PROCESS
• 2. INITILISATION
• 3. N=1
• 4. END INITIALISATION
• 5. WHILE N<= 10
• 6. Print N
• 7. N=N+1
• 8. ENDWHILE
• 9. END PROCESS

1 37
INTRODUCTION TO PROGRAMMING
• Example 9
• Alternatively
• 1. BEGIN PROCESS
• 2. INITILISATION
• 3. N=1
• 4. END INITIALISATION
• 5. REPEAT
• 6. Print N
• 7. N=N+1
• 8. UNTIL N>10
• 9. END PROCESS
1 38
INTRODUCTION TO PROGRAMMING
• Example 10
• Develop an algorithm using pseudo code that prints the sum of
numbers from 1 to 10
• 1: BEGIN PROCESS
• 2: INITILISATION
• 3: N=1
• 4: Sum=0 END INITIALISATION
• 5: WHILE N<= 10
• 6: Sum=Sum + N
• 7: N=N+1
• 8: ENDWHILE
• 9: PRINT Sum
• 10: END PROCESS

1 39

You might also like