CSC102 - Sessionhared-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 83

Problem solving

CSC102

Biralatei. J. Fawei
Biriyai Okolai
Assessment
Ø Examination (70%)
§ Hand written examination
§ Examination 2 hours
§ To answer 4 questions

Ø Continuous Assessment (30%)


• Attendance
• An individual written report
• Instant random tests
What is computer?
What is computer?
Computer is a programmable machine
that accepts input data, stores and
processes the data, generates output in
a useful format
What is computer?
Computer is a programmable machine that
accepts input data, stores and processes the
data, generates output in a useful format

Programmable part is called the software


What is computer?
Computer is a programmable machine that
accepts input data, stores and processes the
data, generates output in a useful format

Programmable part is called the software

Machine part is called the hardware


Hardware
Most computers have six basic components
1) Memory unit
2) Arithmetic/logic unit
3) control unit
4) input device
5) output device
6) auxiliary storage devices
Memory unit
The memory unit is also referred to as
internal storage
Memory unit is a collection of an ordered
sequence of storage cells
Each of the cells can store a piece of data
Each cell has an address
The memory unit stores input data and
instruction
Memory unit
Arithmetic Logic Unit
The arithmetic/logic unit performs
arithmetic operations such as: addition,
subtraction, multiplication and division

The logic unit performs logical operations


such as comparing two values
Control Unit
The control unit controls all the operations
of the system so that program instructions
are executed in the correct order

It works by sending control signals to the


datapath

These signals control the flow of data


within the CPU and between the CPU and
external units
CPU
Input Unit
The input unit accept data
that has been prepared

Example of common
input device
§ Keyboard
§ Mouse
Output Unit
The output unit displays information
that has been processed

Example of common output


device
§ Monitor
§ Printer
Auxiliary storage Unit
Auxiliary memory or storage is also called
secondary memory or storage
The auxiliary storage holds coded data for the
computer until when it is needed
When it is needed the data is transferred
from the auxiliary memory to the main
memory
An auxiliary memory therefore serves as both
an input and an output device
Auxiliary storage device

Hard disk drive


Computer
All the physical components of the
computer discussed so far are called
hardware

The design of computer hardware is fixed

The programs that enable the hardware


to operate is known as software

Software is not fixed as in hardware but


can be easily changed
Computer
Computers are used everywhere and in
different field of studies

More closely related fields


• Electronics engineering
• Computer systems engineering
• Software engineering
• Computer science
Computer
Electronics engineering and Computer systems
engineering focus on the design and manufacturing of
computer hardware
Computer
Software engineering and
Computer science is on the
design and implementation of
software

The focus of this course is the


design and implementation of
software
Software
There are three class of software
1. System software is developed to operate the
computer hardware and as well provide and
maintain a platform for running application
programs
For example, Windows, MacOS, Linux etc.

2. Middleware is the set of programs that enables


multiple processing on one or more machines
to interact. It allows the connection of two
applications and data between them
For example, Web servers, application servers
Software
3. Application software is designed to help a
computer user to perform a specific task

Application software can manipulate text,


numbers, graphics or a combination of these
elements
For example, MSwords, web browser, video
games etc

Our interest in this course is application


software development
Computer Science
The primary focus of computer science is to
understand what goes on behind the
hardware and how software/programs can
be made more efficient

Computer science may not pertain to the


following areas
• IT support
• Computer repairs
• Computers installing
• Computer network configuration
Computer Science
Areas of specialization in computer science
includes:
• Software engineering

• Artificial intelligence
• Computer networking & communication
• Database systems
• Parallel computation
Computer Science
Areas of specialization in computer
science includes:
• Distributed computation
• Computer-human interaction
• Computer graphics
• Operating systems
• Numerical & symbolic computation
Computer Science
Computer science is the study of the
theoretical foundations of information
and computation, and of practical
techniques for their implementation and
application in computer systems

Computer science is very similar to


mathematics in problem solving
Computer Science
Both uses mathematical techniques and
models for problem solving

A solution is expressed in terms of


formulas and equations in mathematics

In computer science the solution is


expressed in terms of a program
Computer Science
Generally Computer science is all about
solving problems with computers

The problem can be any real world


problem or abstract problem

Computer science applies standard


systematic approaches in solving
problems
Computer program
A computer program is the set of
instructions that can be executed by a
computer to solve some problem or
perform a specified task

Computers do not understand human


language
For example, English language, Ijaw, Epie,…

Computer have its own language which is


known as programming language
Computer program
A programming language is an artificial
language designed to automate the task
of organizing and manipulating
information, and to express problem
solutions precisely

There are different types of programming


languages like the many different
languages we speak
Programming Languages
1. Structural programming languages are
also known as traditional
programming language e.g. Fortran,
Pascal, Cobol etc..
2.
3. Object oriented programming
languages e.g. Java, C++, C# etc..
4.
5. Functional programming languages
6.
7. Logic programming languages
Computer System
Computer System
The diagram above is a single CPU computer
processing information

You can imagine a multiple CPU computer


processing information

A multiple CPU computer is more complex


 
 
Computer System
Problems are solved by using a computer to
accept user input
For example, using a keyboard/mouse input
data or game control movements

Processing the input to produce some kind of


output
For example, images, text, sound

Sometimes the incoming and outgoing data


may be in the form of hard drive or network
device
What is problem
solving?
What is problem
solving?
Problem solving could be described as the
sequential process of analyzing information
pertaining to a particular situation and providing
an appropriate response options.
Problem Solving
We solve problems based on 6 well articulated
steps:
1. Understanding the problem
2. Formulate a model
3. Define a procedure (Algorithm)
4. Write the program
5. Test the program
6. Evaluate the solution
WHAT IS A PROGRAMMING
LANGUAGE?
q A communication technique for expressing

instructions to the computer


CATEGORIES OF A
PROGRAMMING LANGUAGE
HIGH-LEVEL LANGUAGES

a)Languages that use a compiler to express


instruction to the computer

b) They are considered high-level because they


are closer to human languages and differ
from machine languages (i.e.: 0 & 1)
c)
E.g. Java, Python, PHP, C, C#, C++, Ruby, Basic,
etc.
LOW-LEVEL LANGUAGES

a)Languages that use an assembler to express


instructions to the computer.

b) Contains basic instructions that are recognized


by the computer.

c) They are the closest languages that are quickly


understood by the computer

e.g. Assembly Language & Machine code


(i.e. 0 & 1)
PROGRAM DEVELOPMENT
LIFECYCLE
PROGRAM DEVELOPMENT LIFECYCLE

This refers to the phases involved in


developing a program.

a) Problem Definition
b) Problem Analysis
c) Algorithm design & representation
(pseudo-code and flowchart)

d) Coding & Debugging


PROGRAM DEVELOPMENT LIFECYCLE
(Contd.)

1. Example of Problem Definition:


Write a program to find the average of any
given five integer numbers
PROGRAM DEVELOPMENT LIFECYCLE
(Contd.)

2. Example of Problem Analysis:


This process involves scrutinizing the
problem in order to understand it.

a) How will the five numbers be represented?


b) What is the meaning of average?
c) What is the mathematical method for
computing average?
d) How will the program output be modeled?, etc.
PROGRAM DEVELOPMENT LIFECYCLE
(Contd.)
3a. Algorithm Design:
This is a step by step narrative method taken to
provide solution to the analyzed problem

1. Start
2. Let a, b, c, d and e and avg be variables for the
five numbers & average respectively.
3. Assign values to the declared variables
4. Compute for avg
5. Let avg = (a+b+c+d+e)/5.0
6. Display avg as output
7. Stop and End Program
PROGRAM DEVELOPMENT LIFECYCLE
(Contd.)
3b. Pseudo-code representation:
This is a notation that resembles a
programming language to be used in solving the
given problem. It is used for interpreting the
algorithm

1. program average
2. var a,b,c,d,e,avg;
3. read a,b,c,d,e
4. avg = (a+b+c+d+e)/5
5. write (“average of 5 numbers,’avg’’);
6. end
7.
PROGRAM DEVELOPMENT LIFECYCLE
(Contd.)
3c. Flowchart:
This is the diagrammatic representation of an
Algorithm. It uses the following Symbols
PROGRAM DEVELOPMENT LIFECYCLE
(Contd.)
Flowchart:
PROGRAM DEVELOPMENT LIFECYCLE
(Contd.)
4. Coding and Debugging:
After constructing the algorithm, it is now
possible to code with any program language and
test-run.

Debugging is the process of searching and


removing bugs (errors) from the source-code.
Types of bugs include:
a) Syntax Bug
b) Logical Bug
c) Compile-time Bug
import java.util.Scanner;
public class JavaExample {

public static void main(String[] args)


{
Scanner scan = new Scanner(System.in);
System.out.print("Enter the first number: ");
double num1 = scan.nextDouble();
System.out.print("Enter the second number: ");
double num2 = scan.nextDouble();
System.out.print("Enter the third number: ");
double num3 = scan.nextDouble();
scan.close();
System.out.print("The average of entered numbers is:" + avr(num1, num2, num3) );
}

public static double avr(double a, double b, double c)


{
return (a + b + c) / 3;
}
}
EXERCISES
PROGRAM DEVELOPMENT LIFECYCLE TASK

1. Prepare a Program Development Lifecycle


for a program to compute the Principal
of an Interest when Rate & Time are
given.

INSTRUCTION:

a) Use a sheet of paper


b) Write your name and Mat. Number
c) Time given is 20 minutes
Problem Solving
Please, pick up your pen and paper, and
find the average of the set of numbers

32, 43, 7, 58, 97, 41, 30, 83, 56, 77, 40,
12, 90, 72, 69, 55, 37, 44, 61, 53, 88, 94,
76
Problem Solving
Please, pick up your pen and paper, and
find the average of the set of numbers

32, 43, 7, 58, 97, 41, 30, 83, 56, 77, 40,
12, 90, 72, 69, 55, 37, 44, 61, 53, 88, 94,
76

