You are on page 1of 9

BCS 1, BCSEC 1 & BIT 1 10/30/2023

Contents
Problem Solving Concepts for the • Introduction
Computer • Constants and Variables
• Data Types
David T. Makota
• Operators
Faculty of Computing and Mathematics
The Institute of Finance Management • Expressions and Equations
Dar Es Salaam, Tanzania

CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving


1 2
Techniques Techniques

Problem Solving Concepts for the Computer Problem Solving Concepts for the Computer

Lecture ii Introduction

CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving


3 4
Techniques Techniques

1
BCS 1, BCSEC 1 & BIT 1 10/30/2023

Introduction
• problems that can be solved on computers
– Computational
• Problems involving some kind of mathematical processing
– Logical
• Problems involving relational or logical processing Problem Solving Concepts for the Computer

• The kinds of processing used in decision making on the computer Constants and Variables
– Repetitive
• problems involving repeating a set of mathematical and/or logical
instructions. CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving
5 6
Techniques Techniques

Constants and Variables Constants and Variables


• The computer uses constants and variables to solve problems. • Constant
– They store data used in processing. – For example, because the value of PI does not change, it
• Constant would be a constant and defined within the program.
– Specific alphabetical and/or numeric value that never changes during – This constant may be given a name, but the only way to
the processing of all the instructions in a solution. change the value of the constant is to change the program.
– Constants can be any type of data • It is desirable that constants be given names containing all capital
• numeric, alphabetical, or special symbols. (Data types are explained in more letters in order to easily distinguish them from variables.
detail later.)

CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving


7 8
Techniques Techniques

2
BCS 1, BCSEC 1 & BIT 1 10/30/2023

Constants and Variables Constants and Variables


• Variable • Variable
– The value of a variable may change during processing. – Variables can be any data type, just as constants can.
– A programmer must give a name to each variable used in a – The variable name should be consistent with what the value
solution. of the variable represents.
• Programmer uses a variable name as a reference name for a – E.g. the name of the variable to store the cost of a pair of
specific value of the variable. shoes can be ShoeCost
• Computer uses the name as a reference to help it find that value in
its memory.

CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving


9 10
Techniques Techniques

Constants and Variables Constants and Variables


• Rules for Naming and Using Variables • Rules for Naming and Using Variables
– Name a variable according to what it represents, that is, Hours for – Be consistent when using upper- and lower-case characters.
hours worked, PayRate for rate of pay, and so on. – Use the naming convention
– Do not use spaces in a variable name; for example, use HoursWorked. • Our naming convention is upper case for the first character in each of the
– Start a variable name with a letter. words in the name, with no spaces between words in the name.
• Named constants will be in all upper case characters.
– Do not use a dash (or any other symbol that is used as a
• Variable Names
mathematical operator)
– PayRate, HoursWorked
– After you have introduced a variable name that represents a specific • Constant Names
data item, this exact variable name must be used in all places where – PI, MULTIPLIER
the data item is used.
CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving
11 12
Techniques Techniques

3
BCS 1, BCSEC 1 & BIT 1 10/30/2023

Data Types
• To process solutions, the computer must have data.
– Data are unorganized facts.
• They go into the computer as input and are processed by the program.
• What is returned to the user is output, or information.
• The data the computer uses are of many different types.
Problem Solving Concepts for the Computer
– Computers must be told the data type of each variable or constant.
Data Types

CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving


13 14
Techniques Techniques

Data Types Data Types


• Most common data types • Numeric data
– Numeric – Include all types of numbers
– Character – Numeric is the only data type that can be used in numeric
– Logical calculations.
– Date – The subtypes of numeric data include Integers and real numbers.
– Other languages allow the programmer to define data types • Integers are whole numbers, such as 5,297 or -376.
• Real numbers, or floating point numbers, are whole numbers plus decimal
parts.

CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving


15 16
Techniques Techniques

4
BCS 1, BCSEC 1 & BIT 1 10/30/2023

