You are on page 1of 29

Foundations of

Information Technology
Lecture 8
Introduction To Programming
Study Plan
O What is Programming?
O How do we write a Program?
O What are Data Types?
O Common Programming Errors
O Skills helpful in Thriving Computer
Programming

2
What is Programming?

3
What is Programming?
O Programming – The activity of writing out
instructions for solving a problem or
performing a task

4
What is Programming?
O Some basic programming tasks that involves
finite steps to be followed in a logical sequential
order
O Lifting a Paper
O Brushing Teeth

5
What is Computer Programming?
O Computer – A programmable device that can
store, retrieve, and process data

O Computer Programming – The process of


writing instructions for a computer to follow to
solve problems (activity – verb)

O Computer Program – Instructions written for


a computer to solve a problem (product – noun)

6
Computer Programming

CT174 - Foundations of Information Technology 7


How Do We Write Program?

8
How Do We Write Program?

9
How Do We Write Program?
O Problem-Solving Phase
O Understand (define) the problem and identify
what the solution must do
O Specify the tasks/steps to solve the problem
O Follow the steps exactly to see if the solution
really does solve the problem

10
How Do We Write Program?
O Implementation Phase
• Translate the general solution into a
programming language
• Have the computer carry out the solution and
check the results
• What if the solution isn't correct?

11
How Do We Write Program?
O Maintenance Phase
• Use the program
• Modify the program to meet changing
requirements, to enhance its functionality, or to
correct any errors that show up in using it

12
Is there a shortcut?

13
Data Types

CT174 - Foundations of Information Technology 14


Data Types
O A data type, in programming, is a classification
that specifies
1. Which type of value a variable has? and
2. What type of mathematical, relational or
logical operations can be applied to it without
causing an error?

CT174 - Foundations of Information Technology 15


Data Types
O A data type tells the compiler or interpreter how
the programmer intends to use the data.
O Most programming languages support basic
data types of integer numbers (of varying
sizes), floating-point numbers (which
approximate real numbers), characters and
Booleans.
O A data type constrains the possible values that
an expression, such as a variable or a function,
might take
CT174 - Foundations of Information Technology 16
Data Types
Data Type Used for Example
String Alphanumeric characters hello world, Alice,
Bob123
Integer Whole numbers 7, 12, 999
Float (floating Number with a decimal point 3.15, 9.06, 00.13
point)
Character Encoding text numerically 97 (in ASCII, 97 is a
lower case 'a')
Boolean Representing logical values TRUE, FALSE

CT174 - Foundations of Information Technology 17


Programming Errors1
1https://www.bbc.co.uk/bitesize/guides/zbssv9q/revision/2

CT174 - Foundations of Information Technology 18


Types of Programming Errors
O When developing programs there are three
types of error that can occur:

1. Syntax Errors
2. Logic Errors
3. Runtime Errors

CT174 - Foundations of Information Technology 19


Syntax Errors
O A syntax error occurs when the code given does not
follow the syntax rules of the programming language.
O Examples include:
1. Misspelling a statement – writing pint instead of print
2. Using a variable before it has been declared
3. Missing brackets - opening a bracket, but not closing it

O A program cannot run if it has syntax errors. Any such


errors must be fixed first. A good integrated development
environment (IDE) usually points out any syntax errors to
the programmer.

CT174 - Foundations of Information Technology 20


Logical Errors
O A logic error is an error in the way a program
works. The program can run but does not do
what it is expected to do
O Examples
1. Incorrectly using logical operators – expecting
a program to stop when the value of a variable
reaches 5, but using <5 instead of <=5
2. Incorrectly using Boolean operators
3. Incorrectly using brackets in calculations

CT174 - Foundations of Information Technology 21


Logical Errors
4. Unintentionally creating a situation where an
infinite loop may occur
5. Unintentionally using the same variable name
at different points in the program for different
purposes

CT174 - Foundations of Information Technology 22


Run Time Errors
O A runtime error is an error that takes place
during the running of a program.

O An example is writing a program that tries to


access the sixth item in an array that only
contains five items. A runtime error is likely to
crash the program.

CT174 - Foundations of Information Technology 23


Skills that help thriving in
Computer Programming1
1https://www.uagrantham.edu/blog/5-skills-help-thrive-

computer-programming/

CT174 - Foundations of Information Technology 24


1. Problem Solving
O “So many developers, they're focused on the
syntax, they're focused on the language, they're
focused on learning to “code” or to program,
but not on solving problems.”

O Programmers are problem-solvers by


occupation, which it is one of the most vital
soft skills for success in the industry. The entire
basis of the job is to solve issues by creating
solutions to what different industries need.
CT174 - Foundations of Information Technology 25
2. A Sharp Memory
O After staring at complex sequences of programming
instructions all day, your brain may feel a little
scrambled and can lead to a jumble of information
in your head that may make you forget simple things.
While this seems harmless, it can hurt your progress
while you’re programming.
O A surprising way you may be harming your memory
is by multitasking. Researchers recommend changing
your working habits to minimize multitasking, which
may boost both memory and efficiency.
CT174 - Foundations of Information Technology 26
3. Efficient Laziness
O The point of programming is essentially to
make processes simpler and more efficient for a
company to save time and money

O People who are lazy will likely find the quickest


way to complete a task efficiently. In this
context, laziness is not inaction but efficiency

CT174 - Foundations of Information Technology 27


4. Self Motivation and
Independence
O The ability to self-motivate allows you to be
independent and work resourcefully — even if
you are “efficiently lazy.”

O Self-motivation sounds like the opposite of


laziness. However, the two soft skills create a
balance that may help when it comes to tackling
complex work and meeting deadlines

CT174 - Foundations of Information Technology 28


5. Perseverance
O It is rare that a code or a program will work on
the first try. It often takes programmers multiple
attempts and a lot of work to get an application
or webpage to run smoothly.
O It isn’t uncommon for programmers to scrap
hours of work and try a completely different
approach.
O That is why it is so important to be able to
handle failure and keep pushing forward if you
want to be a programmer
CT174 - Foundations of Information Technology 29

You might also like