You are on page 1of 71

AN OVERVIEW OF COMPUTER

AND PROGRAMMING
LANGUAGES
INTRODUCTION

• Without software, the computer is useless.


• Software is developed by using
programming languages.
- C++ is a programming language
• C++ is well suited for developing
software to accomplish specific tasks.
A BRIEF OVERVIEW OF THE
HISTORY OF COMPUTERS

• Abacus
- first device to carry
calculations
- invented in Asia
but used in ancient
Babylon, China,
and Europe
A BRIEF OVERVIEW OF THE
HISTORY OF COMPUTERS

• Pascaline
- invented by Blaise Pascal in 1642
- could sums up to 8 figures long
A BRIEF OVERVIEW OF THE
HISTORY OF COMPUTERS

• Stepped Reckoner
- a device invented by Gottfried von Leibniz
that was able to add, subtract, multiply, and
divide
A BRIEF OVERVIEW OF THE
HISTORY OF COMPUTERS
• Difference and
Analytical Engine
- invented by
Charles Babbage
- first
programmable
device that could
perform complex
operations
A BRIEF OVERVIEW OF THE
HISTORY OF COMPUTERS
• Punch Cards and
Calculating
Machine
- invented by
Herman
Hollerith
- used to
tabulate census
data
A BRIEF OVERVIEW OF THE
HISTORY OF COMPUTERS

• Mark I
- first computer-like machine built
in 1944 by IBM and Harvard
University under Howard Aiken
A BRIEF OVERVIEW OF THE
HISTORY OF COMPUTERS
• ENIAC
- Electronic
Numerical
Integrator and
Calculator
- built at the
University of
Pennsylvania in
1946
A BRIEF OVERVIEW OF THE
HISTORY OF COMPUTERS
• UNIVAC
- Universal
Automatic
Computer
- built and sold to
the US Census
Bureau in 1951
A BRIEF OVERVIEW OF THE
HISTORY OF COMPUTERS
• In 1956, the invention of transistors
resulted in smaller, faster, more
reliable, and more energy-efficient
computers.
• This era also saw the emergence of
the software development industry
with the introduction of FORTRAN,
and COBOL.
A BRIEF OVERVIEW OF THE
HISTORY OF COMPUTERS

• In 1970, the microprocessor, an entire


central processing unit (CPU) on a
single chip, was invented.
• In 1977, Stephen Wozniak and
Steven Jobs designed and built the
first Apple computer in their garage.
A BRIEF OVERVIEW OF THE
HISTORY OF COMPUTERS

• In 1981, IBM introduced it personal


computer (PC).
• In the 1980s, clones of the IBM PC
made the personal computer even
more affordable.
ELEMENTS OF A COMPUTER
SYSTEM
• A computer is an electronic device
capable of performing commands.
• The basic commands that a computer
performs are input (get data), output
(display result), storage, and
performance of arithmetic and logical
operations.
ELEMENTS OF A COMPUTER
SYSTEM
• Hardware
- Central Processing Unit (CPU)
- Main Memory (MM): also called
random access memory (RAM)
- Input/Output Devices
- Secondary Storage
ELEMENTS OF A COMPUTER
SYSTEM
• Central Processing Unit (CPU)
- brain of the computer
- most expensive piece of hardware
- carries out arithmetic and logical
operations
ELEMENTS OF A COMPUTER
SYSTEM
ELEMENTS OF A COMPUTER
SYSTEM
• Main Memory or Random Access
Memory
- Random Access Memory – directly
connected to the CPU
- All programs must be loaded into
main memory before they can be
executed.
ELEMENTS OF A COMPUTER
SYSTEM
• Main Memory or Random Access
Memory
- All data must be brought into the
main memory before it can be
manipulated
- When computer is turned off,
everything in main memory is lost.
ELEMENTS OF A COMPUTER
• Main Memory SYSTEM
or Random Access
Memory
- Main memory is an ordered
sequence of memory cells. Each
cell has a unique location in main
memory called the address of the
cell.
- Each cell can contain either a
programming instruction or data.
ELEMENTS OF A COMPUTER
SYSTEM
• Secondary Storage
- a device that stores information
permanently
Examples of secondary storage:
- Hard Disks
- Flash Drives
- Floppy Disks
- Zip Disks
- CD-ROMs
- Tapes
ELEMENTS OF A COMPUTER
SYSTEM
• Software
- are programs written to perform
specific tasks (i.e. word
processors: use to write letters,
papers, books, etc.)
- are all written in programming
languages
- two types of programs: system and
application programs
ELEMENTS OF A COMPUTER
SYSTEM
• Input/Output Devices
- Input devices feed data and
programs into computers
(Keyboard, Mouse, Secondary
Storage)
- Output devices display results
(monitor, printer, secondary
storage)
ELEMENTS OF A COMPUTER
SYSTEM

• System programs control the


computer. The system program that
loads first when you turn on your
computer is called the operating
system. Without an operating system,
the computer is useless.
ELEMENTS OF A COMPUTER
SYSTEM
• System Programs
- Operating system handles the
overall activity of the computer
and provides services such as:
 Memory management
 Input/output activities
 Storage management
ELEMENTS OF A COMPUTER
SYSTEM
• Application programs perform a
specific task. Examples of such are:
- Word processors
- Spreadsheets
- Games
• The operating system is the program
that runs application programs.
THE LANGUAGE OF A
COMPUTER
• Two types of electrical signals:
analog and digital signals
• Analog Signals – are continuously
varying continuous wave forms used
to represent such things as sound.
Audio tapes, for example, store data
in analog signals.
THE LANGUAGE OF A
COMPUTER
• Digital Signals – represent
information with a sequence of 0s
and 1s. A 0 represents a low voltage,
and a 1 represents a high voltage.
Digital signals are more reliable
carriers of information than analog
signals and can be copied from one
device to another with exact
precision.
THE LANGUAGE OF A
COMPUTER
• Because digital signals are processed
inside a computer, the language of a
computer, called machine language,
is a sequence of 0s and 1s.
• Binary Digit (Bit) – digit 0 or 1
• Binary code (Binary number) – a
sequence of 0s and 1s
THE LANGUAGE OF A
COMPUTER
• Byte – a sequence of eight bits
• Kilobyte (KB) : 210 bytes = 1024
bytes
• ASCII (American Standard Code for
Information Interchange) – most
commonly used seven-bit encoding
scheme on personal computers
- 128 characters
THE LANGUAGE OF A
COMPUTER
THE LANGUAGE OF A
COMPUTER
ASCII
THE LANGUAGE OF A
COMPUTER
• There are other encoding schemes,
such as EBCDIC (used by IBM) and
Unicode, which is a more recent
development.
• EBCDIC consists of 256 characters
• Unicode consists of 65, 536
characters.
THE LANGUAGE OF A
COMPUTER
• To store a character belonging to a
Unicode, you need 16 bits or two
bytes.
• Unicode was created to represent a
variety of characters and is
continuously expanding.
• It consists of characters from
languages other than English.
THE EVOLUTION OF
PROGRAMMING LANGUAGES
• Early computers were programmed in machine language
• To calculate wages = rate * hours;

In machine language:

100100 010001 //Load

100110 010010 //Multiply

100010 010011 //Store


THE EVOLUTION OF
PROGRAMMING LANGUAGES
• Assembly languages were developed
to make the programmer’s job easier.
• In assembly language, instructions
are mnemonic.
• Assembler: translates a program
written in assembly language into
machine language
THE EVOLUTION OF
PROGRAMMING LANGUAGES
Using assembly language
instructions:
THE EVOLUTION OF
PROGRAMMING LANGUAGES

• Using assembly language


instructions, wages = rate * hours can
be written as:
LOAD rate
MULT hour
STOR wages
THE EVOLUTION OF
PROGRAMMING LANGUAGES
• High-level languages include Basic,
FORTRAN, COBOL, Pascal, C, C+
+, C#, and Java
• Compiler: translates a program
written in a high-level language into
machine language
• In C++:
wages = rate * hours;
PROCESSING A C++ PROGRAM
• Consider the following C++ program:
#include <iostream>
using namespace std;
int main()
{
cout << "My first C++ program." << endl;
return 0;
}

Sample Run:
My first C++ program.
PROCESSING A C++ PROGRAM
• To execute a C++ program:
- Use an editor to create a source
program in C++
- Preprocessor directives begin with #
and are processed by the
preprocessor
- Use the compiler to: Check that the
program obeys the language rules;
Translate into machine language
PROCESSING A C++ PROGRAM
• To execute a C++ program:
- Linker: Combines object program
with other programs provided by the
SDK to create executable code;
Library: contains prewritten code
you can use
- Loader: Loads executable program
into main memory
- The last step is to execute the
PROCESSING A C++ PROGRAM
• Figure below shows how a typical C+
+ program is processed.
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
• Programming is a process of problem
solving.
• To be a good problem solver and a
good programmer, you must follow
good problem-solving techniques.
• Algorithm – a step by step problem-
solving process in which a solution is
arrived at in a finite amount of time
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION CYCLE

• The figure shows


the summary of
the steps in
Problem
analysis-coding-
execution cycle .
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
• In programming environment, the
problem-solving process requires the
following steps:
1. Analyze the problem
- Outline the problem and its
requirements
- Design steps (algorithm) to solve the
problem
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE

2. Implement the algorithm


- Implement the algorithm in code
- Verify that the algorithm works
3. Maintenance
- Use and modify the program if the
problem domain changes
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE

4. Thoroughly understand the


problem and all requirements.
- Does the program require user
interaction?
- Does program manipulate data?
- What is the output?
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
5. If the problem is complex, divide it
into subproblems
- Analyze and design algorithms for
each subproblem
6. Check the correctness of algorithm
- Can test using sample data
- Some mathematical analysis might be
required
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE

7. Once the algorithm is designed and


correctness verified
- Write the equivalent code in high-
level language
8. Enter the program using text editor
9. Run code through compiler
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE

10. If compiler generates errors


