CC102 Module 1 and 2 - Notes
CC102 Module 1 and 2 - Notes
Introduction to
Programming 1
MODULE 1 – Introduction to
Programming
MODULE 2 –
Algorithm, Pseudocode
B. Module Overview:
Programming is the way humans write their software. It is written from another
language which could end up with another language for a specific purpose of for an
organization to use.
D. Discussion/Learning Activity:
Read the Reference Material attached for this module.
Parts of a Computer System:
Hardware: Electronic Devices
Software: Instructions and Computer
Programs
Hardware
Input : Keyboard, Mouse
System unit:
Random Access Memory (RAM)
Central Processing Unit (CPU)
Output: Monitor, Printer
Secondary Storage: Disk Drive
Programming
The most valuable part of learning to program is learning how to think about arranging
the sequence of instructions to solve the problem or carry out the task
Methods of Programming
Procedural
- Defining set of steps to transform inputs into outputs
- Translating steps into code
- Constructed as a set of procedures
- Each procedure is a set of instructions
Object-Oriented
- Defining/utilizing objects to represent real-world entities that work together to solve
problem
- Basic O-O Programming Components
- Class
- Object/Instance
- Properties
- Methods
Read the Problem: Understand the description of problem or scenario, identifying the knowns
and unknowns. Decide how to go about solving the problem: Determine what steps need to be
taken to reach the solution. Solve the Problem: Write the solution Test the Answer: Make sure
the answer is correct
Polya’s steps (UDIE) can be very effective when applied to solving computing problems
Applying Polya’s Problem Solving to Programming
Step 1 - Understand the Problem
What is the Problem to be solved? What is the unknown? What is the condition? What is the
data? What is needed to solve the problem? What actions need to take
place? Identify the inputs and outputs Identify the processes needed to produce the outputs
from the given inputs. Draw a figure. Introduce suitable notation. Isolate Principle parts of the
problem.
Summary
U - Read the Problem Statement; Identify the inputs, outputs, and processes
D - Decide how to Solve the Problem; Create an Algorithm / Flowchart / Psuedocode
I - Program the Code; Implement in Programming Language
E - Test the Solution; Run the Code using numerous, varied test Cases
Polya’s 4 Steps of Problem Solving
B. Module Overview:
A way of solving the problem in a sequential manner, through how we approach day
to day activity to accomplish. This is by using the English like language and written in a
simple layman’s term to fully comprehend how we will write our solution to the problem.
We make use of numbers to show the sequence of solution from simple to complex
problems. We write them in detail to show the process of how the words later will be
converted to simple codes when we start writing them into source codes.
C. Module Objective:
1. To identify different algorithm and illustrate how one differs from the other.
2. To show the process of solving the problem either simple or complex by way of sentence.
3. To show the different decision making process in solving problems using algorithm.
D. Discussion/Learning Activity:
Read the Reference Material attached for this module.
Introduction to Algorithms
• A sequence of instructions.
• A procedure or formula for solving a problem.
• It was created mathematician, Mohammedibn-Musaal-Khwarizmi.
• Often used for calculation, data processing and programming.
• Algorithms can be expressed in any language.
Topics
• Algorithms
• Pseudocode
• Flowcharts
Introduction to Algorithms
• Algorithms for making things will often be divided into sections;
–the parts/components/ingredients(inputs)requiredtoaccomplishthetask–actions/steps/
methods(processing)toproducetherequiredoutcome(output).
• For example to build a model car, the parts(inputs) are needed plus instructions on how
to assemble the car(processing) and the result is the car(output).
Pseudocode
• Pseudocode (which means fake code, because its not really programming code)
specifies the steps required to accomplish the task.
• Pseudocode is a type of structured English that is used to specify an algorithm.
• Pseudocode cannot be compiled nor executed, and there are no real formatting or
syntax rules.
Example of Pseudocode:
Ready and open subscriber file
Get a record
Do while more records
If current subscriber subscription count is > 3 then
Output the record
Get another record
End
Advantages of Pseudocode
• Reduced complexity.
• Increased flexibility.
• Ease of understanding.
5. A computer can compare two piece of information and select one of two alternative
actions
IF condition
THEN some action
ELSE alternative action
END IF
6. A computer can repeat a group of actions
WHILE condition (is true)
some action
END WHILE
FOR a number of times
some action
END FOR
Data Dictionaries
• The pseudo code by itself doesn't provide enough information to be able to write
program code.
• Data Dictionaries are used to describe the data used in the Pseudo Code.
• The standard data types used in Pseudo Code are Integer, Double, String, Char and
Boolean.
Let us do another with a twist, for decision making: Say the same problem but this time, the
frying pan is not big enough to hold the egg with water. There is no fire coming out of the
burner.
You see the process is increase and many inputs have taken in place and decisions are shown
in a step by step manner with a precise output and flow.
Example: Write an algorithm that will display the sum of two numbers:
1. Accept two numbers
2. Add the two numbers
3. Place the result of the two numbers added in sum
4. Display sum
Example:
instance 1: first number: 1
Second number : 3
instance 2: first number: 5
Second number : 2
PROCESS: The term to display the sum means an operation involve. There are only two
operation that would likely occur in the CPU or computer. Arithmetic or Logic. Here in
this problem it is Arithmetic, USING THE OPERATOR ADDITION. Thus we say
add the two numbers.
OUTPUT: only one and specific. The result of the added number and we place it in a
container, called SUM. Why? because it changes its value all the time, as instances
changes also.
If we write the answer in a pseudo code manner, this is how we will write the
mathematical problem:
1. Enter two numbers
2. Accept and place in containers Num1, Num2
3. Add the two number or we could write it as
Sum = Num1 + Num2
4. Display Sum
Algorithm:
1. Get the item
2. Read the amount of the items
3. Add the prices of the items and place in total
4. Pay the item.
5. Compute the amount money given against the total and place the result in Change.
6. If there is change, give the change.
Pseudo Code:
1. Enter Prices of 2 items
2. Read Item1Price, Item2Price
3. Total all the prices
Total Price = Item1Price + Item2Price
4. Received the Payment 500.00
5. Compute for change
Change = Total Price – Payment
6. If change is available, display change and give change.