[go: up one dir, main page]

0% found this document useful (0 votes)
12 views44 pages

Chapter 1 3

This document serves as an introduction to a programming course focused on C and C++ languages, emphasizing computational thinking over hardcore programming skills. It covers fundamental concepts of programming, including the distinction between system software and application software, the components of computer systems, and the programming process. Additionally, it outlines the structure of programs, the role of variables, and the differences between procedural and object-oriented programming.

Uploaded by

nedmacuacua88
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)
12 views44 pages

Chapter 1 3

This document serves as an introduction to a programming course focused on C and C++ languages, emphasizing computational thinking over hardcore programming skills. It covers fundamental concepts of programming, including the distinction between system software and application software, the components of computer systems, and the programming process. Additionally, it outlines the structure of programs, the role of variables, and the differences between procedural and object-oriented programming.

Uploaded by

nedmacuacua88
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/ 44

CHAPTER 1

Introduction to Computers and


Programming
COURSE OBJECTIVES
• This course aims to provide an overview of programming concepts,
design and an introduction to coding using the C and C++
languages. The course has a focus on creating working computer
programs in C++. This course will address the fundamental
concepts of analysis, design, code development, and testing.
• The major takeaway from this course is to improve computational
thinking skills rather than hardcore programming.
1.1
Why Program?
Why Program?
• Computer – programmable machine designed to follow instructions
• Program – sequence of 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
• Computer programs are often referred to as software where as
computer programs on digital devices (such as on smartphones)
are often referred as applications (also called apps)
• Software may be ranked along functional lines: system
software and application software
1.2
Computer Systems:
Software and Hardware
System Software Vs Application Software
• System Software
• Software that relies only on hardware to run. This type of
software does not require any other software to function and
can run on the top of hardware directly. So they manage the
computer hardware and the programs that run on them, e.g.
operating systems, utility programs, software development
tools
• Application Software
• Software that relies only on other software to run. This type of
software usually needs a System Software to run. So they
provide services to the use, e.g. word processing software,
games, programs to solve specific problems
• The C/C++ programs you are going to write within this course are
all in application Software
Main Hardware
Component Categories:
• Central Processing Unit
(CPU)
• Main Memory
• Secondary Memory /
Storage
• Input Devices
• Output Devices 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
Central Processing Unit (CPU)

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.
• Addresses – Each byte in memory is identified by a unique number
known as an address.
Main Memory

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.
Secondary Storage
• Non-volatile: data retained when program is not running or
computer is turned off
• Comes in a variety of media:
• magnetic: traditional hard drives that use a moveable
mechanical arm to read/write
• solid-state: data stored in chips, no moving parts
• 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, touchscreen, scanner, digital camera,
microphone
• Disk drives, CD drives, and DVD drives
1.3

Programming and Programming


Languages
Programming
• Programming is the task of writing high or medium level codes in
order to tell the computer what to do under certain circumstances.

• Computer programing is a skill, it is not a body of knowledge. Thus,


programming is best learned by practicing.
Programming Language
• Which?
• In this course, you will learn C programming style through C++
Syntax. There are many reasons why we select C/C++ as an
introductory programming language which includes but not limited
to
• how fast the language is;
• platform independency;
• the difficulty and the global use of the language.
• The programs you are going to write are essentially going to be
C++ programs.
What does it mean to code in C style in C++
• It might sound peculiar but what you are going to do is to use C++
statements in order to write C programs.
• C++ is an extension and upgraded version of C. so a lot of C
statements such as printf and scanf are quite old fashioned.
Instead of the old fashioned C statements that require different
data types to execute, we will use more generic and easy
statements of C++.
• For example, we will use cout<< instead of printf and cin>> instead
of scanf in this course.
• Many of the libraries we are going to use will be C++ libraries but
would work in a similar pattern as a C library
Software to Write the Programs?
• The software that is used to write programs are called Integrated
Development Environments simply referred as IDE.
• As C/C++ is a platform independent programming language, you
will need to select an IDE according to the operating system you
use
• Windows: DEV C++
• MAC: Xcode
• Linux: Code Blocks
• However we will stick to DEV C++ during lecture and lab sections.
Computer Algorithm
• A computer algorithm is a list of steps that you can follow to finish a
specific task.
Discussion
• Examining different
options of algorithms to
solve a problem.

Solving the Rubik Cube


Machine Language
• Regardless of how efficient the algorithm is, it is not ready to be
executed on the computer because the computer only executes
machine language instructions.
• Machine language instructions are binary numbers, such as

1011010000000101

• Rather than writing programs in machine language, programmers


use programming languages.
Types of
Programming
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 (Table 1-1 on Page 10)
From a High-Level Program to an Executable File
• Create file containing the program with a text editor.
• Run preprocessor to convert source file directives to source code
program statements.
• Run compiler to convert source program into machine instructions.
• 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
1.4

What is a Program Made of?


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
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
• Used to perform operations on data
• Many types of operators:
• Arithmetic - ex: +,-,*,/
• Assignment – ex: =

• Some operators in Program1-1:


<< >> = *
Punctuation
• Characters that mark
the end of a
statement, or that
separate items in a
list
• In Program 1-1: ,
and ;
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
Variables
• A variable is a named storage location in the computer’s memory
for holding a piece of data.
• A variable is usually a non-constant value that changes during the
program according to the actions of the users.

• 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 Definition
• 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;


• There are some rules about the name identifiers you are going to
use:
• Cannot start with number or dash
• Cannot have space or dash between the characters
• Cannot be reserved words or symbols
• Cannot include special characters other than $,
Variable Definition
• 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.

• For example, the word double specifies that the variables can
hold double-precision floating point numbers. (You will learn more
about that in Chapter 2)
1.5

Input, Processing, and Output


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
1.6

The Programming Process


The Programming Process
1.7

Procedural and Object-Oriented


Programming
Procedural and Object-Oriented Programming
• Procedural programming: focus is on the process. It specifies a
series of well-structured steps and procedures to compose a
program.
• Contains a systematic order of statements functions and
commands to complete a task. .
• The steps to complete the task is abstracted in
Procedures/functions.
• Object-Oriented programming: focus is on objects, which contain
data and the means to manipulate the data. Messages sent to
objects to perform operations.
Questions??
Thank you for your time.

You might also like