0% found this document useful (0 votes)
17 views29 pages

Week 5

The document provides an agenda for a class on computer programming that covers the following topics: 1) An introduction to what computer programming is and programming basics like algorithms, variables, and data types. 2) Logical and Boolean operators that are used for conditions in selection and iteration. 3) Arrays, which are a series of memory locations that store multiple items of the same data type. 4) Common errors in programming like syntax, logic, runtime, and semantic errors and the importance of documenting code with comments.

Uploaded by

joemoak2705
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views29 pages

Week 5

The document provides an agenda for a class on computer programming that covers the following topics: 1) An introduction to what computer programming is and programming basics like algorithms, variables, and data types. 2) Logical and Boolean operators that are used for conditions in selection and iteration. 3) Arrays, which are a series of memory locations that store multiple items of the same data type. 4) Common errors in programming like syntax, logic, runtime, and semantic errors and the importance of documenting code with comments.

Uploaded by

joemoak2705
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Class 05

ENGN-1310
Today’s Agenda

01 02
What is Computer Programming Basics
Programming?

03 04 05
Logical & Boolean Arrays Errors &
Operators Documentation
Why Programming?

https://youtu.be/Dv7gLpW91DM
What is Computer
Programming?
● A program is a set of instructions that tell a
computer what to do.

● A programming language is a language


used to communicate with a computer.
What is a compiler?
Machine code

Fortran
Bits and Bytes
• A binary digit is a single numeral in a
binary number.

• It is represented using 0’s and 1’s.


Programming Basics
Programs are an
implementation of
algorithms.
Algorithms can be
represented as
pseudocode or a
flowchart
Programming is the
translation of these into a
computer program.
Understanding Variable

It is made of three parts:


a name
a type
a value

Why use variables?


Variables are a key element of programming.
They are used for calculations, for storing
values for later use, in decisions and in
iteration.
Naming Variables
The name given to each variable is up to
the programmer, but ideally a variable
name should have meaning , i.e. it should
reflect the value that it is holding.

Rules of Naming:
Consistency, spacing and digits
Data Types
Variables are used to store numbers, some are used to store text, and some are
used for much more complicated types of data.

Most of the programming languages requires variables to be declared before they


can be used.
Types of Data:

• String. Used for a combination of any characters that appear on a


keyboard, such as letters, numbers and symbols.
• Character (or char). Used for single letters.
• Integer (or int). Used for whole numbers.
• Float (or Real). Used for numbers that contain decimal points, or
for fractions.
• Boolean (or bool).
LOGICAL AND BOOLEAN
OPERATORS
● A symbol or word used to connect two or more
expressions such that the value of the compound
expression produced depends only on that of the
original expressions and on the meaning of the
operator.
● Boolean logic is a form of algebra where all values
are either True or False. These values of true and false
are used to test the conditions that selection and
iteration are based around.
Logical Example
USING AND
USING OR
Arrays
An array is a series of memory locations – or ‘boxes’ –
each of which holds a single item of data, but with each
box sharing the same name.

All data in an array must be of the same data type, and


Element
arrays can be multi dimensional.
● The number in brackets determines how many data items the array can hold.

● One-dimensional array

● Any facility that hold more than one data item is called a data structure.

● To access the data stored in an element, the element must be referred to by


its number.
● Two- dimensional Array
Error and Documenting Code
Errors in programs are often referred to as bugs.

Errors can cause a program to produce unexpected results,


or crash.

Types

Syntax Error Logic Error

Runtime Error Semantic Error


Each type of error is different, and each is solved in different ways.

Documenting code
is the best practice.
Syntax Error
Errors in spelling and grammar of a programming
language.

Syntax errors will cause a program to crash or not run at


all.

The program may run until it encounters a syntax error,


then it will stop.
Logic Error
Errors that occur when there is a fault in the logic or
structure of the problem.

Logic errors can cause a program to produce unexpected


results.
Imagine that a program is required to determine if we are eligible for
discounted tickets at the cinema, when discounted tickets are available for
people aged 15 or under and those who are 65 or over.
Documenting Code
Why?
• To make it easier to read and understand.

• When we need to come back to it at a later date.

• someone else needs to change or fix it.


How?
• giving meaningful names for variables, procedures and
functions

• placing comments within the code to explain the


purpose of each step

A comment is one or more sentences that explain the


purpose of a section of code.

A comment is placed just before (or after) the code to


which it refers.
Food for thought!

https://youtu.be/YPE2dO5sII0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy