0% found this document useful (0 votes)
102 views40 pages

Introduction To Computers and C++ Programming

This document provides an introduction to computers and C++ programming. It discusses what a computer is and how it is organized into logical units including input, output, memory, CPU, and secondary storage. It also covers the evolution of programming languages from machine language to assembly language to high-level languages like C++. Key concepts introduced include variables, data types, input/output, and the basic structure of a C++ program.

Uploaded by

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

Introduction To Computers and C++ Programming

This document provides an introduction to computers and C++ programming. It discusses what a computer is and how it is organized into logical units including input, output, memory, CPU, and secondary storage. It also covers the evolution of programming languages from machine language to assembly language to high-level languages like C++. Key concepts introduced include variables, data types, input/output, and the basic structure of a C++ program.

Uploaded by

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

CHAPTER 1:

Introduction to Computers and


C++ Programming
What is a Computer?
 A computer is a device capable of performing computations and making
logical decisions at speeds millions of times faster than human beings can.

A person operating a desk calculator might require decades to complete the


same number of calculations a powerful computer can perform in one second.
 Today's fastest supercomputers can perform
hundreds of billions of additions per
second– about as many calculations as
hundreds of thousands of people could
perform in one year.

 IBM Blue Pacific a 4 Teraflop machine


performs 4x1012 floating point operations
per second.
Computers process data under the control
of sets of instructions called “Computer
programs”. These computers programs
guide the computer through orderly sets of
actions or processes specified by the
computer programmers.
Computer Organization

 Regardless of differences in physical


appearance, virtually every computer
may be envisioned as being divided into
six logical units:
1. Input Unit: The
“receiving”
section of the
computer. Mice,
Keyboards,
Microphones,
Scanners.
2. Output Units: The
“shipping” section of the
computer. It takes
information that has been
processed by the
computer and makes it
available for use outside
the computer
by placing it on various
output devices.
3. Memory unit: This is
the rapid access,
relatively low-
capacity
“warehouse” section
of the computer. The
memory unit is often
called either memory
or primary memory.
4. Arithmetic and Logic Unit (ALU): The
“manufacturing” section of the computer.
It is responsible for performing
calculations such as additions,
subtractions, multiplications and
divisions.
5. Central Processing
Unit (CPU): The
administrative
section of the
computer. It is the
computer’s
coordinator and is
responsible for
supervising the
operation of the
other sections.
6. Secondary storage unit:
Long Term, high capacity
“Warehousing” section of
the computer. The cost
per unit of secondary
storage is much less than
the cost per unit of
primary memory.
Personal Computing, Distributed Computing
and Client/Server Computing.

1977, Apple Computer popularized


the phenomenon of personal
Computers.
1981, IBM introduced the IBM
Personal computers.
– Personal computers
”Standalone”
units.
– Timesharing several
users: Telephone
lines, LANs in
organization
Distributed
Computing.
 Today, Most powerful desktop machines
(Workstations) provide enormous
capabilities Client/Server computing:
 File Servers across computer network +
Client computers.
 Today’s popular operating systems (Unix,
Linux, Microsoft’s Windows based
systems) provide Client / Server
capabilities.
Machine Language,
Assembly Language and high level language

Programmers write instructions in various


programming languages, some directly
understandable by the computers, others need
intermediate “translation” or “interpretation” steps.
Hundreds of computer languages are in use today.
These may be divided into three categories:
1. Machine Languages
2. Assembly Languages
3. High Level Languages
Machine Language
 A Computer can only understand its own machine
language.

 Machine language is the “natural Language” of a


particular computer it is defined by the
hardware design of the computer.

 They usually consists of strings of numbers


(ultimately reduced to 0’s and 1’s) that instruct
computers to perform their most elementary
operations one at a time.
 Machine languages are machine dependent and
meaningless for humans.
The following section of a machine language
program adds “overtime pay” to “base pay” and
stores the result in “gross pay”:

+1300042774
+1400593419
+1200274027
Assembly Language
 Computers became more popular Machine
language programming was too slow, tedious and
error prone.
 Instead of using strings of numbers directly
understandable by computers, programmers began
to use English-Like abbreviations to represent the
elementary operations of the computer  These
abbreviations formed the basis of assembly
languages.
 Translator programs called assemblers were
developed to convert assembly language programs
to machine language at computer speeds.
 The following section of an assembly
language program also adds “overtime pay”
to “base pay” and stores the result in “gross
pay”:

LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
High-Level Language
 Although Assembly languages are clearer to humans, they are
incomprehensible to computer until translated to machine
languages.
 With the use of assembly languages, computer usage increased
rapidly: But an obvious inconvenient was highlighted:
 Assembly languages required many instructions to accomplish
the simplest tasks lengthy process.
 High level languages were developed to speed up the
programming process, by using single statements to accomplish
substantial tasks.
 Translator programs called “Compilers” were introduced to
