COS102: Problem Solving
Lecture 01: Introduction
Venue : CIT Theatre
Presented by: M .I. Mukhtar
Course Description
• This course introduces students to a broad range of
approaches for solving problems.
• It is designed to provide students with the necessary
knowledge and skills to become proficient problem
solvers and effective programmers.
• Throughout the course, students will learn how to
apply problems-solving techniques to address
problems and develop programs for them.
• To aid learning of the course, concepts will be
illustrated using Python Programming Language.
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 2
Learning Outcomes
At the end of the course, Students should be able to:
• explain problem solving processes;
• Demonstrate problem solving skills;
• Describe the concept of algorithms development
and properties of algorithms;
• Discuss the solution techniques of solving
problem;
• Solve computer problems using algorithms,
flowcharts, pseudocodes etc.;
• Solve problems using programming language
using Phyton etc.
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 3
Course Outline
• Introduction to the core concept of computing.
• Problems, types of Problem and Problem Solving
• Methods of solving Computing Problems.
• Solution Techniques of solving problems
• General problem solving process
• Solution Formulation and Design
• Implementation, evaluation and refinement.
• Programming in Python.
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 4
Course Lecturers
• The course will be taken in 2 parts
• Maryam Ibrahim Mukhtar --- Second Part
• Dr. Saratu Yusuf Ilu ----- First Part
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 5
Lectures
• 3 Credit Hour Course
• Tuesday – 2hr
• Wednesday – 1hrs (Will be used during practical in second part)
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 6
Course Assessment
• CA – 30%
• Exams – 70%
7 questions to answer 5
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 7
Reference Text
• Problem solving and programming concept by
Maureen Sprankle and Jim Hubbard ….
• For Second Part of the course
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 8
Lecture Outline
• Introduction
• Core Concepts of Computing
• Problem Decomposition
• Variables and Constants
• Data Types
• Operators
• Arrays
• Functions
• Expression
• Algorithms and Control Structures
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 9
Introduction
• Problem solving is one of the central activities
performed by professional and learners in
computing.
• A problem solver in computing cannot effectively use
the computer to solve problems:
• Without understanding problems, and problems decompositions;
• Without understanding how the computer uses and defines data;
• Without understanding how the computer uses operators and
functions;
• Without understanding how to construct computer expressions and
equations;
• Without understanding how to create algorithms (instructions) and
use its different Control Structures;
• Without understanding how arrays work;
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 10
Core Concepts of Computing for Problem
Solving
• There are some common core concepts of computing
for Problem Solving.
• Understanding them is crucial for developing efficient
and effective solutions to computational problems.
Problem Variables and
Data Types Operators
Decomposition Constants
Algorithms &
Arrays Functions Expression Control
Structures
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 11
Problem and Problem Decomposition
• There are different categorization of problems such
as routine and non-routine, solvable and unsolvable
problems.
• There are also algorithm and heuristic methods to
solve problems.
• Decomposing a problem involve using techniques
such as abstraction, divide and conquer etc to:
• break down complex problems into smaller, manageable
parts.
• Identify sub-problems and solving them individually.
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 12
Constant & Variables
• The computer uses variables and constants to solve
problems.
• A constant is a value that never changes during the
processing of all the instructions in a solution.
• Variables are placeholders for data that can vary or
change during the program’s execution. They are used to
store and manipulate values that might be different at
different points in the program.
• Examples:
• Area = ∏r2 ---------r is a variable, ∏ is a constant
• A = ½ (a + b) * c ------ a, b, c are variables, ½ is a
constant
• Wages= Hours worked * 1000---Hours worked are
variables, 1000 is constant
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 13
Rules for Naming Variables and Constants
Name a variable
Names should start with Do not use spaces in
according to what it
letter not number. name.
represents.
Be consistent when
Special characters like using upper- and lower-
@, %, $, # or any other case characters. In some
Avoid using language
symbol that is used as a languages HOURS is a
specific reserved words.
mathematical operator) different variable name
is not allowed than Hours or hours
(case sensitivity).
Examples of incorrect variables names pay-rate, 10% bonus
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 14
Data Type
• To process solutions, the computer must have data.
• The data the computer uses are of many different
types.
• Computers must be told the data type of each
variable or constant.
• The most common data types:
Numeric Alphanumeric Logical
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 15
Numeric Data Type
• Numeric data include all types of numbers.
• Numeric is the only data type that can be used in
numeric calculations.
• Numeric data are divided into integers and real
numbers.
• Integers are whole numbers example 25 or -376.
• They can be positive or negative.
• Real numbers, sometimes called floating point
numbers, are whole numbers plus decimal parts
example 16.5 or -780.00
• They can be positive or negative.
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 16
Alphanumeric Data Type
• The alphanumeric data set, consists of all single digit
numbers, letters, and special characters.
• They are placed within quotation marks.
• Example a, A, Z, 3, #, &
• When more than one character are join together, the
computer considers this item as string
• String data type: derived from a string of characters.
• Character or string data can be joined together with the
+ operator in an operation called concatenation.
Example:
• “2” + “2” = “22” (not 4).
• “Ado” + “Isa” = “AdoIsa”
• “Ado” + “ Isa” = “Ado Isa”
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 17
Logical Data Type
• Logical data consist of two values namely True
and False.
• These are used in making yes-or-no decisions.
• logical data set True and False are not string data
and are considered reserved words.
• Reserved word: a word that cannot be used as
variable names.
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 18
Operators
• The computer has to be told how to process data.
• This task is accomplished through the use of operators.
• The types of operators used in calculations and problem
solving include:
Mathematical Operators
Relational Operators
Logical Operators
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 19
Mathematical Operators
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 20
Relational & Logical Operators
Operator Computer Symbol Example Results
Relational
Equals to == 2==2 True
Not Equals to != 2!=2 False
Less than < 5< 3 False
Greater than > 8> 1 True
Less than or equal <= 6 < =6 True
to
Greater than or >= 9 >= 5 True
equal to
Logical
And and True and True True
Or or True or False True
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 21
Hierarchy of Operation
SWE1301: Problem Solving and Software
7/22/2024 Development - MIM 22
Arrays
• Array is a collection of values stored in a single
variable.
• In programming, arrays are useful for storing and
manipulation collection of data. Example
Fruits = [“Apple”, “Banana”, “Orange”]
• In this example, fruit is an array that stores three
values: Apple, Banana, orange
Fruits[0] = Apple
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 23
Function
• Functions are small sets of instructions that
perform specific tasks and return values.
• Functions are used for basic tasks that are used
repeatedly in the problem solving process.
• Each language has a set of functions within it.
• The format of a function is :
FunctionName (data)
• The data is listed as part of the function and are
called parameters.
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 24
Type of Functions
Conversion
Mathematical String functions:
functions: used
functions: used in used to Statistical
to convert data
mathematical manipulate string functions: used to
from one data type
calculations such variables. For calculate things
to another. For
things as square example, joining such as maximum
example,
root, absolute strings together, values and
converting a string
value, or a finding the length minimum values.
value to a numeric
random of strings.
value.
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 25
Function Example
Function Definition Example Result
Mathematical/ Statistical Functions
abs(n) Returns absolute value of abs(-4) 4
(N)
sqrt(n) Returns square root of (n) sqrt(4) 2
round(N,n1) Returns the rounded value Round(3.7245, 3.72
of N to the n1 place. 2)
max(n1,n2,..) Returns the maximum Max(3,2,10) 10
number in the list
Pow(N, n1) Returns the value of N Pow(4, 2) 16
raise to the power of n1
ceil(n) Return the largest integer Ceil (3.22) 4
greater than n
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 26
Function Example
Function Definition Example Result
String Functions
Length(s) Returns the number Length(‘’Maryam’’) 6
of character in a
string
Capitalize() Converts the first Capitalize(“maryaM”) Marya
character of a string m
to upper case and
lower case to all
others
Conversion Functions
float(n) Converts an integer (n) float(2) 2.0
to real number
int(n) Converts a real int(3.55) 3
number (n) to integer
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 27
Computer Expression
• Sometimes a programmer has to modify an
expression into a format supported by
computer. Examples:
Numeric Expression
Computer Expression
Relational expression X is less than Y + 5
Computer Expression X < (Y + 5)
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 28
Algorithms & Control Structures
• An algorithm is an effective step-by-step procedure
for solving a problem in a finite number of steps.
• Control structure of algorithm can be broadly
classified into 3
7/22/2024 SWE1301-Problem Solving and Software Development- MIM 29
Test yourself
• Identify the variables and constants in the equations
below:
• x3 – x2 +2x +2 =0
• V = 4∏r3
• What would be the most appropriate data type to
use for the following:
• The number of people that attended SWE1301 lecture today
• Name of University
• “1”
• Price of a computer system
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 30
Test Yourself
Data Item Incorrect Variable Problem Corrected Name
Name
Space between words WagesPaid
Wages paid Wages Paid
Name of EN Does not define data EmployeeName
Employee item
Use of mathematical PayRate
Pay - Rate operator
Rate of pay
Start with number TenPercentBonus
10% bonus 10% _bonus or Bonus
Variable E.g in other places
Introduced as
Example Inconsistent Name Example
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 31
Exercises
• Convert the following expression into computer
form
• Iv v.
• vi
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 32
Exercises
i. String S = “practice”
• What is the result of Length(S)?
• What will be the result of Capitalize(S) ?
ii. float n = -2.436
• What is the result of abs(n)?
• What is the result of abs(N)?
• What is the result of round(n,1)?
• What is the result of ceil(n)?
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 33
Successful Degree
I want to be successful in Computing
Success begins in Problem Solving Course
+
hard work, dedication and willingness to
learn new things.
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 34
Lecture Summary
• Understanding the core concepts of computing for
problem solving is crucial for developing efficient
and effective solutions to computational problems.
• Some common core concepts of computing for
problem solving include
• Problem Decomposition
• Variables and Constants
• Data Types
• Operators
• Arrays
• Functions
• Expression
• Algorithms and Control Structures
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 35
Questions??
7/22/2024 SWE1301: Problem Solving and Software Development - MIM 36