Anda di halaman 1dari 18

Computer

A device capable of performing computations and making logical decisions

Computer

programs

Sets of instructions that control a computers processing of data


Various devices comprising a computer

Hardware

Examples: keyboard, screen, mouse, disks, memory, CD-ROM, and processing units

Software

Collection of Programs that run a computer

Six logical units in every computer:


Input unit

Output unit

Obtains information from input devices (keyboard, mouse) Outputs information (to screen, to printer, to control other devices) Rapid access, low capacity, stores input information

Memory unit

Arithmetic and logic unit (ALU) Central processing unit (CPU)

Performs arithmetic calculations and logic decisions Supervises and coordinates the other sections of the computer Cheap, long-term, high-capacity storage, stores inactive programs

Secondary storage unit

Batch processing

Do only one job or task at a time

Operating systems
Manage transitions between jobs Increased throughput

Amount of work computers process

Multiprogramming

Many jobs or tasks sharing a computers resources Perform a small portion of one users job then moves on to service the next user Economical enough for individual Organizations computing is distributed over networks Sharing of information, across computer networks, between file servers and clients (personal computers)

Timesharing Personal computers

Distributed computing

Client/server computing

Three types of programming languages

Machine languages

Strings of numbers giving machine specific instructions Example:


+1300042774 +1400593419 +1200274027

Assembly languages

English-like abbreviations representing elementary computer operations (translated via assemblers) Example:
LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

High-level languages

Similar to everyday English, use mathematical notations (translated via compilers) Example: grossPay = basePay + overTimePay

C++

evolved from C
C

C evolved from two other programming languages, BCPL and B

ANSI

Established worldwide standards for C programming

C++

spruces up C

Provides capabilities for object-oriented programming

Objects are reusable software components that model things in the real world Object-oriented programs are easy to understand, correct and modify

standard library
Provides rich collections of existing functions for all programmers to use

language
Facilitates a structured and disciplined approach to computer program design

Structured

programming

Disciplined approach to writing programs Clear, easy to test and debug, and easy to modify

Following

are several examples

The examples illustrate many important features of C++ Each example is analyzed one statement at a time.

Editor

Disk

Phases of C/C++ Programs: 1. Edit 2. Preprocess 3. Compile 4. Link 5. Load 6. Execute

Program is created in the editor and stored on disk. Preprocessor program processes the code. Compiler creates object code and stores it on disk. Linker links the object code with the libraries, creates a.out and stores it on disk

Preprocessor

Disk

Compiler

Disk

Linker

Disk
Primary Memory

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.

Variables
Location in memory where a value can be stored for use by a program A quantity whose value may changed during execution of the program is called variable Must be declared with a name and a data type before they can be used Some common data types are:

int - integer numbers char - characters double - floating point numbers Declares a variable named myvariable of type int Declares two variables, each of type int

Example: int myvariable;

Example: int variable1, variable2;

Variable

specifies the type of data that can be stored in it Following are the basic data types of C++ 1. Int 2. Float 3. double 4. Char 5. bool

Int represents the integer data type, it is used to declare integer type variables An integer is a whole number for example 23,50,-5 Int take two bytes of memory and the range of values is -32768 to 32767 The storage capacity of integer type variable can be changed applying qualifiers, there are three types of qualifiers which are short int(two bytes same value range), long int (four bytes value range from-2147483648 to 2147483648), unsigned int (two bytes, only positive whole number 0 to 65,535)

float

represents real or floating type data storage presents real or floating type data Storage capacity of float type variable is 4 bytes Long float capacity is 8 bytes Double data type storage capacity is 8 bytes Long double capacity is 10 bytes Char is for characters, its storage capacity is 1 byte and range of values is 1 byte to 65535 bytes

Variable names Correspond to locations in the computer's memory Every variable has a name, a type, a size and a value Whenever a new value is placed into a variable, it replaces the previous value - it is destroyed Reading variables from memory does not change them A visual representation integer1

45

Arithmetic

calculations

Use * for multiplication and / for division Integer division truncates remainder

7 / 5 evaluates to 1
7 % 5 evaluates to 2

Modulus operator returns the remainder

Operator

precedence

Some arithmetic operators act before others (i.e., multiplication before addition)

Be sure to use parenthesis when needed Do not use: a + b + c / 3 Use: (a + b + c ) / 3

Example: Find the average of three variables a, b and c


C++ operation Arithmetic operator + Addition Subtraction Multiplication Division Modulus * / %

Algebraic expression f+7 pc bm x/y r mod s

C++ expression f + 7 p - c b * m x / y r % s

Arithmetic operators:
Operator(s) () Operation(s) Parentheses Order of evaluation (precedence) Evaluated first. If the parentheses are nested, the expression in the innermost pair is evaluated first. If there are several pairs of parentheses on the same level (i.e., not nested), they are evaluated left to right.

*, /, or % + or -

Multiplication Division Evaluated second. If there are several, they re Modulus evaluated left to right. Addition Subtraction Evaluated last. If there are several, they are evaluated left to right.

Rules of operator precedence:

if

structure

Test conditions truth or falsity. If condition met execute, otherwise ignore

Equality

and relational operators

Lower precedence than arithmetic operators

Table

of relational operators on next slide

Standard algebraic equality operator or relational operator

C++ equality or relational operator

Example of C++ c ondition

Meaning of C++ c ondition

Relational operators > <

> < >= <=

x > y x < y x >= y x <= y

x is greater than y x is less than y x is greater than or equal to y x is less than or equal to y


Equality operators =

== !=

x == y x != y

x is equal to y x is not equal to y

Anda mungkin juga menyukai