- Look at code and remove errors
- Run code again through compiler
11. If there are no syntax errors
- Compiler generates equivalent
machine code
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
12. Linker links machine code with
system resources
13. Once compiled and linked, loader
can place program into the main
memory for execution
14. The final step is to execute the
program
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE

15. Compiler guarantees that the


program follows the rules of the
language
- Does not guarantee that the program
will run correctly
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
Example 1 – 1:
Design an algorithm to find the
perimeter and area of a rectangle.
Note:
To find the perimeter and area of a
rectangle, you need to know the
rectangle’s length and width
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
Answer:
The algorithm is:
1. Get the length of the rectangle.
2. Get the width of the rectangle.
3. Find the perimeter using:
perimeter = 2 * (length + width)
4. Find the area using:
area = length * width
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
Example 1 – 2:
There are 10 students in a class. Each
student has taken five tests, and each test is
worth 100 points. We want to design an
algorithm to calculate the grade for each
student, as well as the class average. The
grade is assigned as follows: If the average
test score is greater than or equal to 90, the
grade is A;
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
if the average test score is greater than or
equal
to 80 and less than 90, the grade is B; if the
average test score is greater than equal to 70
and less than 80, the grade is C; if the average
test score is greater than or equal to 60 and
less than 70, the grade is D; otherwise, the
grade is F. Note that the data consists of
students’ names and their test scores.
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
Answer:
This is a problem that can be divided into
subproblems as follows:
1. Design an algorithm to find the average
test score
2. Design an algorithm to determine the
grade.
The two subproblems are to determine the
average test score and to determine the grade.
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
Answer:
Algorithm to determine the average test
score:
1. Get the five tests scores.
2. Add the five test scores. Suppose sum
stands for the sum of the test scores.
3. Suppose average stands for the average
test score:
average = sum / 5;
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
Algorithm to determine the grade: (Suppose
grade stands for the grade assigned to a
student.)
if average is greater than or equal to 90
grade = A
otherwise
if average is greater than or equal to 80 and less
than 90
grade = B
otherwise
if average is greater than or equal to 70 and less
than 80
grade = C
otherwise
if average is greater than or equal to 60 and less
than 70
grade = D
otherwise
grade = F
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
You can use the solutions to these
subproblems to design the main algorithm
as follows:
1. totalAverage = 0;
2. Repeat the following for each student:
• Get student’s name
• Use the algorithm to find the average
test score
PROGRAMMING WITH THE PROBLEM
ANALYSIS-CODING-EXECUTION
CYCLE
You can use the solutions to these
subproblems to design the main algorithm
as follows:
2. Repeat the following for each student:
• Use the algorithm to find the grade
• Update totalAverage by adding
current student’s average test score
3. Determine the class average as follows:
classAverage = totalAverage / 10
PROGRAMMING
METHODOLOGIES

• Two popular approaches to


programming design
- structured approach
- object-oriented approach
PROGRAMMING
METHODOLOGIES
• Structured design:
- dividing a problem into smaller
subproblems
• Structured programming
- the process of implementing a structured
design
• The structured design approach is also called:
- Top-down (or bottom-up) design
- Stepwise refinement
- Modular programming
PROGRAMMING
METHODOLOGIES
• Object-oriented design (OOD)
Steps:
- identify the components called objects
- determine how objects interact with each
other
- specify relevant data and possible
operations to be performed on that data
- each object consists of data and operations
on that data
PROGRAMMING
METHODOLOGIES
• Object-oriented design (OOD)
- An object combines data and operations on
the data into a single unit
- A programming language that implements
OOD is called an object-oriented
programming (OOP) language
- Must learn how to represent data in
computer memory, how to manipulate data,
and how to implement operations
PROGRAMMING
METHODOLOGIES
• Object-oriented design (OOD)
- Write algorithms and implement them in
a programming language
- Use functions to implement algorithms
- Learn how to combine data and
operations on the data into a single unit
called an object
- C++ was designed to implement OOD
- OOD is used with structured design
ANSI/ISO STANDARD C++
• C++ evolved from C
• C++ designed by Bjarne Stroustrup at
Bell Laboratories in early 1980s
• Many different C++ compilers were
available
• C++ programs were not always portable
from one compiler to another
• In mid-1998, ANSI/ISO C++ language
standards were approved
SUMMARY
• Computer: electronic device that can
perform arithmetic and logical operations
• Computer system has hardware/software
 Central processing unit (CPU): brain
 Primary storage (MM) is volatile;
secondary storage (e.g., disk) is
permanent
 Operating system monitors overall
activity of the computer and provides
services
 Various kinds of languages
SUMMARY
• Compiler: translates high-level language
into machine code
• Algorithm: step-by-step problem-solving
process; solution in finite amount of time
• Problem-solving process has three steps:
 Analyze problem and design an
algorithm
 Implement the algorithm in code
 Maintain the program
SUMMARY
• Structured design:
 Problem is divided into smaller
subproblems
 Each subproblem is solved
 Combine solutions to all subproblems
• Object-oriented design (OOD): a program
is a collection of interacting objects
 Object: data and operations on those
data

You might also like