Computer
programs
Hardware
Examples: keyboard, screen, mouse, disks, memory, CD-ROM, and processing units
Software
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
Performs arithmetic calculations and logic decisions Supervises and coordinates the other sections of the computer Cheap, long-term, high-capacity storage, stores inactive programs
Batch processing
Operating systems
Manage transitions between jobs Increased throughput
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)
Distributed computing
Client/server computing
Machine languages
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
ANSI
C++
spruces up C
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
The examples illustrate many important features of C++ Each example is analyzed one statement at a time.
Editor
Disk
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
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
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
Operator
precedence
Some arithmetic operators act before others (i.e., multiplication before addition)
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.
if
structure
Equality
Table
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