Data Types Data Types


• Character data set • Character data set
– sometimes called alphanumeric data set – When more than one character are put together, the computer
– Consists of all single digit numbers, letters, and special characters considers this item a string
available to the computer • Derived from a string of characters.
• a, A, Z, 3, #, &, and so forth placed within quotation marks. • Some languages do not differentiate between characters and strings.
– An upper case letter is considered a different character from a lower • All character data are considered string data.
case letter.
– Characters cannot be used for calculations even if they consist of only
numbers.
CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving
17 18
Techniques Techniques

Data Types Data Types


• Logical data • Rules for Data Types
– Consist of two values in the data set – The data that define the value of a variable or a constant will most
• The words True and False. commonly be one of three data types: numeric, character (including
– These are used in making yes-or-no decisions. character string), or logical.
• For example, logical data type might be used to check someone’s credit – The programmer designates the data type during the programming
record; True would mean her credit is okay, and False would mean it’s not process.
okay.
– Data types cannot be mixed. For example, string data cannot be
– Remember, the logical data set True and False are not string data and placed in a variable memory location that has been designated as
are considered reserved words numeric, and vice versa.
• That is, word that cannot be used as variable names.
CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving
19 20
Techniques Techniques

5
BCS 1, BCSEC 1 & BIT 1 10/30/2023

Data Types Data Types


• Rules for Data Types • Rules for Data Types
– Each of the data types uses what is called a data set. – Any numeric item that must be used in calculations resulting in a
• The numeric data uses the set of all base 10 numbers, the plus sign (+), and numeric result must be designated as numeric data type.
the negative sign (-) • All other numbers should be designated as character or character-string data
• The character type uses the set of all characters available to the computer types, even if data are all numbers, as in postal codes.
• The logical data type uses the set of data consisting of the words True and
False.
• The use of any data outside the data set results in an error.

CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving


21 22
Techniques Techniques

Operators
• Operators are the data connectors within expressions and
equations.
– They tell the computer how to process the data.
– Types of operators used in calculations and problem solving
• Mathematical operators
Problem Solving Concepts for the Computer
• Relational operators
Operators • Logical operators.
– Without these operators very little processing can be done.

CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving


23 24
Techniques Techniques

6
BCS 1, BCSEC 1 & BIT 1 10/30/2023

Operators Operators
• The operand and the resultant are two concepts related to the operator.
– Operands
• Data that the operator connects and processes.
– Resultant
• Answer that results when the operation is completed.
– For example, in the expression 5 + 7
• The + is the operator
• 5 and 7 are the operands
• 12 is the resultant.
– Operands can be constants or variables.
– The data type of the operands and the resultant depends on the operator.
CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving
25 26
Techniques Techniques

Operators

Problem Solving Concepts for the Computer

Expressions and Equations

CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving


27 28
Techniques Techniques

7
BCS 1, BCSEC 1 & BIT 1 10/30/2023

Expressions and Equations Expressions and Equations


• Expressions and equations make up part of the instructions in • Equation
the solution to a computer problem. – Stores the resultant of an expression in a memory location in the
• Expression computer through the equal (=) sign.
– Processes data, the operands, through the use of operators. – The previous expression would be used as part of an instruction in
the equation:
– E.g.: to find the number of square feet in a room you multiply the
length of the room by the width in the expression Area = Length * Width
Length * Width – The resultant of the expression Length * Width would then be stored
in a memory location called Area.

CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving


29 30
Techniques Techniques

Expressions and Equations

Problem Solving Concepts for the Computer

Summary

CSU07101/ITU07101/CYU07106 - Problem Solving CSU07101/ITU07101/CYU07106 - Problem Solving


31 32
Techniques Techniques

8
BCS 1, BCSEC 1 & BIT 1 10/30/2023

Summary
• Introduction
• Constants and Variables
• Data Types
• Operators
• Expressions and Equations

CSU07101/ITU07101/CYU07106 - Problem Solving


33
Techniques

You might also like