0% found this document useful (0 votes)
9 views54 pages

ECE151 - Lecture 1

ECE 151 is an introductory programming course focusing on C++ and covers topics such as expressions, decision-making, loops, functions, and object-oriented programming. The course includes approximately 12 lectures with a mix of lectures, homework, and a final project for assessment. Key materials include lecture slides, notes, and the textbook 'Starting Out with C++' by Tony Gaddis.

Uploaded by

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

ECE151 - Lecture 1

ECE 151 is an introductory programming course focusing on C++ and covers topics such as expressions, decision-making, loops, functions, and object-oriented programming. The course includes approximately 12 lectures with a mix of lectures, homework, and a final project for assessment. Key materials include lecture slides, notes, and the textbook 'Starting Out with C++' by Tony Gaddis.

Uploaded by

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

ECE 151 – Introduction to

Programming

Lecture 1

What is a computer program?


What is a computer? What is C++?
Course Content

1. Introduction to computer programming (Chapter 1/ 1 Lecture)


2. Expressions and interactivity (Chapter 3/ 1 Lecture)
3. Making decisions (Chapter 4 / 1 Lecture)
4. Loops (Chapter 5/ 1 Lecture)
5. Functions (Chapter 6/ 1 Lecture)
6. Arrays (Chapter 7/ 1 Lecture)
7. Pointers (Chapter 9/ 1 Lecture)
8. Strings, structured data types, I/O operation (1 Lecture)
9. Introduction to classes and objects (Chapter 13 /2 Lectures)
10.Inheritance, polymorphism, virtual functions (Chapter 15/ 1
Lecture)
Course Material

1. Lecture slides

2. Notes

3. Homework

4. Example codes

5. References

Tony Gaddis. Starting Out with C++: From Control Structures through Objects.
Pearson, Eighth Edition, 2015
Logistics

1. ~12 lectures

2. Marks distribution
40 Final, 60 Year work (Final project 20, homeworks and
assignments 20, midterm 15 and quizzes 5)

1. Please fill in course survey when the time comes

2. Please keep noise at minimum level during lecture time

3. Be on time
Overview

Chapter 1 : Introduction to Computers and Programming


This chapter introduces the field of computer science and covers the fundamentals of
programming, problem solving, and software design. The components of programs, such
as key words, variables, operators, and punctuation are covered. The tools of the trade,
such as pseudocode, flow charts, and hierarchy charts are also presented.
Why Program?
From Textbook 1

 Computer
Programmable machine designed to follow instructions.

 Program
Instructions in computer memory to make it do something.

 Programmer
Person who writes instructions (programs) to make computer perform a
task.

So, without programmers, no programs; without programs, a computer cannot


do anything

1 https://staff.emu.edu.tr/sebnemcoban/Documents/_itec243/StartingOutwithC++.pdf
Main Hardware Component
Categories

Figure 1-2
Central Processing Unit (CPU)

Comprised of:
Control Unit
Retrieves and decodes program instructions
Coordinates activities of all other parts of computer
Arithmetic & Logic Unit
Hardware optimized for high-speed numeric calculation
Hardware designed for true/false, yes/no decisions
CPU Organization

Figure 1-3
Main Memory

● It is volatile. Main memory is erased when program terminates,


or computer is turned off
● Also called Random Access Memory (RAM)
● Organized as follows:

○ bit: smallest piece of memory. Has values 0 (off, false) or 1


(on, true)

○ byte: 8 consecutive bits. Bytes have addresses.


Main Memory – Cont.

● Addresses – Each byte in memory is identified by a unique


number known as an address.

● In Figure 1-4, the number 149 is stored in the byte with the
address 16, and the number 72 is stored at address 23.
Main Memory – Cont.
Secondary Storage

● Non-volatile: data retained when program is not running, or


computer is turned off
● Comes in a variety of media:
○ Magnetic: floppy disk, hard drive

○ Optical: CD-ROM, DVD

○ Flash drives, connected to the USB port


Input Devices

● Devices that send information to the computer from outside


● Many devices can provide input:
○ Keyboard, mouse, scanner, digital camera, microphone