This is a typical problem to be solved


Problem Solving
Please, pick up your pen and paper, and
write in a step by step manner how to find
the average of these set of numbers

32, 43, 7, 58, 97, 41, 30, 83, 56, 77, 40,
12, 90, 72, 69, 55, 37, 44, 61, 53, 88, 94,
76
Problem Solving
Instructing computer to find the average
of a set of numbers:

1. Input: get all the numbers…


2.
3. Process: add them up, count all the
number and then divide the sum up
of the numbers by the count.
4.
5. Output: Display the result in the
monitor or print in a paper
Understand the problem
You need to understand the following things in the
problem you are trying to solve

1. What is my input data?


1. What does it represent?
2. What is the data format?
2.
3. What is the kind of result to be produced?
What do I want the result to look like?
Example, text, picture, number
4.
5. What am I going to compute?
6.
7. Is anything missing?
Understand the problem
From our example problem, find the
average of a set of numbers:
1. What is my input data?
2.
Ans: Input data is a set of numbers

3. What does it represent?


4.
Ans: A set of numbers

5. What is the data format?

Ans: A set of integer numbers


Understand the problem
From our example problem, find the
average of a set of numbers:
1. What is the kind of result to be produced?
2.
Ans: The output is a numerical value
3.
4. What do I want the result to look like?

Ans: A numerical value

For example, integer or double value


5.
Understand the problem
From our example problem, find the
average of a set of numbers:

1. What am I going to compute?


2.
Ans: Some arithmetic operations
For example, addition and division
3.
4. Is anything missing?
5.
Ans: none
Formulate a model
Understand the processing part of the
problem
Some problems require breaking down into
smaller problems for simple mathematical
computation

We then apply available formulas

If there is no formula, we need to develop


our own. We can look up certain formulas
in textbooks or online.
Formulate a model
From our example problem, find the average
of a set of numbers:

Finding average
1. Addition of the numbers
2.
3. Count the set of numbers
4.
5. Divide Addition by Count

6.
Define a procedure
Draw up a precise plan for the computer to
execute
ie. Draw up an algorithm

An algorithm is a precise sequence of


instructions for solving a problem

Some algorithms are very complex where the


instructions are not sequential and may not
have finite steps

These algorithms could be considered as


“randomized or non-deterministic algorithms”
Algorithm
Commonly used representation form of
Algorithms are:
• Pseudo Code
• Flowchart

A pseudo code is a readable detailed plan
resembling a programming language used in
program design

A flowchart is a diagrammatical representation


of a step by step details of solving a problem
Algorithm
From our example problem, find the
average of a set of numbers:

Pseudo code
1. Set sum and count to 0
2. Load set of numbers
3. Repeat x number of times
1. Sum = add number
2. Count = add x
4. Average = divide sum by count
5. Display Average
Algorithm
From our example problem, find the average
of a set of numbers:

A Flowchart
Algorithm
From our example problem

Pseudo code
1. Set sum and count to 0
2. Load set of numbers
3. Repeat x number of times
1. Sum = add number
2. Count = add x
4. Average = divide sum by count
5. Display Average
A Flowchart
Algorithm
Pseudocodes and flowcharts may vary
depending on the author

Pseudocodes and flowcharts have some


common control structure
1. Sequence
2. Condition
3. Repetition (Loop)
4. Storage
5. Jumping
Control structures
• Sequence: instruction in
step by step format

• Condition: taking a
decision of what to do
next

• Repetition (Loop): do
same thing in a given
number of times
Control structures
• Storage: storing information
to be used later in the
program

• Jumping: to jump a given


number of steps when
needed
Algorithm
From our example problem, find the average
of a set of numbers:

Pseudo code
Sequential
1. Set sum and count to 0
2. Load set of numbers
3. Repeat x number of times
1. Sum = add number Repetition
2. Count = add x
4. Average = divide sum by count
5. Display Average
Algorithm
From our example problem

Sequential

Repetition
Write program

Writing program means encoding an


algorithm into some programming
language for computer understanding
Write program
Write program
The computer needs precise information
to do what you want it to do

For example, a missing semi-colon


characters (;) will confuse the
computer because (;) is what it
understands to be the end of an
instruction

This may cause Compile error


Write program
Compilation is the process of converting
a program into an instructions that can
be understood by the computer

The longer your program the more


possible compile errors.
Program Testing
Program is tested if it compiles successfully

Program is evaluated to ascertain its


correctness

If the program is OK, then you will have the


correct output

If the program is OK and no output means


that you have runtime error
Program Testing
If the output is not correct means that your
program encountered some bugs

If output is not correct


• Algorithm conversion is not correct
• Initial algorithm is not correct

Bugs are problems/errors with a program


that cause it to stop working or produce
incorrect or undesirable results
Program Testing
The process of finding and fixing errors
in your code is called debugging

Debugging is time-consuming when it


comes to being a programmer.
COMPUTATIONAL APPROACHES TO
PROBLEM-SOLVING

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy