CSC 120 Lecture 1 Final
CSC 120 Lecture 1 Final
LECTURE 1
Problem solving
ZUBAIR ADAM
EKOUNIVERSITY OF MEDICINE AND HEALTH SCEINCE, IJANIKIN LAGOS
1
Computers as a problem solving tool
3
A problem scenario
The first step to solving any problem is to make sure that you understand the
problem that you are trying to solve. One needs to know:
1. What input data/information is available?
2. What does it represent?
3. What format is it in?
4. Is anything missing?
5. Do I have everything that I need?
6. What output information am I trying to produce?
7. What do I want the result to look like text, a picture, a graph?
8. What am I going to have to compute?
5
Understand the Problem
In our example, we well understand that the input is a bunch of grades. But we need to understand the
format of the grades.
Each grade might be a number from 0 to 100 or it may be a letter grade from A+ to F. If it is a number, the
grade might be a whole integer like 73 or it may be a real number like 73.42.
We need to understand the format of the grades in order to solve the problem.
We also need to consider missing grades. What if we do not have the grade for every student (e.g., some
were away during the test) ? Do we want to be able to include that person in our average (i.e., they received
0) or ignore them when computing the average ?
We also need to understand what the output should be. Again, there is a formatting issue. Should we output a
whole or real number or a letter grade ? Maybe we want to display a pie chart with the average grade. It is
our choice.
Finally, we should understand the kind of processing that needs to be performed on the data. This leads to
the next step 6
Formulate a model
Now that we understand the problem and have formulated a model, it is time to come
up with a precise plan of what we want the computer to do.
An algorithm is a precise sequence of instructions for solving a problem.
To develop an algorithm, we need to represent the instructions in some way that is
understandable to a person who is trying to figure out the steps involved. Two
commonly used representations for an algorithm is by using
Pseudo code, or
Flow charts.
Pseudocode is a simple and concise sequence of English-like instructions to solve a
problem
Flowchart is simply a graphical representation of steps in sequential order and is 8
Flowchart
ANSI/ISO Shape Name Decription
Shows the process's order of operation. A line coming from one symbol and
Flowline
pointing at another. Arrowheads are added if the flow is not the standard top-
(Arrowhead)
to-bottom, left-to right.
Shows a conditional operation that determines which one of the two paths the
Decision program will take. The operation is commonly a yes/no question or true/false
test. Represented as a diamond (rhombus).
A labeled connector for use when the target is on another page. Represented as a
Off-page Connector
home plate-shaped pentagon.
10
Pseudocode Vs Flowchart
1. set the sum of the grade values to 0. int sum = 0; int sum = 0;
13
Test the Program
Once you have a program written that compiles, you need to make sure that it solves the problem
that it was intended to solve and that the solutions are correct.
Therefore the program is run in order to evaluate the compiled instructions.
After running the program, if all is well, then a correct output displayed.
It is possible however, that the program works correctly for some set of data input but not for all.
If the output of the program is incorrect,
it is possible that the algorithm was not converted properly into a proper program.
It is also possible that the algorithm itself is flawed.
Or some instructions where written and performed out of sequence.
Whatever happened, such problems with your program are known as bugs. 14
Test the Program
Bugs are problems/errors with a program that cause it to stop working or produce incorrect or
undesirable results.
One should fix as many bugs in ones program as possible.
To find bugs effectively, the program must be evaluated with many test cases (called a test suite).
It is also a good idea to have a third-party test ones program because they may think up situations or
input data that the writer may never have thought of.
The process of finding and fixing errors in your code is called debugging and it is often a very time-
consuming “chore” when it comes to being a programmer.
If one takes time to carefully follow problem solving steps 1 through 3, this should greatly reduce
the amount of bugs in ones programs and it should make debugging much easier.
15
Assignment
16
Reference
17