○ Disk drives, CD drives, and DVD drives


Software-Programs That Run on a
Computer
● Categories of software:
○ System software: programs that manage the computer hardware and the
programs that run on them. Examples: operating systems, utility
programs, software development tools
○ Application software: programs that provide services to the user.
Examples : word processing, games, programs to solve specific
problems
Open-Source Software - What

From RedHat 3

Open source is a term that originally referred to open-source software


(OSS). Open-source software is code that is designed to be publicly
accessible—anyone can see, modify, and distribute the code as they see fit.
Computer software with its source code made available with a license in
which the copyright holder provides the rights to study, change, and
distribute the software to anyone and for any purpose.

3 https://www.redhat.com/en/topics/open-source/what-is-open-source
Technical Standard - What

From RedHat 3

It is usually a formal document that establishes uniform engineering or


technical criteria, methods, processes and practices related to technical
systems.

3 https://www.redhat.com/en/topics/open-source/what-is-open-source
Programs & Programming
Languages

● A program is a set of instructions that the computer follows to


perform a task

● We start with an algorithm, which is a set of well-defined steps.


Programs & Programming
Languages – Cont.
According to John von Neumann 2
In computing, a program is a specific set of ordered operations for a
computer to perform. In the modern computer that John von Neumann
outlined in 1945, the program contains a one-at-a-time sequence of
instructions that the computer follows.

● A programming language is a formal computer language designed to


communicate instructions to a machine, particularly a computer.
● Programming languages can be used to create programs to control the
behavior of a machine or to express algorithms.

2Stallings, William. "COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR


PERFORMANCE EIGHTH EDITION." (2010).
Example Algorithm for Calculating
Gross Pay
Machine Language

● Although the previous algorithm defines the


steps for calculating the gross pay, it is not ready
to be executed on the computer.
● The computer only executes machine language
instructions
Language Programs
● Machine language instructions are binary
numbers, such as

1011010000000101

● Rather than writing programs in machine Logical Gates

language, programmers use programming


languages.
Programs and Programming
Languages

• Types of languages:

– Low-level: used for communication


with computer hardware directly.
Often written in binary machine
code (0’s/1’s) directly.

– High-level: closer to human


language
Some Well-Known Programming
Languages

C++
BASIC Ruby
FORTRAN
Java
Visual Basic

COBOL
C#
JavaScript
C Python
From a High-Level Program to an
Executable File
a) Create file containing the program with a text editor.
b) Run preprocessor to convert source file directives to source
code program statements.
c) Run compiler to convert source program into machine
instructions.
d) Run linker to connect hardware-specific code to machine
instructions, producing an executable file.
● Steps b–d are often performed by a single command or button
click.
● Errors detected at any step will prevent execution of following
steps.
From a High-Level Program to an
Executable File – Cont.
Integrated Development
Environments (IDEs)

● An integrated development environment, or IDE, combine all


the tools needed to write, compile, and debug a program into a
single software application.
● Examples are Microsoft Visual C++, Turbo C++ Explorer,
CodeWarrior, etc.
Examples of Programming
Paradigms

● Imperative
● Structured
● Procedural
● Functional
● Event-Driven
● Object-Oriented
● Declarative
● Reactive
● Others
Examples of Programming
Paradigms - Cont.

Imperative Programming
● Programming paradigm that uses statements that change a
program’s state.
● Imperative program consists of commands for the computer to
perform.
Most of the mainstream languages, including object-oriented
programming (OOP) languages such as C#, Visual Basic, C++,
and Java, were designed to primarily support imperative
(procedural) programming.
Examples of Programming
Paradigms - Cont.

Structured Programming
● Programming paradigm aimed at improving the clarity, quality,
and development time of a computer program
● Making extensive use of subroutines, block structures, for and
while loops—in contrast to using simple tests and jumps such
as the goto statement.
Examples of Programming
Paradigms - Cont.

Procedural Programming
● Derived from Structured programming
● Based upon the concept of the procedure call.
● Procedures, also known as routines, subroutines, or functions
simply contain a series of computational steps to be carried out.
● Any given procedure might be called at any point during a
program’s
● execution, including by other procedures or itself.
● Pascal, C, C++, Ada, Lisp, PHP, Python, and Go
Examples of Programming
Paradigms - Cont.

