0% found this document useful (0 votes)
84 views

01 Introduction To Computers and Programming

Uploaded by

ryanzhang357
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

01 Introduction To Computers and Programming

Uploaded by

ryanzhang357
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Introduction to

Computers and Programming


What is a Computer?
◙ Computer – programmable machine designed to follow instructions
◙ Computers can do such a wide variety of things because they can be
programmed. This means computers are designed to do any job that
their programs tell them to do
◙ The uses of computers are almost limitless in our everyday lives
◘ In school, students use computers for tasks such as writing papers,
searching for articles, sending e-mail, and participating in online classes
◘ At work, people use computers to conduct business transactions,
communicate with customers and coworkers, analyze data, make
presentations, control machines in manufacturing facilities, and many
many other tasks
◘ At home, people use computers for tasks such as paying bills, shopping
online, social networking, and playing computer games
2
Why Program?
◙ Program – set of instructions in computer memory to make it do
something
◘ Programs are commonly referred to as software. Software is essential to
a computer because without software, a computer can do nothing.

◙ Programmer (software developer) – person who writes instructions


(programs) to make computer perform a task
◘ a person with the training and skills necessary to design, create, and test
computer programs.
◙ So, without programmers, no programs; without programs, a
computer cannot do anything

3
Computer Systems
◙ Computer systems consist of two main components:
◘ Hardware devices and
◘ Software components

4
Computer Hardware Component Categories
◙ Hardware refers to the physical components of which a computer is
made. A computer is not an individual device, but a system of devices.
◙ A typical computer system consists of the following major hardware
components:
1. Central Processing Unit (CPU)
2. Main Memory
3. Secondary Memory / Storage
4. Input Devices
5. Output Devices

5
Computer Hardware

Figure-1: Typical devices in a computer system 6


Central Processing Unit (CPU)
◙ The central processing unit, or CPU, is the part of a computer that
actually runs programs. The CPU is the most important component in
a computer because without it, the computer could not run software.
◙ The CPU’s job is to fetch instructions, follow the instructions, and
produce (compute) some result.
◙ Central processing unit (CPU) comprised of two parts:
◘ 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

7
CPU Organization

Figure-2: Organization of a CPU 8


Main Memory (1 of 2)

◙ Main memory – where the computer stores a program while the


program is running, as well as the data with which the program is
working.
◙ Main memory also called Random Access Memory (RAM), because
the CPU is able to quickly access data stored at any random location
in RAM.
◙ RAM is volatile. Main memory is erased when program terminates or
computer is turned off
◙ Computer memory is organized as follows:
◘ bit: smallest piece of memory. Has values 0 (off, false) or 1 (on, true)
◘ byte: 8 consecutive bits. Each byte has a unique addresses.

9
Main Memory (2 of 2)

◙ Addresses – Each byte in memory is identified by a unique number known as an


address.

◙ In Figure-3, the number 149 is stored in the byte with the address 16, and the
number 72 is stored at address 23.

Figure-3: Memory 10
Secondary Storage
◙ Secondary storage is a type of memory that can hold data for long
periods of time, even when there is no power to the computer
◙ Secondary storage is non-volatile. Data and / or programs retained
when computer is turned off
◙ Programs are normally stored in secondary memory and loaded into
main memory as needed.
◙ Secondary storage 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
11
Input Devices
◙ Input is any data the computer collects from the outside world
◙ Input 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, DVD drives, and USB drives can also be
considered input devices because programs and information are retrieved
from them and loaded into the computer’s memory.

12
Output Devices
◙ Output is any information the computer sends to the outside world. It
might be a sales report, a list of names, or a graphic image.
◙ The information is sent to an output device, which formats and
presents it.
◙ Common output devices are :
◘ screens, printers, plotters and speakers.
◘ Storage devices (like Disk drives, CD drives, DVD drives, and USB
drives) can also be considered output devices because the CPU sends
them data to be saved.

13
Software or Programs
◙ Everything a computer does, from the time you turn the power switch
on until you shut the system down, is under the control of software.
◙ There are two general categories of software:
◘ System software: programs that control and manage the basic operation
of a computer hardware and the programs that run on them.
■ Examples: operating systems, utility programs, Compilers and software
development tools
◘ Application software: programs to solve specific problems that provide
services to the user and make a computer useful for everyday tasks.
■ Examples : word processing, presentation program, spreadsheet programs,
e-mail programs, web browsers, and game programs.

14
Programs and Programming Languages
(1 of 2)

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


a task
◘ program tells the computer how to solve a problem or perform a task.

◙ Program development process starts with writing an algorithm, which


is a set of well-defined steps written in a native (natural) language.

15
Example Algorithm for Calculating Gross Pay

16
Machine Language (1 of 2)

◙ 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
◙ Machine language instructions are binary numbers (numbers
consisting of only 1s and 0s)
◙ The binary numbers form machine language instructions, which the
CPU interprets as commands. Following is an example of what a
machine language instruction might look like:
1011010000000101

17
Machine Language (2 of 2)

◙ The process of encoding an algorithm in machine language is very