convert high-level language to machine languages
understandable by the machines.

 High level languages allow programmers to
write instructions similar to the everyday
English language containing commonly
used mathematical notations.
 The payroll example will be written like the
following in high-level languages:

grossPay = basePay + overTimePay


What is a language?
 System of words or “symbols” which allow
purposeful communications between two agents.

 Agent can be a computer or a a human.


What is a programming?
 Def1: Writing a a set of instructions to carry
out a particular task with a computer:
Instruct = tell someone what action to take
(without reference to the goal)
Instruction = An expression of what action to take
+ authority to enforce the action.
The program produced is a list of instructions
assuming the structure of the solution.
Def2: Writing a software which ensures
that a particular task is carried out.
Delegate= telling someone what goal is
needed without giving specific instructions.
The program produced describes the behavior
desired by the programmer.
 Def3: Producing a knowledge representation
which guides an agent towards a solution.
Teaching = imparting knowledge without reference
to a goal. The goal is derived from the
environment. Assuming that the receiver is
rational (will use this knowledge to produce
actions to guide them to their goals)
The program produced is a knowledge base which
emulates what a person (possibly non-
programmer) knows.
So what is programming
language?

 This depends on what we mean by


programming.
 For Def1: A software that allows a user to
write a series of instructions to define a
particular task, which will then be translated
to a form that is understood by the
computer.
Programming atom=Instruction
 For Def2: A software which allows the user
to write a decomposition of the behavior
desired, this behavior is then translated to a
form that is understood by the computer.
Programming atom=Function
 For Def3: This becomes known as a:
Knowledge representation language + a
Knowledge acquisition mechanism.
Programming atom = Rule of the form “if
condition then action”.
“The primary purpose of a
programming language is to
help the user to enlist the
help of a computer” (Bal,
Grune 94)
Basics of a Typical C++
Environment
Program is created in the editor and
Editor Disk stored on disk

Preprocessor Disk Preprocessor program processes the code

Compiler Compiler creates object code and stores it on


Disk disk
Linker Linker links the object code with the
Disk libraries, creates a.out and stores it
Primary memory on disk
Loader
Loader puts program in memory

Disk
Primary memory
CPU CPU takes each instruction and executes
. it, possibly storing new data values
as the program executes
Introduction to C++ programming
 A simple program: printing a line of Text

// A first program in C++


#include <iostream> //this line is going to be preprocessed

int main ()
{
std::cout<<“welcome to c++!\n”; // this is a statement
Return 0; //indicates that program ended successfully
}

Comment-semicolon (syntax error)-standard output stream object.


Introduction to C++ programming
 Another simple program: adding two integers
// Addition program
#include <iostream>

int main ()
{
Int integer1, integer2, sum; //declarations
std::cout<<“Enter first integer\n”; // prompt
std::cin >>integer1; // read an integer
std::cout<<“Enter second integer\n”; // prompt
std ::cin >>integer2; //read an integer
sum = integer1 + integer2; //assignment of sum
std::cout <<“Sum is “sum <<std::endl; //print sum
Return 0; //indicates that program ended successfully
}
Memory Concepts
 Variable names such as integer1, integer2 and
sum actually corresponds to locations in the
computer’s memory. Every variable has a name,
a type, a size and a value.
 In the addition program, when the statement :
std::cin >>integer1; is executed, the characters
typed by the user are converted to an integer
that is placed into a memory location to which
the name integer1 has been assigned by the C++
compiler.
Suppose the user enters the number 45 as the
value for integer1, the computer will place
45 into location integer1:
Example:

Memory

integer1 45
integer2 72

sum 117
Arithmetic
 C++ arithmetic operators:

C++ operator Arithmetic Algebraic C++


operator expression expression
Addition + f+7 f+7

Subtraction - p-c p–c

Multiplication * bm b*m

Division / x/y or x÷y x/y

Modulus % r mod s r%s


Arithmetic cont..
 Parentheses are used in C++ expressions in
much the same manner as in algebraic
expressions. For example, to multiply a times
the quantity b+c we write: a * (b + c)

 C++ applies the operators in arithmetic


expressions in a precise sequence determined by
the following rules of precedence, which are
generally the same as those followed in algebra:
1. Operators in expressions contained within
parentheses are evaluated first.
Parentheses are said to be at the highest
level of precedence. In case of nested or
embedded parentheses, the operators in
the innermost pair of parentheses are
applied first.
2. Multiplication, Division and modulus
operations are applied next. If an
expression contains several multiplication,
division and modulus, operators are
applied from left to right.
3. Addition and subtraction operations are
applied last.
Example:
Algebra: z = pr%q + w/x - y
C++: z = p * r % q + w / x – y;
 6 1 2 4 3 5  the
numbers indicate the order in which C++
applies the operators.

You might also like