Functional Programming
● Treats computation as the evaluation of mathematical functions
and avoids changing-state and mutable data.
● Programming is done with expressions or declarations instead
of statements.
● In functional code, the output value of a function depends only
on the arguments that are passed to the function, so calling a
function f twice with the same value for an argument x will
produce the same result f(x) each time.
Examples of Programming
Paradigms - Cont.

Functional Programming
● C++, Clojure, Coffeescript, Elixir, Erlang, F#, Haskell, Lisp,
Python, Ruby, Scala, SequenceL, Standard ML, JavaScript
Examples of Programming
Paradigms - Cont.

Event-Driven Programming
● Flow of the program is determined by events such as user
actions (mouse clicks, key presses), sensor outputs, or
messages from other programs / threads.
● Dominant paradigm used in graphical user interfaces (GUI) and
other applications (e.g. JavaScript web applications) that are
centered on performing certain actions in response to user
input.
● This is also true of programming for Device Drivers, Game
Programming
Examples of Programming
Paradigms - Cont.

Object Oriented Programming


● Based on the concept of objects, which may contain data, in the
form of fields, often known as attributes; and code, in the form
of procedures, often known as methods.
● Programs are designed by making them out of objects that
interact with one another.
● Java, C++, C#, Python, PHP, Ruby, Perl, Object Pascal,
Objective-C, Dart, Swift, Scala, Common Lisp, and Smalltalk.
Examples of Programming
Paradigms - Cont.

● Procedural programming: focus is on the process.


Procedures/functions are written to process data.
● Object-Oriented programming: focus is on objects, which
contain data and the means to manipulate the data. Messages
sent to objects to perform operations.
What is a Program Made of?

● Common elements in programming languages:


○ Key Words
○ Programmer-Defined Identifiers
○ Operators
○ Punctuation
○ Syntax
Program 1-1
Key Words

● Also known as reserved words.


● Have a special meaning in C++
● Can not be used for any other purpose
● Key words in the Program 1-1: using, namespace, int, double,
and return
Key Words
Programmer-Defined Identifiers

● Names made up by the programmer


● Not part of the C++ language
● Used to represent various things: variables (memory
locations), functions, etc.
● In Program 1-1: hours, rate, and pay.
Operators
Operators - Cont.
Punctuation

● Characters that mark the end of a statement, or that


separate items in a list
● In Program 1-1: , and ;
Punctuation - Cont.
Syntax

● The rules of grammar that must be followed when writing a


program
● Controls the use of key words, operators, programmer-defined
symbols, and punctuation
Variable Definitions

● A variable is a named storage location in the computer’s


memory for holding a piece of data.
● In Program 1-1 we used three variables:
○ The hours variable was used to hold the hours worked
○ The rate variable was used to hold the pay rate
○ The pay variable was used to hold the gross pay
Variable Definitions - Cont.

● To create a variable in a program you must write a variable


definition (also called a variable declaration)

● Here is the statement from Program 1-1 that defines the


variables:

double hours, rate, pay;


Variable Definitions - Cont.

● There are many different types of data, which you will learn
about in this course.

● A variable holds a specific type of data.

● The variable definition specifies the type of data a variable can


hold, and the variable name.
Variable Definitions – Cont.

● Once again, line 7 from Program 1-1:

double hours, rate, pay;

● The word double specifies that the variables can hold


double-precision floating point numbers. (You will learn
more about that in Chapter 2)
Variable Definitions – Cont.
Variable Definitions – Cont.

From Textbook4

C++ also supports unsigned integers. Unsigned integers are


integers that can only hold non-negative whole numbers.

4 4.5 — Unsigned integers, and why to avoid them – Learn C++ (learncpp.com)
Input, Processing, and Output

Three steps that a program typically performs:


1) Gather input data:
■ from keyboard
■ from files on disk drives
2) Process the input data
3) Display the results as output:
■ send it to the screen
■ write to a file
Programming Process
Thank You

You might also like