tedious and difficult
◙ Each different type of CPU has its own machine language
◙ Rather than writing programs in machine language, programmers use
programming languages writing programs
◙ Programming languages use words instead of numbers, were invented
to ease the task of programming
◙ A program can be written in a programming language, such as C++,
which is much easier to understand than machine language
◙ Programmers save their programs in text files, then use special
software (compiler) to convert their programs to machine language.
18
Programs and Programming Languages
(2 of 2)

◙ Two types of programming languages:


◘ Low-level language is close to the level of
the CPU, which means it resembles the
numeric machine language of the computer
more than the natural language of humans
■ used for communication with computer
hardware directly. Often written in binary
machine code (0’s/1’s) directly.
◘ High-level language is closer to human
language
■ High-level languages are closer to the level
of human readability than computer
readability.

Figure-4: Low-level versus high-level languages 19


Some Well-Known Programming Languages

C++
BASIC Ruby
FORTRAN
Java
Visual Basic
COBOL
C# Swift

Rust JavaScript
C Python Go
Figure-5: High-level Programming languages
From a High-Level Program
to an Executable File (1 of 2)

◙ Following are the steps for the development of high-level language


program and translate it to a machine language program
a) Create file containing the program using a text editor.
◘ The program statements written in high-level language are called
source code, and the file they are saved in is called the source file
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.
21
From a High-Level Program
to an Executable File (2 of 2)

Figure-6: Translating a C++ source file to an executable file 22


Integrated Development Environments
(IDE) (1 of 2)

◙ An integrated development environment, or IDE, combine all the tools


needed to write, compile, and debug a program into a single software
application.
◙ These environments (IDE) consist of a text editor, compiler, debugger,
and other utilities integrated into a package with a single set of menus.
◙ Examples are Microsoft Visual C++, Turbo C++ Explorer, CodeWarrior,
etc.
◙ Figure-7 shows a screen from the Microsoft Visual Studio IDE.

23
Integrated Development Environments
(IDE) (2 of 2)

Figure-7: An integrated development environment (IDE) 24


What is a Program Made of?
◙ Common elements in programming languages:
◘ Key Words - that have a special meaning. Key words may only be used for their
intended purpose. Key words are also known as reserved words.
◘ Programmer-Defined Identifiers - Words or names defined by the
programmer. They are symbolic names that refer to variables or
programming routines.
◘ Operators - Operators perform operations on one or more operands. An
operand is usually a piece of data, like a number.
◘ Punctuation - Punctuation characters that mark the beginning or end of a
statement, or separate items in a list.
◘ Syntax - Rules that must be followed when constructing a program.
Syntax dictates how key words and operators may be used, and where
punctuation symbols must appear.
25
C++ Program

Figure-7: C++ Language Program 26


Key Words (1 of 2)

• Key words are also known as reserved words


• Key words have a special meaning in C++
• Key words can only be used for their intended purposes, can not be
used for any other purpose
• In C++ programs, key words are written in all lowercase
• Key words in the C++ Program: using, namespace, int, double,
and return

27
Key Words (2 of 2)
Programmer-Defined Identifiers
◙ Programmer-defined identifiers - Names made up by the programmer
◙ Programmer-defined identifiers are not part of the C++ language
◙ Used to represent various things: variables (memory locations),
functions, etc.
◙ In previous C++ Program: hours, rate, and pay are Programmer-
defined identifiers.

29
Operators (1 of 2)

◙ Operators are used to perform operations on piece of data known as


operands
◙ Many types of operators:
◙ Arithmetic operators :  , , , 
◙ Assignment operator: =
◙ Some operators used in previous C++ Program:   

30
Operators (2 of 2)
Punctuation (1 of 2)

◙ Characters that mark the end of a statement, or that separate items in


a list
◙ In previous C++ Program: , and ;

32
Punctuation (2 of 2)
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

34
Variables
◙ A variable is a named storage location in the computer’s memory for
holding a piece of data.
◙ In previous C++ Program, 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

35
Variable Definitions (1 of 3)

◙ To create a variable in a program you must write a variable definition


(also called a variable declaration)

◙ Here is the statement from previous C++ Program that defines the
variables:

double hours, rate, pay;

36
Variable Definitions (2 of 3)

◙ 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.

37
Variable Definitions (3 of 3)

• Once again, line 7 from previous C++ Program:

double hours, rate, pay;

• The word double specifies that the variables can hold double-
precision floating point numbers.

38
Input, Processing, and Output
Three steps that a program typically performs:
◙ Gather input data:
◘ from keyboard
◘ from files on disk drives
◙ Process the input data
◙ Display the results as output:
◘ send it to the screen
◘ write to a file

39
The Programming Process
◙ The programming process consists of several steps, which include
design, creation, testing, and debugging activities.
◙ Figure-8 showing the steps recommended for the process of writing a
program.

40
The Programming Process

Figure-8: Steps for writing a program 41


Procedural and Object-Oriented Programming
◙ Procedural programming and object-oriented programming are two
ways of thinking about software development and program design.
◙ Procedural programming: focus is on the process.
◘ The programmer constructs procedures (or functions, as they are called
in C++)
◘ The procedures each contain their own variables and commonly share
variables with other procedures.
◙ Object-Oriented programming: focus is on objects
◘ An object is a programming element that contains data and the
procedures that operate on the data.
◘ Messages sent to objects to perform operations.

42

You might also like