CPE 112-Chapter1 - Updated2021
CPE 112-Chapter1 - Updated2021
CMPE112,CTPR112,ITEC112,MISY112,IT112,COMP112,CPE112
Computer Programming
Application Software
Software that relies only on other software to run.
This type of software usually needs a System
Software to run.
The C/C++ programs you are going to write within this
course are all in application Software.
Programming
Programming is the task of writing high or medium level
codes in order to tell the computer what to do under
certain circumstances.
will not take notes and will just listen to the teacher.
will not write programs on the computer, will just note programs on the
notebook.
Will constantly try to take pictures of the white board and even slides
Copies programs from the board and when it doesn’t run, calls to the teacher:
“the program doesn’t work, can you fix it?”
When you are telling the computer what to do, you also
get to choose how it's going to do it.
Let's say that you have a friend arriving at the airport, and
your friend needs to get from the airport to your home.
Computer algorithms e.g.
Here are four different algorithms that you might give your friend for
getting to your home:
The taxi algorithm:
• Go to the taxi stand.
• Get in a taxi.
• Give the driver my address.
The call-me algorithm:
• When your plane arrives, call my cell phone.
• Meet me outside baggage claim.
The rent-a-car algorithm:
• Rent a car.
• Follow the directions to get to my house.
The bus algorithm:
• Outside baggage claim, catch the airport bus shuttle service
• Get off on Nicosia Town Centre (e.g. Dereboyu)
• Walk two blocks north to my house.
Computer algorithms e.g.
All four of these algorithms
• accomplish exactly the same goal
• does it in completely different way
• has a different cost and a different travel time.
Taking a taxi, for example, is probably the fastest way, but
also the most expensive. Taking the bus is definitely less
expensive, but a whole lot slower. You choose the algorithm
based on the circumstances.
There are two types of operations you are going to deal with
in algorithms and also in programming.
1) Arithmetic Operations
These are mathematical operations. Although the operations use
the math logic, the symbols used in programming/computer
algorithms are quite different than regular math symbols.
2) Logical Operations
These are decision making you will need to do across the
program/computer algorithms. They usually including comparing
or matching values.
Arithmetic operations
Programming is not MATH! So you will need to use the correct
symbol for arithmetic's.
1 Multiplication * bm b*m
2 Division / x/y x/y
3 Modulus % r mod s r%s
4 Addition + f+7 f+7
5 Subtraction - p–c p-c
Logical operations
Algebraic C /C++ C /C++ Meaning of C
operator operator expression /C++ expression
Equality = == x == y x is equal to y
Operators
!= x != y x is not equal to y
Pseudocode
Uses instruction level English based
commands to do input, output, arithmetic
and logical operations.
Flowchart
Uses graphical diagrams to display input,
output, arithmetic and logical operations.
IBM’s Flowchart Template
Processing Calculate
(Assignment & Set
Calculation)
Example statements
Statements Symbols of Flowchart Words of Pseudocode
input r from the user
Input enter r
r
statement read r
Output area
display area
statement
Or =
Which one to use?
Notice that and = signs are interchangeably used in
flowcharts.
Essentially,
You can use any of these as long as you follow the same
standard within your flowcharts
Example of Statements:
declare
This statement declares a name identifier (i.e. variable) of
a particular data type.
start
Note: START
Each symbol must
follow the other with DISPLAY “Hello World”
an arrow sign: usually
“Hello World” top to down or left to STOP
right sequence.
stop
Exercise 2:
Draw the flowchart and write the pseudo-code for the following problem:
Get two numbers from the user, and calculate and display the average of
numbers.
start start
START
Integer num1,num2 Integer num1,num2
Integer sum Real avg
Real avg DECLARE Integer num1,num2
STOP
avgsum/2
end
avg
Note:
Each step can only be presented with one symbol. However, you can
end use the same symbol to show multiple operations.
Exercise 3:
Draw the flowchart and write the pseudo-code for the following problem;
Get three numbers from the user, and calculate and display the product
(multiplication) of numbers.
start
Integer START
a,b,c.mul
DECLARE Integer a, b, c, mul
a, b, c
INPUT a.b.c
DISPLAY mul
mul
STOP
stop
Exercise 4:
Draw the flowchart and write the pseudo-code for the
following problem;
Get a number from the user, and calculate and display
the square of that number.
F X8
X9
Exercise 6:
Draw the flowchart and write the pseudo-code for the following problem;
Get two numbers from the user and display the greatest number.
start
start START
Integer
x, y,max DECLARE Integer X,Y,max
Integer
x, y
x, y INPUT X,Y
end
end
Exercise 7:
Draw the flowchart and write the pseudo-code which will
accept an X value from the user and will show different
outputs according to the entered X value:
true
false
Example LOOP sequence
Write the pseudo code and
draw the flowchart of an
algorithm that would count
numbers from 0 to100
START
set 0 to count
STOP
Exercise 9:
Draw the flowchart and write the pseudo-code which will
display “Hello World” on the screen for 5 times.
START
DECLARE Integer x
set 0 to X
STOP
START
DISPLAY sum
STOP
1 0 1<=6 T
1+1=2 0+1=1 2<=6 T
2+1=3 1+2=3 3<=6 T
3+1=4 3+3=6 4<=6 T
4+1=5 6+4=10 5<=6 T
5+1=6 10+5=15 6<=6 T
6+1=7 15+6=21 7<=6 F 21
Exercise 11:
Draw the flowchart and write the pseudo-code which will
display the summation of numbers from 1 to 1000.
Exercise 12:
Draw the flowchart and write the pseudo-code which will
display the avarage of numbers from 1 to 1000.
Exercise 13:
Draw the flowchart and write the pseudo-code which will
display the multiplication of numbers from 15 to 250.
Exercise 14:
Write the pseudo-code which will get 10
numbers from the user and display their
summation.
STOP
Exercise 14:
Draw the flowchart
which will get 10
numbers from the user
and display their
summation.
Exercise 16:
Draw the flowchart and write the pseudo-code which will
get 1500 numbers from the user and display their average.
Exercise 17:
Draw the flowchart and write the pseudo-code which will ask
the user to enter a number from keyboard and then display
all the even numbers starting from 2 up to that number.
𝑁𝑢𝑚𝑏𝑒𝑟 6 𝑂𝑢𝑡𝑝𝑢𝑡 2 4 6
𝑁𝑢𝑚𝑏𝑒𝑟 10 𝑂𝑢𝑡𝑝𝑢𝑡 2 4 6 8 10
Exercise 18:
Draw the flowchart and write the pseudo-code which
display all the integer numbers from 1 to 30 which are
divisible by 3.
𝑂𝑢𝑡𝑝𝑢𝑡 3 6 9 12 15 18 21 24 27 30
Exercise 19:
Draw the flowchart and write the pseudo-code which will get
2 integer numbers from the user and display all the integer
numbers between them which are divisible by 7.
Revision
In this chapter, we covered: