Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

CPL - PRELIMS

HISTORY OF COMPUTERS

Computer Punched Cards


o Machine that can perform many tasks o Joseph Marie Jacquard, 1801
o Originally invented to do speedy & o Power loom that could base its weave
accurate calculation upon a pattern automatically read from
o Can perform arithmetic, logical punched wooden cards
operations, process it per instruction,
input given, give info as output
Babbage’s Difference Engine

Abacus o Charles Babbage, 1822


o Difference engine – steam driven
o Early aid for mathematical computations calculating machine the size of a room
o Not from China – 300 B.C. by the o Would be able to compute tables of
Babylonians numbers such as logarithm tables
o Still in use in the far east

Mark 1
Schickard’s Calculating Clock
o 1944
o First gear-driven calculation machine o Special step in computer history
o Got little publicity because Schickard o First automatic digital computer in the
died in bubonic plague world

Pascal’s Pascaline ENIAC


o Invented as aid for father who was a tax o Very large
collector o Vacuum tubes technology
o 1642, Blaise Pascal o First general-purpose computer
o Same mechanism as odometer of car’s
speedometer
o Pascal also invented probability theory, Univac
hydraulic press, syringe
o 1951
o Faster and smaller that ENIAC and
Leibniz’s Stepped Reckoner Mark 1

o Gottfried Wilhelm Leibniz – German


o First to advocate use of binary numbers
o Stepped reckoner – 4-function calculator
(add/subtract/multiply/divide)
COMPUTER GENERATIONS

First Generation (1940 – 1956) Fifth Generation (Present and Beyond)

o Built during the World War II o Only in the minds of advance research
o First computers – designed for a specific scientists
task – extremely slow o Will be under artificial intelligence (AI)
o Relied on vacuum tubes and magnetic o Operations which requires low human
drums intelligence
o Parallel Processing - power of CPU’s
can be used side by side
o Will be more powerful than those under
Second Generation (1956 – 1963)
central processing
o Make use of transistors invented by Bell o Advances in super conductor technology
Telephone laboratories will greatly improve speed of info traffic
o Had many of the same components as
modern-day computers
o Had printer, tape or disk storage,
operating systems, stored programs,
memory
o More reliable and solid in design

Third Generation (1864 – 1971)


o Smaller in size – use integrated circuits
and semiconductors
o Contained operating systems - overseers
computer performance, allowed to run
diff. programs at once
o Operating system – make sure
everything is flowing smoothly inside
the computer
o Transition: transistors to integrated
circuits; punch cards to electronic
computer system

Fourth Generation (1971 – Present)


o Marked by usage of integrated circuits
and microprocessors
o Computers become smaller and prices
lower
o Million of components in a single
silicon chip
o More efficient and more reliable – could
perform more and more operations
o Networks became commonplace –
whole world became connected by
internet and world wide web
PARTS AND FUNCTION OF COMPUTER

Computer o Can be controlled by user using simple


or multi-touch gestures (touching the
o System of information screen with stylus/pen or finger/s)
o Perform input, processing, output, o User can use touchscreen to react and
storage, control functions control to what is displayed
o Consists of
▪ Input and output devices
▪ Central processing Unit Light Pens
▪ Primary/secondary storage
devices o Light sensitive wand used in
▪ Peripheral devices conjunction with computer’s CRT
display
o Allows user to point to displayed object
Input Device o Allows user to draw on screen like touch
screen but with greater positional
o Any peripheral used to provide data and accuracy
control signals to an information
processing system
o Convert data into electronic-readable Scanners
form
o Scans documents
o Creates electronic version of document
Examples of Input Devices that can be viewed / edited on a
computer
Keyboard o Most scanners are flatbed devices
o Type-writer style device
o Buttons or keys act as mechanical levers
/ electronic switches Computer Microphone
o Teleprinter-style keyboard became the o Converts sound waves into analogous
main input device for computers electrical waves
o Usually called “mike”
o Contains flexible diaphragm with
Mouse film/foil that vibrates as it makes contact
with sound
o Pointing device: detects two-
dimensional motion relative to a surface
o Typically translated to motion of a
pointer on a display __________
o Allows for fine control of graphical user
interface
*
The first touch screen phone
Touch Screen
IBM Simon Personal Communicator
o Electronic visual display
Processing Primary Storage Unit
CPU (central processing unit) – main
processing component of a computer system
__________
Microcomputers – CPU is the main
microprocessor
Output Devices
ALU – CPU’s major arithmetic-logic unit:
perform arithmetic and logic o Convert electronic info produced by
computer system to human-intelligible
form
Components of CPU
Examples of Output Devices
Control Unit
Video display units
o Directs operation of the processor
o VDU or “Monitor”
o Controls communication and
o Can also refer to another type of display:
coordination between input/output
e.g.: digital projector
devices
o Displays images generated by computer
o Reads and interprets instructions
o May be peripheral devices or integrated
o Determines sequence for processing
with other components
data

Audio Response Unit


Arithmetic-Logic Unit
o Provides synthesized voice responses to
o Fundamental building block of CPU
dual-tone multifrequency signaling input
o Digital circuit: inter arithmetic and
o Processing calls based on
logical operations
o Call-originator input
o Maintaining timers
o Info received from a host data
o GPUs (Graphics processing units)
base
accommodate v powerful and v complex
o Info: incoming call (e.g.: time of
ALUs
day)

Computer Data Storage


Printers
o Storage or memory
o Peripheral which makes a persistent
o Computer components + recording
human-readable representation of
media used to retain digital data
graphics or text on paper or similar
o Core function and fundamental
physical media
component of computers
o CPU manipulates data by performing
computations
o Storage Hierarchy – fast but expensive __________
storage: close to CPU; slower but larger
and cheaper: farther away
Storage
o Used to store data and program
instructions needed for processing

Primary Storage Unit (main memory / hard


disk)
o Main area which data is stored for quick
access by the computer’s processor
o RAM – used instead of main storage
o Hard disk, CD and DVD collectively –
secondary / auxiliary storage

Secondary Storage Devices (magnetic disks,


tape units, optical disks)
o Storage devices and storage media that
are not always directly accessible by a
computer
o Differ from internal hard drive
o Internal hard drive is constantly
available

__________

*
Who is the mathematician who proposed the
ALU concept in 1945 and design the parts of
CPU
John Von Neuman
CPL – MIDTERMS - FINALS IDE – Integrated Development Environment

NUMBER SYSTEMS
Three Stages of Developing a Computer
1. Binary – 0,1 – base 2 Program
2. Decimal – 0-9 – base 10
1. Creating
3. Octal – 0-7 – base 8
2 Main stages:
4. Hexadecimal – 0-9, A-F – base 16
Designing a program
A = 10 D = 13 Physically creating the program
B = 11 E = 14 - Has to be entered into the computer
C = 12 F = 15 - filename.cpp

2. Compiling
FLOWCHARTING - Converts source code to instructions
for the computer to run
Terminal (Start/End) - Stores these as executable file (.exe)
3. Running
Arrow

Input/Output Linking

Process box - All information which tells the


computer how to write messages to
Decision the screen, and how to read info from
the keyboard, is linked into the
program you write.
Notes: (Decisions)
No: always to the right/left
BASIC ELEMENTS OF A C++ PROGRAM
Yes: always downwards
1. Character Set
C++ program is constructed as a sequence of
characters
A : next page connector - Lowercase letters (a-z)
- Upper case letters (A-Z)
- Digits (0-9)
A : same page connector - Special characters (+, /, -, *,=, ), …

2. Identifiers
INTRO TO C++ PROGRAMMING - Sequence of one or more
letters/digits/underline symbol
ANSI-C++ - Length not limited
(for some compiler: only first 32
- Published: November 1997
characters are significant)
Compilers – editors specifically tailored for - Spaces/marked letters are not part
C++ programs - Should always begin with a letter
- Can also begin with _ but usually for Declaring Variables
reserved external links
- Stating data-type and variable name
- Never begin with a digit
- Variables with same data type can be
- Cannot match any keyword of C++
grouped together
(variable names separated by
commas)
(semicolon to terminate declaration)
Variables - Variable may be assigned with initial
value
- Basic data objects manipulated in the
program 3. Data-types
- Can take on any value while program Computer’s memory is organized in bytes
is running Bytes: minimum amt of memory that we can
- Initialized before use (random number manage
or 0)
- Must be declared int the declarations
list
- Type is specified:
o char (hold single letter)
o int
o float (with decimal points)
o etc

Variable Names
- Up to 31 characters
- A – Z or a – z (case sensitive)
- 0 – 9 (but not as first character)
- Underscore (but not as first character)
- Generally better sticking to lower case
- Must not be a C++ keyword Signed/Unsigned
- Used to specify integer data type
(range)
C++ keywords - Default: signed
Declarations:
Constants
- Can declare constants with specific
type as you would with a variable
Integer Numbers
- Identify integer decimal places
-
-
- Allows use of octals and hexadecimals
(octal: precede with 0)
(hexadeci: precede with 0x) < Less than
>= Greater than or equal
Floating Point Numbers
<= Less than or equal
- Expresses numbers with decimals
and/or exponents Logic Operators
- e (“ten at the Xth height”) ! Not
&& And
Characters and Strings || Or
- Escape codes:
Conditional Operator
?:
condition ? result1 : result 2
- If true – will return result1
- If false – will return result2

Bitwise Operators

4. Operators

= assignment operator
Order of Precedence
Arithmetic Operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Module (obtain remainder)

Compound Assignation Operators


+= (a = a + increase)
-= (a -= b: a = a – b)
/= (a = a/b)
*= (a = a * (units + 1)

Increment and Decrement


a++
++a
STRUCTURE OF A C++ PROGRAM
Relational Operators Scope of Variables
== Equal
!= Different - All variables must be previously
> Greater than declared
Global Variables – anywhere in the code, d. Return Statement
within any function - Cause main function to finish and
return the code and return the code,
Local Variables – limited to code level
followed by 0
which they are declared
- Most usual way to terminate a
Comment ( // are optional) program

- // new style
- /* old style */
COMMUNICATION THROUGH
CONSOLE

Preprocessor Directive Console

# - are directives for the preprocessor; are not - Basic interface of computers
executable, but indications - Set composed of the keyboard (input)
and the screen (output)
#include Directive
iostream C++ library:
- Tells compiler’s preprocessor to
include - cin (input)
- cout (output)
#define Directive - cerr and clog (designed to show error
- Used to define an identifier and a messages)
string that will be substituted for the Output (cout)
identifier each time it is encountered
in the source file - used in conjunction with <<
- << (insertion operator) : inserts the
data
Function Prototype - “” : for constant string of characters
- cout << “the sentence”;
- Provides compilers with name and - \n or endl : line break
arguments of the function
- Must appear before function is used Escape sequences

The Main Function


- Anything before it is “set-up” code
- “main” is case sensitive
- Conventionally goes right @
beginning od the program (after the
set-up code)
a. Variable Definition
b. Program Statements
- Complete direction instructing
computer to carry out some tasks
c. Expressions
- Anything that evaluates to a numerical
value
Input (cin) else-if Statements
- >> (overload operation of extraction) if (expression1)
- >> then variable that will store the
{
data that is going to be read
- cin >> variable; statements 1;
- can only process the input from
keyboard once return key (enter key?) }
has been pressed else if (expression2)
{
CONDITIONAL if STATEMENTS statements 2;
Block of Instructions }
- group of instructions separated by else if(expression3)
semicolons (;) but grouped in a block
delimited by {} {

if Statements statements 3;

if (expression) }

{ statement1; else

statement2; {

statement_last; statements 4; }

} - Are evaluated in order


- If any is true (executed), the rest is
- If condition is true – executed terminated
- If condition is false – ignored

CONDITIONAL switch STATEMENTS


Nested if Statements
Switch Statements
- if inside other if
- Provide more concise representation
if (n > 0) of multiple else-if statements
{ - Multiway decision: tests whether an
expression matched one of a number
if (a > b) of constant int values
z = a; Points to consider:
} - No floats
- Must evaluate an integer
else
- Switch should match a case
z = b; - Should have default case (when none
matched)
- Break: stops execution of any further LOOPING do…while STATEMENT
statements
- Tests the stated condition:
If true: will execute & repeat the loop
If not: statements may never be
LOOPING while STATEMENT
executed
Increment and Decrement - Performs statement first and tests the
condition
- Increase/decrease value of the variable
by 1 initialization;
- i++ (postfix form)
do
- ++i (prefix form)
{
statements;increment/decrement;
}
while(condition);

LOOPING for STATEMENT


- for: marks the beginning of the code
The while Loop
which will be repeated according to
Initialization; the conditions supplied
While (condition) for (initialization; condition;
increment/decrement)
{
{
statements;
statements;
increment/decrement;
}
}
- initialization: carried out only once
- Repeat statement while the condition loop is first entered
is true - condition: tested before each run of
- If value entered fulfills condition n > the loop
0, block of instructions will execute - increment/decrement: alter the test
indefinitely while condition remains condition variable
true - for statements provide places to
The break Instruction specify and initialization instruction
and an increase/decrease instruction
- Used to leave a loop even if the
condition for its end is not fulfilled
The continue Instruction
- Causes program to skip the rest of the
loop in the present iteration

You might also like